Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions crates/mq-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ def verify_string_empty():
end
```

```bash
$ mq-test example.mq
✓ add
✓ string_upcase
✓ verify_array_length
✓ verify_string_empty

4 passed, 0 failed
```

## Development

### Running Tests
Expand Down
16 changes: 14 additions & 2 deletions crates/mq-test/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use miette::IntoDiagnostic;
use mq_lang::{CstNodeKind, CstTrivia};
use std::fs;
use std::path::{Path, PathBuf};

/// Discovers and runs mq test functions from `.mq` files.
///
/// A function is treated as a test if:
Expand Down Expand Up @@ -76,9 +75,18 @@ impl TestRunner {
/// - Its `leading_trivia` contains a comment whose text (trimmed) is `@test`.
fn discover_test_functions(content: &str) -> Vec<String> {
let (nodes, _) = mq_lang::parse_recovery(content);
Self::discover_test_functions_in(&nodes)
}

fn discover_test_functions_in(nodes: &[mq_lang::Shared<mq_lang::CstNode>]) -> Vec<String> {
let mut names = Vec::new();

for node in &nodes {
for node in nodes {
if node.kind == CstNodeKind::Module {
names.extend(Self::discover_test_functions_in(&node.children));
continue;
}

if node.kind != CstNodeKind::Def {
continue;
}
Expand Down Expand Up @@ -149,6 +157,10 @@ mod tests {
vec!["test_first", "annotated"]
)]
#[case("def helper():\n None\nend\n", vec![])]
#[case(
"module a:\n def test_first():\n None\nend\n\n# @test\ndef annotated():\n None\nend\nend\n",
vec!["test_first", "annotated"]
)]
fn test_discover_test_functions(#[case] content: &str, #[case] expected: Vec<&str>) {
let names = TestRunner::discover_test_functions(content);
assert_eq!(names, expected);
Expand Down
Loading