Skip to content

Unit tests - #399

Merged
trzy merged 7 commits into
masterfrom
bart/unit-tests
Nov 28, 2026
Merged

trzy merged 7 commits into
masterfrom
bart/unit-tests

Conversation

@trzy

@trzy trzy commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Formal unit tests that will be run as part of CI. We want to create these sparingly, so I added an AGENTS.md that 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 vrext which was recently added then removed.

trzy added 7 commits November 28, 2026 13:11
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.
@trzy
trzy merged commit 3a5012e into master Nov 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant