# MLF Test Suite
# Run with: just test
#
# Test runner: cargo-nextest. Install with `just install-tools`.

# Default: run all tests
default: test

# Install developer tools (test runner, snapshot reviewer)
install-tools:
    cargo install cargo-nextest --locked
    cargo install cargo-insta --locked

# Run every test across the workspace (excluding packages we can't build
# locally). Nextest parallelises across binaries, so a single invocation
# is both faster and more comprehensive than chaining the per-suite
# recipes below — those remain useful for targeted runs. Use
# `just test-fast` to skip network-dependent real-world tests.
test:
    @echo "Running all workspace tests..."
    cargo nextest run --workspace --exclude mlf-wasm

# Run everything except network-dependent real-world roundtrip tests
test-fast:
    @echo "Running workspace tests (excluding real-world)..."
    cargo nextest run --workspace --exclude mlf-wasm -E 'not binary(real_world_roundtrip)'

# Run only language tests (mlf-lang crate)
test-lang:
    @echo "Running mlf-lang integration tests..."
    cargo nextest run -p mlf-lang --test integration_test

# Run codegen integration tests (multi-crate)
test-codegen:
    @echo "\nRunning codegen integration tests..."
    cargo nextest run -p mlf-integration-tests --test codegen_integration

# Run diagnostics integration tests (multi-crate)
test-diagnostics:
    @echo "\nRunning diagnostics integration tests..."
    cargo nextest run -p mlf-integration-tests --test diagnostics_integration

# Run lexicon fetcher tests
test-lexicon-fetcher:
    @echo "\nRunning lexicon fetcher tests..."
    cargo nextest run -p mlf-lexicon-fetcher

# Run validation tests
test-validation:
    @echo "\nRunning validation tests..."
    cargo nextest run -p mlf-validation

# Run CLI integration tests (when implemented)
test-cli:
    @echo "\nRunning CLI integration tests..."
    cargo nextest run -p mlf-integration-tests --test cli_integration

# Run workspace resolution tests (when implemented)
test-workspace:
    @echo "\nRunning workspace resolution tests..."
    cargo nextest run -p mlf-integration-tests --test workspace_integration

# Run only the network-dependent real-world round-trip tests
test-real:
    @echo "\n🌐 Running real-world round-trip tests (fetches from network)..."
    cargo nextest run -p mlf-integration-tests --test real_world_roundtrip

# Review pending insta snapshot changes (accepts / rejects `.snap.new` files)
review:
    cargo insta review

# Run tests with verbose output (stdout streamed live, tests run serially)
test-verbose:
    cargo nextest run --workspace --exclude mlf-wasm --no-capture

# Quick check without running tests
check:
    cargo check --workspace

# Format code
fmt:
    cargo fmt --all

# Run clippy
lint:
    cargo clippy --workspace

# Build everything
build:
    cargo build --workspace

# Build release
build-release:
    cargo build --workspace --release

# Clean build artifacts
clean:
    cargo clean

# Show test statistics
test-stats:
    @echo "Test Statistics:"
    @echo "  Lang tests:            21 tests in mlf-lang/tests/lang/"
    @echo "  Codegen tests:         10 tests in tests/codegen/lexicon/"
    @echo "  Diagnostics tests:      1 test  in tests/diagnostics/"
    @echo "  Lexicon fetcher tests: 33 tests in mlf-lexicon-fetcher/"
    @echo "  Validation tests:      12 tests in mlf-validation"
    @echo ""
    @echo "Total integration tests: 77"

# List all test directories
test-list:
    @echo "Lang tests:"
    @ls -1 mlf-lang/tests/lang/*/
    @echo "\nCodegen tests:"
    @ls -1 tests/codegen/lexicon/*/
