Skip to content

Commit d293722

Browse files
committed
itest: New macro, support for tmt and debian autopkgtest, and more
A lot of stuff for itest, which is our Rust-based test framework for integration testing. Fork-exec output capture: when not running under nextest or tmt, the harness re-executes itself per test to capture stdout/stderr, matching cargo test default behavior. ITEST_NOCAPTURE=1 disables for debugging. Test metadata generation: --emit-tmt and --emit-autopkgtest flags generate FMF and DEP-8 metadata from registered tests, enabling tmt and autopkgtest to discover and run individual tests. Verified end-to-end with tmt. TestMeta: per-test metadata struct (timeout, needs_root, isolation, tags, summary, needs_internet, flaky) that maps to tmt and autopkgtest fields. Stored in distributed slices alongside test functions. Proc macro (#[itest::test_attr]): attribute macro that replaces the declarative macros for cleaner ergonomics. Preserves doc comments, handles error type conversion (anyhow/eyre/io::Error), supports async fn via automatic tokio runtime creation, and accepts all metadata as attribute arguments. VM instance type: privileged_test! and booted_test! accept itype for VM sizing, threaded through require_root() to bcvk --itype. The Justfile now prefers nextest with cargo test fallback, and fixes a pre-existing bug where set -e skipped cleanup on test failure. Assisted-by: OpenCode (Claude Opus 4) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent f4dd05a commit d293722

File tree

11 files changed

+1816
-57
lines changed

11 files changed

+1816
-57
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Justfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ unit *ARGS:
2424
pull-test-images:
2525
podman pull -q {{ALL_BASE_IMAGES}} >/dev/null
2626

27-
# Run integration tests (auto-detects nextest, with cleanup)
27+
# Run integration tests (prefers cargo-nextest, falls back to cargo test with
28+
# built-in fork-exec output capture)
2829
test-integration *ARGS: build pull-test-images
2930
#!/usr/bin/env bash
3031
set -euo pipefail
@@ -36,16 +37,15 @@ test-integration *ARGS: build pull-test-images
3637
# Clean up any leftover containers before starting
3738
cargo run --release --bin test-cleanup -p integration-tests 2>/dev/null || true
3839

39-
# Run the tests
40+
# Prefer nextest for better UX (retries, timing, etc.), but the harness
41+
# captures output itself via fork-exec so cargo test works too.
4042
if command -v cargo-nextest &> /dev/null; then
41-
cargo nextest run --release -P integration -p integration-tests {{ ARGS }}
42-
TEST_EXIT_CODE=$?
43+
cargo nextest run --release -P integration -p integration-tests {{ ARGS }} && TEST_EXIT_CODE=0 || TEST_EXIT_CODE=$?
4344
else
44-
cargo test --release -p integration-tests -- {{ ARGS }}
45-
TEST_EXIT_CODE=$?
45+
cargo test --release -p integration-tests -- {{ ARGS }} && TEST_EXIT_CODE=0 || TEST_EXIT_CODE=$?
4646
fi
4747

48-
# Clean up containers after tests complete
48+
# Clean up containers after tests complete (must run even on failure)
4949
cargo run --release --bin test-cleanup -p integration-tests 2>/dev/null || true
5050

5151
exit $TEST_EXIT_CODE

crates/itest-macros/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "itest-macros"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
description = "Proc-macro companion crate for itest"
7+
8+
[lib]
9+
proc-macro = true
10+
11+
[dependencies]
12+
proc-macro2 = "1"
13+
quote = "1"
14+
syn = { version = "2", features = ["full", "extra-traits"] }
15+
16+
[lints]
17+
workspace = true

0 commit comments

Comments
 (0)