When you have example files that demonstrate language features, you need a way to ensure they:
cargo test - no
manual workCreated tests/example_tests.rs with:
#[test]
fn test_hello_world_demo_parses() {
let path = Path::new("examples/hello_world_demo.dal");
if path.exists() {
test_example_parses(path);
}
}
#[test]
fn test_all_examples_parse() {
// Tests ALL examples at once
// Fails if any example has syntax errors
}parse_source() to
verify examples compileexecute_source()
for simple examplesWhen we ran the tests, they immediately caught issues:
❌ Failed to parse 37 example(s):
- "examples/hello_world_demo.dal": Unexpected character '|' at line 488
- "examples/cross_chain_patterns.dal": Syntax Error at line 1
- ...
This is exactly what we want! The tests are:
| Approach | Pros | Cons |
|---|---|---|
| Rust Unit Tests ✅ | Automated, fast, CI-ready, reliable | Requires Rust knowledge |
| Manual Testing | Simple, no code needed | Time-consuming, error-prone, not automated |
| Shell Scripts | Can automate | Platform-specific, harder to maintain |
| DAL Test Framework | Tests in DAL itself | Requires building entire framework first |
# Before committing, run:
cargo test example_tests
# If tests pass, examples are valid
# If tests fail, fix the examples before committing# .github/workflows/test.yml
- name: Test Examples
run: cargo test example_testsWhen adding a new example:
examples/tests/example_tests.rscargo test to verify it works// Individual test for each example
#[test]
fn test_my_example_parses() {
let path = Path::new("examples/my_example.dal");
if path.exists() {
test_example_parses(path);
}
}
// Comprehensive test for all examples
#[test]
fn test_all_examples_parse() {
let example_files = get_example_files();
// ... test all files
}
// Execution test (skips if requires external deps)
#[test]
fn test_simple_examples_execute() {
// ... test execution for simple examples
}# Developer has to remember to test
dist_agent_lang run examples/hello_world_demo.dal
dist_agent_lang run examples/smart_contract.dal
# ... 30 more files
# Easy to miss one
# No record of what was tested# One command tests everything
cargo test example_tests
# ✅ All examples tested
# ✅ Results recorded
# ✅ Fails if anything breaks
# ✅ Runs in CI automaticallyRust unit tests are the right approach because they:
The tests we created (tests/example_tests.rs) are
already working and catching real issues in the examples. This is
exactly what we need to ensure examples stay valid as the language
evolves.
tests/example_tests.rs is ready