From 4f371a5a0966e9e3c33e550a30e598575fe3fabc Mon Sep 17 00:00:00 2001 From: Akonwi Ngoh Date: Mon, 20 Jul 2026 21:40:01 -0400 Subject: [PATCH] fix(cli): scope test discovery to package --- compiler/main.go | 11 ++++++++++- compiler/main_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/compiler/main.go b/compiler/main.go index 4c58d007..7a58c98f 100644 --- a/compiler/main.go +++ b/compiler/main.go @@ -1112,6 +1112,7 @@ func discoverTestFiles(inputPath string) ([]string, error) { return []string{filepath.Clean(inputPath)}, nil } + inputPath = filepath.Clean(inputPath) files := make([]string, 0) seen := make(map[string]struct{}) err = filepath.WalkDir(inputPath, func(path string, entry os.DirEntry, walkErr error) error { @@ -1119,8 +1120,16 @@ func discoverTestFiles(inputPath string) ([]string, error) { return walkErr } if entry.IsDir() { - if strings.HasPrefix(entry.Name(), ".") && path != inputPath { + if path == inputPath { + return nil + } + if strings.HasPrefix(entry.Name(), ".") { + return filepath.SkipDir + } + if _, manifestErr := os.Stat(filepath.Join(path, "ard.toml")); manifestErr == nil { return filepath.SkipDir + } else if !os.IsNotExist(manifestErr) { + return manifestErr } return nil } diff --git a/compiler/main_test.go b/compiler/main_test.go index 0e061e56..1c54001f 100644 --- a/compiler/main_test.go +++ b/compiler/main_test.go @@ -825,6 +825,39 @@ test fn panics() Void!Str { } }) } +func TestDiscoverTestFilesSkipsNestedProjects(t *testing.T) { + projectDir := t.TempDir() + if err := os.WriteFile(filepath.Join(projectDir, "ard.toml"), []byte("name = \"root\"\nard = \">= 0.1.0\"\n"), 0o644); err != nil { + t.Fatal(err) + } + rootTest := filepath.Join(projectDir, "test", "root_test.ard") + if err := os.MkdirAll(filepath.Dir(rootTest), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(rootTest, []byte("test fn root_test() {}\n"), 0o644); err != nil { + t.Fatal(err) + } + + nestedDir := filepath.Join(projectDir, "examples", "hello") + if err := os.MkdirAll(nestedDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(nestedDir, "ard.toml"), []byte("name = \"hello\"\nard = \">= 0.1.0\"\n"), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(nestedDir, "main.ard"), []byte("fn main() {}\n"), 0o644); err != nil { + t.Fatal(err) + } + + files, err := discoverTestFiles(projectDir) + if err != nil { + t.Fatal(err) + } + if len(files) != 1 || files[0] != rootTest { + t.Fatalf("discovered files = %v, want [%s]", files, rootTest) + } +} + func TestTestCommandDisambiguatesSameNamedTestsInSingleRun(t *testing.T) { dir := t.TempDir() projectDir := filepath.Join(dir, "project")