Repository navigation
Conversation
SerialProgramsTests runs the same unit tests as --command-line-test-mode, but opens no window, reads and writes no settings, and does not scan serial ports or cameras, so it can run while SerialPrograms is open. --filter <text> (repeatable) selects tests by name substring, --list prints the selected names, and the exit code is the number of failed tests (255 for a bad argument or no matching test). CommandLineUnitTestRunner::run() takes the filters and returns the failure count; --command-line-test-mode still returns 0 or 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
|
do we need to explain / document how to build this thing? (the CMake changes)? |
| namespace{ | ||
| bool matches_any(const std::string& test_name, const std::vector<std::string>& filters){ | ||
| if (filters.empty()){ | ||
| return true; | ||
| } | ||
| for (const std::string& filter : filters){ | ||
| if (test_name.contains(filter)){ | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
google C++ style, put this unnamed namespace on the top, between line 45-50
There was a problem hiding this comment.
ad6aa40: moved the unnamed namespace (matches_any) to the top of the file, right after namespace ComputerPrograms{ opens.
|
|
||
|
|
||
| bool CommandLineUnitTestRunner::run(bool augment_color_distortions){ | ||
| size_t CommandLineUnitTestRunner::run(bool augment_color_distortions, const std::vector<std::string>& filters){ |
There was a problem hiding this comment.
is there a span / view type in C++ 23 that can be used?
There was a problem hiding this comment.
ad6aa40: the project is C++23; filters are now std::span in run(), unit_test_names() and run_unit_tests(). The runner keeps string_views of argv, so nothing is copied.
| } | ||
|
|
||
|
|
||
| namespace{ |
There was a problem hiding this comment.
ad6aa40: read it as comment 1: the unnamed namespace is now the first thing inside namespace PokemonAutomation, before use_qt_ui().
| #include "ComputerPrograms/ComputerPrograms_UnitTestRunner.h" | ||
| #include "Tests/CommandLineTests.h" | ||
|
|
||
| using namespace PokemonAutomation; |
There was a problem hiding this comment.
don't do this -- check google C++ style / ToTw on relevant recommendations
There was a problem hiding this comment.
ad6aa40: removed the using-directive. Everything now lives in namespace PokemonAutomation, and main() just calls PokemonAutomation::test_runner_main(argc, argv).
| GlobalThreadPools::qt_event_threadpool().stop(); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
ad6aa40: closed with } // namespace, which is what the repo uses most (Common/ and Source/).
- Pass test-name filters as std::span<const std::string_view>; the runner keeps views of argv instead of copying strings. - Put the unnamed namespaces at the top, inside namespace PokemonAutomation, closed with "} // namespace"; drop the using-directive and let main() call PokemonAutomation::test_runner_main(). - AGENTS.md: how to build and run SerialProgramsTests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
|
Yes. ad6aa40 adds a Build and run part to the description: the |
| static UnitTestDatabase database = make_UNIT_TESTS_ALL(); | ||
| return database; | ||
| } | ||
| std::vector<std::string> unit_test_names(std::span<const std::string_view> filters){ |
There was a problem hiding this comment.
blank line above and below this function
There was a problem hiding this comment.
c213cac: added a blank line above and below unit_test_names().
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Depends on #206
Adds
SerialProgramsTests, a small executable that runs the unit tests without the GUI. It is for two things:--filter PokemonFRLGtakes about 1 s instead of about 12 s for every test.It does not make builds faster: both executables link the same
SerialProgramsLib, so rebuild time is the same (measured below).SerialPrograms --command-line-test-modefirst reads the settings and scans serial ports and cameras, logs into the app's ownSerialPrograms.log, and always runs every test. Its camera scan has made an open SerialPrograms on the same Mac switch its program panel mid-run.Source/Tests/TestRunner_Main.cpplinksSerialProgramsLibwith only aQCoreApplication, definesuse_qt_ui()(from Replace the USE_QT_UI global with use_qt_ui() #206) asfalse, and logs to its own folder (~/Library/Application Support/SerialProgramsTests/on macOS). Built by default;-DTEST_RUNNER_EXE=OFFturns it off.--filter <text>(repeatable, name substring),--list,--augment-color-distortions. The exit code is the number of failed tests (capped at 254), or 255 for a bad argument or no match.CommandLineUnitTestRunner::run()gained the filter; the GUI test mode still runs everything and returns 0 or 1.SerialProgramsTests, built by default withSerialPrograms(configure with-DTEST_RUNNER_EXE=OFFto skip it).ninja -C <build> SerialProgramsTestsbuilds only it, and the binary lands at<build>/SerialProgramsTests. Run<build>/SerialProgramsTests --filter PokemonFRLG, or--listto see what a filter selects. Image tests need the CommandLineTests images in aUnitTestResources/folder in or above<build>, as for the GUI test mode. The in-repoAGENTS.mdnow says the same.SerialProgramsLib, and after a one-file edit re-archiving it takes 5–18 s while linking either executable takes 0.6–0.9 s. The gain is at run time:--filter PokemonFRLGfinishes in 0.6–1.2 s, against about 12 s for the GUI mode's whole suite on the same Mac, and it leaves an open app alone.SerialProgramsfor anything touching UI or the program panels, and before a console run.Testing
-j4, no other build running: touch or edit one FRLG.cpp, thenninja SerialProgramstook 6.5–20 s andninja SerialProgramsTests5.9–22 s over six alternating runs each, so no difference beyond noise.--list(20,339 tests on main) takes 0.4–0.5 s; the GUI mode reaches its first test about 0.2 s after starting, so startup is not different either.SerialPrograms.log. Image tests needUnitTestResources/in the build folder, as in the GUI mode; without it they fail withFileException.Sockets (Qt) - close() cancels an in-flight send(Sockets: make the Qt client's close() cancel in-flight sends PokemonAutomation/Arduino-Source#1831) hung in 4 of 4 runs here under heavy load, so an unfiltered run did not finish. It looks like a race inClientSocket_Qt::send()rather than this runner, but I did not try it in the GUI mode.🤖 Generated with Claude Code
https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E