baml_language/TEST_INSTRUCTIONS.md
| Suite | Location | Purpose |
|---|---|---|
baml_tests | crates/baml_tests/ | Snapshot tests with detailed CST/HIR/THIR output |
lsp_actions_tests | crates/lsp_actions_tests/ | LSP integration tests with inline expectations |
cargo test --package lsp_actions_tests
Look for errors in crates/lsp_actions_tests/test_files/syntax/.
Create a new project directory:
mkdir -p crates/baml_tests/projects/my_repro/
Add a .baml file with the minimal repro case:
# crates/baml_tests/projects/my_repro/repro.baml
cargo test --package baml_tests my_repro
Accept new snapshots:
cargo insta accept --all
Snapshots are created in crates/baml_tests/snapshots/my_repro/:
| Snapshot | Contents |
|---|---|
*_01_lexer_*.snap | Token stream from lexer |
*_02_parser_*.snap | CST (Concrete Syntax Tree) |
*_03_hir.snap | HIR (High-level IR) |
*_04_thir.snap | THIR (Typed HIR) with type inference |
*_05_diagnostics.snap | All errors and warnings |
*_06_codegen.snap | Generated bytecode |
Edit the relevant crate (baml_compiler_parser, baml_compiler_syntax, baml_compiler_hir, etc.).
# Update baml_tests snapshots
cargo test --package baml_tests my_repro
cargo insta accept --all
# Update lsp_actions_tests inline expectations
UPDATE_EXPECT=1 cargo test --package lsp_actions_tests
# Run all tests (can skip slow parser_stress with --skip parser_stress)
cargo test --package baml_tests -- --skip parser_stress
cargo test --package lsp_actions_tests
# Run specific test project
cargo test --package baml_tests my_project_name
# Run all snapshot tests
cargo test --package baml_tests
# Run all snapshot tests (skip slow parser_stress tests)
cargo test --package baml_tests -- --skip parser_stress
# Run LSP tests and auto-update expectations
UPDATE_EXPECT=1 cargo test --package lsp_actions_tests
# Accept all pending snapshots
cargo insta accept --all
# Review snapshots interactively
cargo insta review
crates/baml_compiler_lexer/src/tokens.rscrates/baml_compiler_parser/src/parser.rscrates/baml_compiler_syntax/src/syntax_kind.rscrates/baml_compiler_syntax/src/ast.rscrates/baml_compiler_hir/src/body.rscrates/baml_thir/src/lower.rsDO NOT EDIT the diagnostics manually in lsp_actions_tests. Use update_expect=1
Find the base-case that makes syntax fail and add that to baml_test with a good name and good folder organization.
A good place to start when given a diagnostic failure or some parser issue is to look at the snapshot test (create one if missing) and checking the .snap files for CST/HIR etc.
BEFORE you run these lsp tests with update_expect, make sure to just run without it and figure out if the new results are what you expect.
Just because the existing file may say 'no diagnostics expected' doesn't mean it is correct by the way. We haven't finished implementing all diagnostics. You have to see if we added some other comments elsewhere in the file to see what we should sort of expect, or just inspect the behavior manually.