Repository navigation
Unit tests - #399
Merged
Merged
Unit tests#399
Conversation
Test_BitRegister.cpp tests the BitRegister class, which was deleted in 04f1ed7, so it no longer builds. Test_Config printed which tests failed but always exited 0. Now it exits 1 if a test fails, so a script or CI job can tell.
"make tests" builds Test_Thread and Test_Config in the binary directory and runs them. It stops at the first test that fails, with a non-zero exit code. The tests link the emulator's object files, which are compiled with the same flags, and nothing more. They don't need SDL, so each platform Makefile gives the libraries that the tests do need in PLATFORM_TEST_LDFLAGS. On Windows, -static makes each test a single .exe that runs without MinGW's DLLs.
The new step runs "make tests" on Windows, Linux, and macOS with the build's OPT, so the tests link the object files that the build just made. A failing test fails the job before the package is made.
Test_Thread.cpp and Test_Config.cpp move from Src/OSD and Src/Util, so the tests are in one place, apart from the emulator's sources. Src/Tests isn't in SRC_FILES, so Rules.inc adds it to VPATH for the %.cpp rule.
AGENTS.md tells AI coding agents to create unit tests sparingly, and only when a human coder explicitly asks for one, and how to build and run the tests. CLAUDE.md imports it for Claude Code.
Test_GamesXML loads Config/Games.xml with the emulator's GameLoader and fails if GameLoader reports any error. That includes a clone that uses a parent's file name for a file with other contents, as vrext did: a merged ROM set keeps a family in one zip file, so the names must be unique in it. Small definitions check that GameLoader still detects that case, also between two clones, and still allows a shared identical file and unrelated games with the same names. The test links GameLoader and its unzip code, so the test link flags gain -lz. "make tests" now prints each "Running unit test" message with echo, because make prints $(info) for the whole recipe before it runs any of it.
Build and Release now also runs for pull requests into master, so each pull request builds and runs the unit tests on Windows, Linux, and macOS. The release job still runs only on master. The packages stay attached to the workflow run as artifacts, so that a pull request's build can be tried before it's merged. They're kept for 7 days rather than 90: a release keeps its own copies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Formal unit tests that will be run as part of CI. We want to create these sparingly, so I added an
AGENTS.mdthat says so, otherwise AI coding tools tend to slopify the code base with lots of silly tests.A test for Games.xml was added, which should catch the issue with
vrextwhich was recently added then removed.