From dc02870d6aec20f4202e70cf36704bd1e5b08d47 Mon Sep 17 00:00:00 2001 From: harehare Date: Wed, 15 Apr 2026 21:25:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=85=20test(mq-test):=20support=20test?= =?UTF-8?q?=20discovery=20inside=20module=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored `discover_test_functions` to recursively traverse `Module` CST nodes, so `def test_*` and `# @test`-annotated functions defined inside a `module` block are now included in the discovered test list. Also fixed a typo in the helper function name and removed an unused `std::sync::Arc` import. --- crates/mq-test/src/runner.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/mq-test/src/runner.rs b/crates/mq-test/src/runner.rs index 1bb626a7..c5cbb25c 100644 --- a/crates/mq-test/src/runner.rs +++ b/crates/mq-test/src/runner.rs @@ -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: @@ -76,9 +75,18 @@ impl TestRunner { /// - Its `leading_trivia` contains a comment whose text (trimmed) is `@test`. fn discover_test_functions(content: &str) -> Vec { let (nodes, _) = mq_lang::parse_recovery(content); + Self::discover_test_functions_in(&nodes) + } + + fn discover_test_functions_in(nodes: &[mq_lang::Shared]) -> Vec { 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; } @@ -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); From ce912ee1587c63cebc4b7cfccfd9c28b38281e5a Mon Sep 17 00:00:00 2001 From: harehare Date: Wed, 15 Apr 2026 21:26:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20docs:=20update=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/mq-test/README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/mq-test/README.md b/crates/mq-test/README.md index c7d42bbc..aa3179a9 100644 --- a/crates/mq-test/README.md +++ b/crates/mq-test/README.md @@ -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