tribute-testing

star 10

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.

Kroisse By Kroisse schedule Updated 6/3/2026

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           # All tests (preferred)
cargo nextest run -p tribute            # Specific crate
cargo nextest run -p tree-sitter-tribute
cargo nextest run -p tribute-passes
cargo nextest run -p trunk-ir
cargo insta review                      # Review snapshot test failures

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) {
    // Test code using db
}

Generated code:

#[test]
fn test_example() {
    salsa::Database::attach(&salsa::DatabaseImpl::default(), |db| {
        // Test code
    });
}

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.

// ❌ Direct accumulate in unit test - FAILS
#[salsa_test]
fn test_unresolved_name(db: &salsa::DatabaseImpl) {
    let resolver = Resolver::new(db, env, span_map);
    resolver.resolve_name(&unresolved);  // calls accumulate() internally → error!
}

// ✅ Integration test via tracked query - WORKS
#[salsa_test]
fn test_diagnostics(db: &salsa::DatabaseImpl) {
    let source = make_source(db, "fn main() { undefined_var }");
    let _module = resolved_module(db, source);  // tracked function
    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.

Install via CLI
npx skills add https://github.com/Kroisse/tribute --skill tribute-testing
Repository Details
star Stars 10
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator