From 4e7b4dc55488a5a3cc227c8bd3b8d75ac14ea92d Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 15:37:01 -0800 Subject: [PATCH 1/4] show hotkeys bound to number keys, F11, and F12 --- docs/changelog.txt | 2 ++ plugins/hotkeys.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 75bec1368..6ca4995c9 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -44,6 +44,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `automaterial`: fix rendering errors with box boundary markers - `autolabor` & `autohauler`: properly handle jobs 241, 242, and 243 - `autofarm`: add missing output flushes +- `hotkeys`: correctly detect hotkeys bound to number keys, F11, or F12 - Core: fix the segmentation fault with the REPORT event in EventManager - Core: fix the new JOB_STARTED event only sending each event once, to the first handler listed - Core: ensure ``foo.init`` always runs before ``foo.*.init`` (e.g. ``dfhack.init`` should always run before ``dfhack.something.init``) @@ -60,6 +61,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `ls`: indent tag listings and wrap them in the right column for better readability - `ls`: new ``--exclude`` option for hiding matched scripts from the output. this can be especially useful for modders who don't want their mod scripts to be included in ``ls`` output. - `hotkeys`: hotkey screen has been transformed into an interactive `overlay` widget that you can bring up by moving the mouse cursor over the hotspot (in the upper left corner of the screen by default) +- `hotkeys`: now supports printing active hotkeys to the console with ``hotkeys list`` - `digtype`: new ``-z`` option for digtype to restrict designations to the current z-level and down - UX: List widgets now have mouse-interactive scrollbars - UX: You can now hold down the mouse button on a scrollbar to make it scroll multiple times. diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 85c304d82..0e9e0953c 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -76,11 +76,15 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { vector valid_keys; + for (char c = '0'; c <= '9'; c++) { + valid_keys.push_back(string(&c, 1)); + } + for (char c = 'A'; c <= 'Z'; c++) { valid_keys.push_back(string(&c, 1)); } - for (int i = 1; i < 10; i++) { + for (int i = 1; i < 13; i++) { valid_keys.push_back("F" + int_to_string(i)); } From 23e467deaf1dffaf5c82d13707c4af54a764f460 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 15:50:05 -0800 Subject: [PATCH 2/4] use consistent bounds checking style in hotkeys --- plugins/hotkeys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 0e9e0953c..6bb6a1600 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -84,7 +84,7 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) { valid_keys.push_back(string(&c, 1)); } - for (int i = 1; i < 13; i++) { + for (int i = 1; i <= 12; i++) { valid_keys.push_back("F" + int_to_string(i)); } From ae035d5836d0eff129e45508ec98c54b85388e51 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 17:16:48 -0800 Subject: [PATCH 3/4] simplify unit testing setup --- .github/workflows/build.yml | 14 ++++---- CMakeLists.txt | 68 ++++++++++++------------------------ data/CMakeLists.txt | 2 +- depends/CMakeLists.txt | 6 ++-- library/CMakeLists.txt | 4 +-- library/tests/CMakeLists.txt | 9 ++--- 6 files changed, 36 insertions(+), 67 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8631bc4e..39e332920 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,7 +83,7 @@ jobs: -B build-ci \ -G Ninja \ -DDFHACK_BUILD_ARCH=64 \ - -DBUILD_TESTING:BOOL=ON \ + -DBUILD_TESTS:BOOL=ON \ -DBUILD_DEV_PLUGINS:BOOL=${{ matrix.plugins == 'all' }} \ -DBUILD_SIZECHECK:BOOL=${{ matrix.plugins == 'all' }} \ -DBUILD_SKELETON:BOOL=${{ matrix.plugins == 'all' }} \ @@ -96,15 +96,13 @@ jobs: run: | ninja -C build-ci install ccache --show-stats - - name: Run unit tests - id: run_tests1 + - name: Run cpp unit tests + id: run_tests_cpp run: | - if build-ci/library/tests/test-library; then - exit 0 - fi - exit 1 + ninja -C build-ci && ninja -C build-ci test + exit $? - name: Run lua tests - id: run_tests2 + id: run_tests_lua run: | export TERM=dumb status=0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a94274c7..e2b123120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -394,11 +394,10 @@ else() endif() endif() -if(BUILD_TESTING) - message("BUILD TESTS: Core, Scripts") - set(BUILD_SCRIPT_TESTS ON FORCE) - set(BUILD_CORE_TESTS ON FORCE) -endif() +find_package(ZLIB REQUIRED) +include_directories(depends/protobuf) +include_directories(depends/lua/include) +include_directories(depends/md5) # Support linking against external tinyxml # If we find an external tinyxml, set the DFHACK_TINYXML variable to "tinyxml" @@ -415,11 +414,6 @@ else() set(DFHACK_TINYXML "dfhack-tinyxml") endif() -find_package(ZLIB REQUIRED) - -include_directories(depends/protobuf) -include_directories(depends/lua/include) -include_directories(depends/md5) include_directories(depends/lodepng) include_directories(depends/tthread) include_directories(${ZLIB_INCLUDE_DIRS}) @@ -427,42 +421,16 @@ include_directories(depends/clsocket/src) include_directories(depends/xlsxio/include) add_subdirectory(depends) - # Testing with CTest -if(BUILD_TESTING OR BUILD_CORE_TESTS) - macro(dfhack_test name files) - message("dfhack_test(${name}, ${files})") - add_executable(${name} ${files}) - target_include_directories(${name} PUBLIC depends/googletest/googletest/include) - target_link_libraries(${name} dfhack gtest) - set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") - add_test(NAME ${name} COMMAND ${name}) - endmacro() - include(CTest) -endif() - -include(CMakeDependentOption) -cmake_dependent_option( - BUILD_SCRIPT_TESTS "Install integration tests in hack/scripts/test" OFF - "BUILD_TESTING" OFF) -mark_as_advanced(FORCE BUILD_TESTS) -# Handle deprecated BUILD_TESTS option -option(BUILD_TESTS "Deprecated option; please use BUILD_SCRIPT_TESTS=ON" OFF) - -if(BUILD_TESTING OR BUILD_SCRIPT_TESTS) - if(EXISTS "${dfhack_SOURCE_DIR}/test/scripts") - message(SEND_ERROR "test/scripts must not exist in the dfhack repo since it would conflict with the tests installed from the scripts repo.") - endif() - install(DIRECTORY ${dfhack_SOURCE_DIR}/test - DESTINATION ${DFHACK_DATA_DESTINATION}/scripts) - install(FILES ci/test.lua DESTINATION ${DFHACK_DATA_DESTINATION}/scripts) -else() - add_custom_target(test - COMMENT "Nothing to do: CMake option BUILD_TESTING is OFF" - # Portable NOOP; need to put something here or the comment isn't displayed - COMMAND cd - ) -endif() +macro(dfhack_test name files) + message("dfhack_test(${name}, ${files})") + add_executable(${name} ${files}) + target_include_directories(${name} PUBLIC depends/googletest/googletest/include) + target_link_libraries(${name} dfhack gtest) + set_target_properties(${name} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") + add_test(NAME ${name} COMMAND ${name}) +endmacro() +include(CTest) find_package(Git REQUIRED) if(NOT GIT_FOUND) @@ -570,6 +538,16 @@ if(BUILD_DOCS) install(FILES "README.html" DESTINATION "${DFHACK_DATA_DESTINATION}") endif() +option(BUILD_TESTS "Include tests (currently just installs Lua tests into the scripts folder)" OFF) +if(BUILD_TESTS) + if(EXISTS "${dfhack_SOURCE_DIR}/test/scripts") + message(SEND_ERROR "test/scripts must not exist in the dfhack repo since it would conflict with the tests installed from the scripts repo.") + endif() + install(DIRECTORY ${dfhack_SOURCE_DIR}/test + DESTINATION ${DFHACK_DATA_DESTINATION}/scripts) + install(FILES ci/test.lua DESTINATION ${DFHACK_DATA_DESTINATION}/scripts) +endif() + # Packaging with CPack! set(DFHACK_PACKAGE_SUFFIX "") if(UNIX) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 8cf6bb2ca..412ffa347 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -21,7 +21,7 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/blueprints/ FILES_MATCHING PATTERN "*" PATTERN blueprints/library/test EXCLUDE) -if(BUILD_SCRIPT_TESTS) +if(BUILD_TESTS) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/blueprints/library/test/ DESTINATION blueprints/library/test ) diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt index f5e77ad8a..e1c07bd92 100644 --- a/depends/CMakeLists.txt +++ b/depends/CMakeLists.txt @@ -3,10 +3,8 @@ add_subdirectory(lodepng) add_subdirectory(lua) add_subdirectory(md5) add_subdirectory(protobuf) -if(BUILD_CORE_TESTS) - add_subdirectory(googletest EXCLUDE_FROM_ALL) - set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare") -endif() +add_subdirectory(googletest) +set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare") # Don't build tinyxml if it's being externally linked against. if(NOT TinyXML_FOUND) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5e7488027..39c5d92d9 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -82,9 +82,7 @@ set(MAIN_SOURCES RemoteTools.cpp ) -if(BUILD_CORE_TESTS) - add_subdirectory(tests) -endif() +add_subdirectory(tests) if(WIN32) set(CONSOLE_SOURCES Console-windows.cpp) diff --git a/library/tests/CMakeLists.txt b/library/tests/CMakeLists.txt index 3e5a2b3ca..8bbc34065 100644 --- a/library/tests/CMakeLists.txt +++ b/library/tests/CMakeLists.txt @@ -1,7 +1,4 @@ -file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *test.cpp) +file(GLOB_RECURSE TEST_SOURCES + LIST_DIRECTORIES false + *test.cpp) dfhack_test(test-library "${TEST_SOURCES}") - -# How to get `test` to ensure everything is up to date before running -# tests? This add_dependencies() fails with: -# Cannot add target-level dependencies to non-existent target "test". -#add_dependencies(test MiscUtils.test) From a22e3117d396e1a2a10167cb17cb0fee9bf4757e Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 17:22:17 -0800 Subject: [PATCH 4/4] simplify the github action to just ninja test since ninja all was just run --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 39e332920..d7e8a52b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,7 +99,7 @@ jobs: - name: Run cpp unit tests id: run_tests_cpp run: | - ninja -C build-ci && ninja -C build-ci test + ninja -C build-ci test exit $? - name: Run lua tests id: run_tests_lua