Testing

Perseid uses two testing frameworks:

boost::ut is used for the unit tests, which construct objects in memory and verify SQL output without connecting to a database.

Catch2 is used for integration tests, which connect to an actual PostgreSQL database and verify end-to-end behavior.

Running the tests

cmake --build build
ctest --test-dir build

ctest runs the unit tests first and then the integration suite. The integration suite requires PostgreSQL running locally.

createdb perseas_test
createdb perseas_test_src

Most suites share the perseas_test database. The functional migration tests use perseas_test_src as their source database and perseas_test as their target. Every database-backed test starts by dropping all user schemas (including the public schema that createdb creates), cascading to the objects they contain, so each test observes an identical, empty database regardless of what earlier runs left behind.

The database names are configurable, so the tests can run against differently named databases. The integration and functional suites read the PERSEAS_TEST_DB and PERSEAS_TEST_DB_SRC (functional only) environment variables, defaulting to perseas_test and perseas_test_src respectively when unset.

Smoke test: running against alternate databases

To verify that the environment-variable override works properly, you can create two throwaway databases, run the whole suite against them, then drop them:

createdb perseid_alt
createdb perseid_alt_src
PERSEAS_TEST_DB=perseid_alt PERSEAS_TEST_DB_SRC=perseid_alt_src \
    ctest --test-dir build
dropdb perseid_alt
dropdb perseid_alt_src

The databases need no preparation beyond createdb; the tests reset them on their own.

Unit tests

The unit tests use boost::ut and construct objects in memory. They live under src/; source files are named <suite>_test.cpp, build to executables named <suite>_test, and are registered with CTest under short names such as test_database and test_schema.

You can use ctest -N to see the tests currently registered:

# List all registered tests and their CTest names
ctest --test-dir build -N

# Run a single unit test by replacing <name> with a name from that list
ctest --test-dir build -R '^test_<name>$' --output-on-failure

# Or run every boost::ut binary found under build/src directly
find build/src -type f -name '*_test' -print -exec {} \;

Integration tests

The integration tests live in tests/ and use Catch2. They connect to the test database through Rel_db and exercise the same objects as the unit tests against live catalogs. Their CTest names end in _integration, so new suites are picked up by the same pattern.

# Ensure the test database exists
createdb perseas_test

# Run all integration tests
ctest --test-dir build -R '_integration$' --output-on-failure

# Run a single integration suite
ctest --test-dir build -R '^test_<suite>_integration$' --output-on-failure

# Or run a Catch2 binary directly, with an optional test-name or tag filter
./build/tests/test_<suite>
./build/tests/test_<suite> "Create a new schema"

Functional tests

The functional tests are ports of Pyrseas’ functional test suite. The first one, test_filmversions, executes SQL scripts against a source database to build successive schema versions (0.1, 0.2, 0.3), mirrors each version into a target database by applying the differences between the two YAML descriptions, and after each step—and after reverting to each earlier version—verifies that the two databases are identical by diffing pg_dump output and YAML files. It uses the Db_migrate_testcase base class from tests/testutils.cppm.

# Run the functional test
ctest --test-dir build -R test_filmversions

# Or run the binary directly (optionally with Catch2 tags or filters)
./build/tests/test_filmversions
./build/tests/test_filmversions "[film]"

In addition to both test databases, the test requires pg_dump to be available on PATH.

The SQL scripts live in tests/scripts/, separate from the test sources. Temporary files (dumps, YAML and generated SQL) are written to a perseid_test directory under the system temporary directory. The directory is emptied at the start of each test run.

The suites share the same databases and temporary files, so test executables should not be run concurrently; CTest runs them serially by default. Note also that test_filmversions does not match the _integration$ pattern, so it is not included in ctest -R '_integration$'.

Test organization

Source location

Framework

File naming

CTest name

src/ and its subdirectories

boost::ut

<suite>_test.cpp

test_<suite>

tests/

Catch2

test_<suite>.cpp

test_<suite>_integration

tests/test_filmversions.cpp

Catch2

fixed name

test_filmversions

When adding a test, follow the naming pattern of its directory and add the target and add_test() call to the nearest CMakeLists.txt; the commands above will then find it without further documentation changes.