Attributes
All attributes live in sparkles.test_runner.attributes and are plain marker types — a test annotated with them remains an ordinary unittest block for any other runner. Import them unconditionally (not under version (unittest)): unittest UDAs are resolved even in builds that do not compile the unittest bodies.
@betterC
The test is -betterC-compatible (no GC, exceptions, TypeInfo, druntime).
- Runs normally under
dub test. --better-cextracts it into a standalone druntime-free program.- The body may only use the module's public symbols. Its own module is compiled in by default, so ordinary functions work; other modules are opted in with
--include-import. @betterC(selfContained: true)keeps the module out entirely, limiting the body to templates/CTFE-able code — which is what lets a module that cannot compile under-betterCstill host such a test.
@ctfe
The test runs at compile time instead of runtime.
- Evaluated through CTFE by a runner-generated probe compiled with
-o- -unittest(semantic analysis only) after-i/-efiltering — so filters control which tests execute, and--help/--listwork even when an@ctfetest would fail. - Reported as
⚙ … (compile time)on success,✗ … (compile time)plus the compiler's CTFE error trail on failure; never executed at runtime. - The body must be CTFE-able; needs a D compiler on
PATH(or$DC/--compiler) at run time. - Named after (and forward-compatible with) DMD 2.113's
@__ctfefunction attribute.
@wasm
The test is WebAssembly-compatible.
- Runs normally under
dub test. --wasmcompiles it forwasm32-unknown-wasip1with the full druntime and Phobos of an LDC that has the WASI runtime, and runs it underwasmtime.--wasm-barecompiles it for barewasm32with-betterCinstead; there all@betterCconstraints apply.@wasm(selfContained: true)keeps the test's own module out of the extracted program.
@benchmark / @benchmark(iterations: N)
The test is a benchmark whose body is the measured unit.
- Skipped by normal runs (counted in the summary); measured by
--bench. iterationspins the per-sample iteration count;0(default) auto-scales.- The whole body is measured. To keep setup out of the timing, register the measured part as a
benchCasefrom a@benchCasestest instead (aBenchTiming.batchedcase is timed the way a whole body is).blackBoxis the optimizer barrier. - Calling
benchCasefrom a@benchmarkbody fails the test's registration: a matrix is@benchCases. --perfadds hardware-counter columns to the--benchtable: Linuxperf_event(IPC, instructions/iter, cache/branch miss rates) or macOSproc_pid_rusagefixed counters (IPC + instructions/iter, process-wide).
@benchCases / @benchCases(iterations: N)
The test registers its rows with benchCase — a matrix, or one case that keeps setup out of the timing (case structs the runner owns, with Metric throughput columns) — and its body is never measured itself.
- Skipped by normal runs; measured by
--bench, case by case.--listshows it with the@benchmarkmarker, which is the runner's word for "measured by--bench". iterationsruns exactly N timed calls per per-call case, one sample each, and pins aBenchTiming.batchedcase's per-sample count;0(default) samples until the time budget is met.- A body that registers no case fails with "
<test>registered no cases", unless it calledskipTest(an environment filter left nothing to measure), which leaves the test skipped with no rows.
@workload / @workload(reps: N)
The test is a workload, measured under the window model — the counterpart to @benchmark's per-iteration statistics.
- Skipped by normal runs (counted in the summary); measured by
--benchin a single pass: the body runs once (repstimes for the measured window content;0is treated as1), and the runner reports each open counter source's deltas across the window plus a wall-clock decomposition (on-CPU user/kernel from rusage, runqueue wait from schedstat, and a clampedotherresidual — locks/sleeps are never attributed to a fabricated cause). The body is never re-run for counting, so expensive or non-idempotent workloads are safe. - The whole body is the window by default. From
sparkles.test_runner.workload,workloadWindow(dg)/workloadWindow(name, dg)measures only the closure (× reps); each call is one row in theworkloadstable. Outside--benchthe closure runs exactly once, inertly. --perf/--syscalls/--metricsopen the same sources for windows; the table shows a fixed summary column set per source (full totals in--bench-json'swindowsarray).- On Linux the decomposition is thread-scoped (the driving thread); rusage's user/kernel split is tick-sampled, so windows should be long (tens of milliseconds up) for the split to be signal rather than quantization.
@workload(regime: CacheRegime.cold)(orwarm) sets the page-cache regimeworkloadFiles(paths...)establishes and verifies for the files the body names — see the how-to's regime section.
See Measure workloads.
@slow
The test takes minutes rather than milliseconds — a sweep over a whole corpus, say.
- Runs normally under
dub test. --skip-slowleaves it out (the summary counts it:5 slow (run with --only-slow));--only-slowruns nothing else. The two exclude each other, and both combine with-i/-e.ci testpasses--skip-slow; CI runs each slow test as a job of its own throughci test --slow, which selects it by name. So a slow test needs a@("name"), and@slowgoes on theunittestitself, not on a@slow:label or block:cifinds slow tests by reading the source, and fails a job whose test binary lists slow tests the source scan did not.
@serial / @serial(threadAffinity: ThreadAffinity.mainThread)
The test must not run beside other tests: it uses process-wide state, say. Whatever -t asks for, the default mode runs every other test first, on the workers, then the @serial ones, one at a time.
threadAffinity(aThreadAffinity) says which thread runs them:none(the default, and a bare@serial): any thread; the runner uses one worker for all of them.mainThread: the main thread of the process that runs them — the worker's, or the binary's own in the fallback — after thenoneones. For a library confined to the thread that initialized it:sparkles:nix's tests use it, because the Nix evaluator registers only the thread that calledinitNixwith its garbage collector, and evaluating on another thread crashes.
- The main thread runs its tests under the same stack budget as a worker (a 384 KiB watermark), so a test that passes there also fits a worker.
--listshows@serialor@serial(mainThread); it combines with every other attribute.
Combining
Attributes compose freely — e.g. @betterC @wasm opts one test into both extra environments; @("name") string UDAs keep naming the test. The exclusions: @benchmark and @benchCases declare different roles for a body, and either with @workload names different measurement models for the same body, and combining them is a discovery-time error.