2026-07-23 01:24:42 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
2026-07-22 18:16:38 +02:00
|
|
|
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
import std;
|
|
|
|
|
import Crafter.Build;
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
namespace {
|
2026-07-23 01:24:42 +02:00
|
|
|
std::int32_t Failures = 0;
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
|
|
|
|
|
void Check(bool cond, std::string_view msg) {
|
|
|
|
|
if (!cond) {
|
|
|
|
|
std::println(std::cerr, "FAIL: {}", msg);
|
2026-07-23 01:24:42 +02:00
|
|
|
++Failures;
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write a tiny POSIX shell script that exits with `code` and return its
|
|
|
|
|
// path. The harness invokes `<binary> <args>` through the host shell, so
|
|
|
|
|
// a #!/bin/sh script works as a stand-in for a real test binary.
|
2026-07-23 01:24:42 +02:00
|
|
|
fs::path WriteExitScript(const fs::path& dir, std::string_view stem, std::int32_t code) {
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
fs::path script = dir / stem;
|
|
|
|
|
std::ofstream out(script);
|
|
|
|
|
out << "#!/bin/sh\nexit " << code << "\n";
|
|
|
|
|
out.close();
|
2026-07-23 01:24:42 +02:00
|
|
|
fs::permissions(script, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec | fs::perms::group_read | fs::perms::group_exec | fs::perms::others_read | fs::perms::others_exec, fs::perm_options::replace);
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Drives RunSingleTest against shell-script fixtures and asserts the
|
|
|
|
|
// exit-code → TestOutcome mapping documented in the README:
|
|
|
|
|
// 0 -> Pass
|
|
|
|
|
// 77 -> Skipped (autoconf convention)
|
|
|
|
|
// anything else -> Fail
|
test: what a test leaves in its TMPDIR, kept when it fails, else gone
TestTemporaryDirectory runs a probe through RunTests that records the
TMPDIR it was given and the directory fs::temp_directory_path() names,
leaves a file there and exits as it is told. Two configurations each
declare a passing test named probe, built differently so that the run
does not refuse them, and the second also a failing one and one for
another target, the host's own triple without its vendor and with x32
after it, which is never the host's and makes a second pass after the
host's, and is skipped before it is built. The run takes one test at a
time, so the failing one comes last in the host's pass, and it dates
the run's directory, and a directory beside it that looks like one a
run let go of, two minutes back before it fails, as a test that ran
that long leaves them. Each test's fs::temp_directory_path() is the
TMPDIR it was given: <run>/<name>, in a directory made for the run in
the temp directory, and probe-2 for the second probe. What the passing
tests left is removed; what the failing one left is kept, named in its
output and its log, and so is the run's directory. A second run gets a
directory of its own, removes it since every test passed, and leaves
the first run's alone; a third, once that one is dated past the minute,
removes it. The other target's pass makes no directory of its own: the
one dated back beside the run's is still there when the run ends. A
fourth run, whose pass for the other target throws, as one does where
CRAFTER_BUILD_RUNNER_ names that target's runner wrong, keeps what its
first pass kept.
The runs make their directories in a temp directory the test makes for
them and names with TMPDIR. The test removes only its own scratch
directory, which holds that one, and the fixture's bin/ and build/, and
dates a directory a probe reports only when it is a run's directory in
that temp directory.
HeadlessCompositor checks that a test that sets wayland and is given a
TMPDIR runs with both: the TMPDIR it is given and its compositor's
display alone, and that one under `host` and given a TMPDIR has it
beside the session's display. Two failing tests of one name each have a
log of their own, twin.log and twin-2.log, that says where what each
left is kept. RunSingleTestExit runs a script whose path has an '=' in
it, given a TMPDIR, which has to run and whose exit decides the
outcome.
Without TMPDIR on the test's command, 13 of TestTemporaryDirectory's
checks fail; with a test's log named after the test alone, the two on
the logs of the tests of one name do; without the date a kept directory
gets as it is let go of, the one on the second run leaving the first
run's alone does; with a directory of its own for a later pass, beside
the run's, the one on the other target's pass does; and with the
directory kept only once RunTests returns, the one on the fourth run
does. With the test's own words as env's command, the two of
RunSingleTestExit on the script whose path has an '=' fail.
2026-11-27 09:17:35 +01:00
|
|
|
// and that a binary whose path has an '=' in it runs, with a TMPDIR as
|
|
|
|
|
// RunTests gives it.
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
int main() {
|
|
|
|
|
fs::path dir = fs::temp_directory_path() / "crafter-build-run-single-test";
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
fs::remove_all(dir, ec);
|
|
|
|
|
fs::create_directories(dir);
|
|
|
|
|
|
|
|
|
|
Test t;
|
|
|
|
|
t.runner = TestRunner::Local();
|
|
|
|
|
t.config.outputName = "run-single";
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
fs::path script = WriteExitScript(dir, "pass.sh", 0);
|
|
|
|
|
TestResult r = RunSingleTest(t, script, std::chrono::seconds(5));
|
|
|
|
|
Check(r.outcome == TestOutcome::Pass, "exit 0 -> Pass");
|
|
|
|
|
Check(r.exitCode == 0, "Pass carries exitCode 0");
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
fs::path script = WriteExitScript(dir, "skip.sh", 77);
|
|
|
|
|
TestResult r = RunSingleTest(t, script, std::chrono::seconds(5));
|
|
|
|
|
Check(r.outcome == TestOutcome::Skipped, "exit 77 -> Skipped");
|
|
|
|
|
Check(r.exitCode == 77, "Skipped carries exitCode 77");
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
fs::path script = WriteExitScript(dir, "fail.sh", 3);
|
|
|
|
|
TestResult r = RunSingleTest(t, script, std::chrono::seconds(5));
|
|
|
|
|
Check(r.outcome == TestOutcome::Fail, "non-zero/non-77 exit -> Fail");
|
|
|
|
|
Check(r.exitCode == 3, "Fail carries the original exitCode");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cmd-prefix runner: wrap the script in `sh {bin} {args}` so we exercise
|
|
|
|
|
// the templated-exec path through RunSingleTest. Probes don't run here
|
|
|
|
|
// (RunSingleTest doesn't probe — RunTests does), so any prefix that
|
|
|
|
|
// resolves on PATH is fine.
|
|
|
|
|
{
|
|
|
|
|
Test ct;
|
|
|
|
|
ct.runner = TestRunner::Cmd("sh");
|
|
|
|
|
ct.config.outputName = "run-single-prefix";
|
|
|
|
|
fs::path script = WriteExitScript(dir, "prefixed.sh", 0);
|
|
|
|
|
TestResult r = RunSingleTest(ct, script, std::chrono::seconds(5));
|
|
|
|
|
Check(r.outcome == TestOutcome::Pass, "Cmd-prefixed exit 0 -> Pass");
|
|
|
|
|
}
|
|
|
|
|
|
test: what a test leaves in its TMPDIR, kept when it fails, else gone
TestTemporaryDirectory runs a probe through RunTests that records the
TMPDIR it was given and the directory fs::temp_directory_path() names,
leaves a file there and exits as it is told. Two configurations each
declare a passing test named probe, built differently so that the run
does not refuse them, and the second also a failing one and one for
another target, the host's own triple without its vendor and with x32
after it, which is never the host's and makes a second pass after the
host's, and is skipped before it is built. The run takes one test at a
time, so the failing one comes last in the host's pass, and it dates
the run's directory, and a directory beside it that looks like one a
run let go of, two minutes back before it fails, as a test that ran
that long leaves them. Each test's fs::temp_directory_path() is the
TMPDIR it was given: <run>/<name>, in a directory made for the run in
the temp directory, and probe-2 for the second probe. What the passing
tests left is removed; what the failing one left is kept, named in its
output and its log, and so is the run's directory. A second run gets a
directory of its own, removes it since every test passed, and leaves
the first run's alone; a third, once that one is dated past the minute,
removes it. The other target's pass makes no directory of its own: the
one dated back beside the run's is still there when the run ends. A
fourth run, whose pass for the other target throws, as one does where
CRAFTER_BUILD_RUNNER_ names that target's runner wrong, keeps what its
first pass kept.
The runs make their directories in a temp directory the test makes for
them and names with TMPDIR. The test removes only its own scratch
directory, which holds that one, and the fixture's bin/ and build/, and
dates a directory a probe reports only when it is a run's directory in
that temp directory.
HeadlessCompositor checks that a test that sets wayland and is given a
TMPDIR runs with both: the TMPDIR it is given and its compositor's
display alone, and that one under `host` and given a TMPDIR has it
beside the session's display. Two failing tests of one name each have a
log of their own, twin.log and twin-2.log, that says where what each
left is kept. RunSingleTestExit runs a script whose path has an '=' in
it, given a TMPDIR, which has to run and whose exit decides the
outcome.
Without TMPDIR on the test's command, 13 of TestTemporaryDirectory's
checks fail; with a test's log named after the test alone, the two on
the logs of the tests of one name do; without the date a kept directory
gets as it is let go of, the one on the second run leaving the first
run's alone does; with a directory of its own for a later pass, beside
the run's, the one on the other target's pass does; and with the
directory kept only once RunTests returns, the one on the fourth run
does. With the test's own words as env's command, the two of
RunSingleTestExit on the script whose path has an '=' fail.
2026-11-27 09:17:35 +01:00
|
|
|
// A test whose binary's path has an '=' in it, given a TMPDIR, as
|
|
|
|
|
// RunTests gives every test one: env, which sets the TMPDIR, took that
|
|
|
|
|
// path for an assignment and, with no command left, exited 0, a pass
|
|
|
|
|
// for a test that never ran.
|
|
|
|
|
{
|
|
|
|
|
const fs::path equals = dir / "a=b";
|
|
|
|
|
fs::create_directories(equals);
|
|
|
|
|
fs::create_directories(dir / "tmpdir");
|
|
|
|
|
const fs::path marker = dir / "a=b-ran";
|
|
|
|
|
const fs::path script = equals / "marker.sh";
|
|
|
|
|
std::ofstream(script) << std::format("#!/bin/sh\necho ran > '{}'\nexit 3\n", marker.string());
|
|
|
|
|
fs::permissions(script, fs::perms::owner_all, fs::perm_options::replace);
|
|
|
|
|
TestResult r = RunSingleTest(t, script, std::chrono::seconds(5), std::nullopt, dir / "tmpdir");
|
|
|
|
|
Check(fs::exists(marker), "a test whose binary's path has an '=' in it runs");
|
|
|
|
|
Check(r.outcome == TestOutcome::Fail && r.exitCode == 3, std::format("and its exit decides the outcome, got {}", r.exitCode));
|
|
|
|
|
}
|
|
|
|
|
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
fs::remove_all(dir, ec);
|
|
|
|
|
|
2026-07-23 01:24:42 +02:00
|
|
|
if (Failures > 0) {
|
|
|
|
|
std::println(std::cerr, "{} assertions failed", Failures);
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|