Testing
structop test checks that a project does what it should. Tests live next to the configuration, in tests/*.sttest files, and each run block is one test.
On this page
A test file#
run "lists_each_argument" {
args = ["one", "two", "three"]
expect {
output_equals = "Parameter 0 is one\nParameter 1 is two\nParameter 2 is three\n"
}
}
run "no_arguments_prints_nothing" {
expect {
output_equals = ""
}
}Each run builds a fresh copy of the project, so runs never affect each other or your own build.
| Attribute | Meaning |
|---|---|
variables | values that replace the ones in .stvars files for this run |
input | text given to the program on standard input |
args | command-line arguments |
expect | what must be true afterwards (below) |
expect takes one or more of:
| Check | Passes when |
|---|---|
output_equals | the program prints exactly this text |
output_contains | the program's output contains this text |
exit_code | the program exits with this code (0 when left out) |
error_contains | validation or the build fails, with this text in the error |
Running the tests#
$ structop test tests/params.sttest PASS lists_each_argument PASS no_arguments_prints_nothing Success! 2 passed, 0 failed.
structop test -filter=NAME runs only the runs with that name. The command exits with 1 when any run fails, so it fits in a build script.
Run the same test on C and Rust#
For the greeting in Getting started, save this file alongside the project declarations under tests/.
run "greets_ada" {
input = "Ada\n"
expect {
output_contains = "Hello, Ada!"
exit_code = 0
}
}With lang = "C" in intent.st, run structop init and structop test. Change only lang to "Rust" and run structop test again. In a portable project, validate checks declarations and source generation for both targets. Each invocation of test builds and executes the selected target, so running it twice checks both executables against the same assertions.
Testing games and windows#
Terminal games run headless when standard input is not a terminal: each input line is one frame's key, and the last frame is printed, so output_contains can check the final screen. Set STRUCTOP_SEED to make random numbers repeat (see Terminal games).
Window programs can drive themselves with test abilities such as click, answer and exit_after, and print what a person would have seen, so their output can be checked the same way.
Verify the project catalog#
From the source repository, run make catalog-test with the handbook source checked out beside it. The runner checks that each project page has a fixture, then tries every fixture as C and as Rust in fresh directories. The only project setting it edits is lang in intent.st. Each target must initialize, validate, match the recorded plan, build, run with the example’s inputs, match the recorded output, and pass any project tests.
The per-target results are written to build/catalog/results.csv. This is a strict portability check. It exits nonzero if any target fails, including the opposite target for the native examples. Use make test for the regular regression suite. Running the entire catalog requires both toolchains, the native libraries used by the fixtures, the Rust crate dependencies and a working GTK display.
The macOS ARM64 verification used GTK 2.24.33 and GTK 3.24.52 with the SVG pixbuf loader. For the C binding examples, pkg-config selected the SDK packages for libcurl 8.7.1, SQLite 3.54.0 and zlib 1.2.12. These versions matter because structop bind derives the provider API from the installed headers.