Testing Guide

MIRR has a comprehensive test suite with 3000+ tests covering all compiler subsystems.

Test Organization

DirectoryContents
tests/Integration tests
src/*/Unit tests (inline #[cfg(test)])
benches/Benchmarks
fuzz/Fuzz targets

Writing Tests

Unit Tests

Unit tests go inline in the module they test:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_feature() {
        assert_eq!(result, expected);
    }
}

Integration Tests

Integration tests go in tests/ directory:

#![forbid(unsafe_code)]
#![deny(warnings)]

use mirrc::pipeline::{run_pipeline, PipelineConfig};

#[test]
fn test_full_pipeline() {
    let source = "module test { signals { x: in bool } }";
    let config = PipelineConfig::default();
    let result = run_pipeline(source, &config);
    assert!(result.is_ok());
}

Test Conventions

  1. File size limit: Test files must be ≤ 600 lines (CI enforced)
  2. No unsafe code: All test files use #![forbid(unsafe_code)]
  3. Zero warnings: All test files use #![deny(warnings)]
  4. Bounded loops: All loops must have explicit upper bounds
  5. Error codes: Use [E-codes] in assertions

Running Tests

# All tests
cargo test --all

# With nextest (recommended)
cargo nextest run

# Specific test
cargo nextest run --test riscv_integration_tests

# With output
cargo test -- --nocapture

Test Coverage

SubsystemTest FilesApprox Tests
Parser5+200+
Type checker3+150+
Width inference4+300+
Temporal3+200+
Emitters5+400+
Symbolic2+200+
MAPE-K2+300+
S-expression3+200+
Patterns2+100+
Integration10+500+

See Also