| name | tribute-testing |
| description | Tribute project testing guide covering test commands, Salsa incremental computation framework test patterns, nextest usage, and insta snapshot testing. Use when running or writing tests, using Salsa tracked functions, resolving accumulate() errors, or following Tribute test conventions. |
Tribute Testing Guide
Running Tests
cargo nextest run --workspace
cargo nextest run -p tribute
cargo nextest run -p tree-sitter-tribute
cargo nextest run -p tribute-passes
cargo nextest run -p trunk-ir
cargo insta review
Salsa Test Patterns
#[salsa_test] Macro
The #[salsa_test] macro from salsa_test_macros automatically provides a
Salsa database context.
use salsa_test_macros::salsa_test;
#[salsa_test]
fn test_example(db: &salsa::DatabaseImpl) {
}
Generated code:
#[test]
fn test_example() {
salsa::Database::attach(&salsa::DatabaseImpl::default(), |db| {
});
}
accumulate() Test Constraints
Key constraint: Diagnostic.accumulate(db) must be called inside a
#[salsa::tracked] function.
#[salsa_test] attaches a database but does NOT create a tracked function context.
Unit tests that directly call code using accumulate() will fail:
cannot accumulate values outside of an active tracked function
Solution: Test diagnostic accumulation at the integration level via
tracked queries.
#[salsa_test]
fn test_unresolved_name(db: &salsa::DatabaseImpl) {
let resolver = Resolver::new(db, env, span_map);
resolver.resolve_name(&unresolved);
}
#[salsa_test]
fn test_diagnostics(db: &salsa::DatabaseImpl) {
let source = make_source(db, "fn main() { undefined_var }");
let _module = resolved_module(db, source);
let diagnostics = resolved_module::accumulated::<Diagnostic>(db, source);
assert!(!diagnostics.is_empty());
}
Test Level Separation
| Level | Test Target | accumulate OK |
|---|
| Unit tests | Pure logic (bindings, scopes) | ❌ |
| Integration tests | Tracked queries + diagnostics | ✅ |
Snapshot Testing (insta)
use insta::assert_snapshot;
#[test]
fn test_ir_output() {
let output = compile_to_ir("fn main() { 42 }");
assert_snapshot!(output);
}
Update snapshots: cargo insta review
Collecting Diagnostics
Collect accumulated Diagnostics from a tracked query:
let diagnostics: Vec<Diagnostic> =
query_function::accumulated::<Diagnostic>(db, source)
.into_iter()
.cloned()
.collect();
See guides/salsa.md for detailed Salsa usage documentation.