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
18 changes: 13 additions & 5 deletions blink/internal/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ var alwaysSkipDirs = map[string]bool{
".git": true,
}

// Find walks paths and returns every .php file not matching a skip glob.
func Find(paths []string, skip []string) ([]string, error) {
// Find walks paths and returns every .php file not matching a skip glob, plus the
// count of distinct .php files discovered before skip globs are applied. ECS counts
// every discovered file in its run summary (skipped ones included), so the caller
// reports this total while only processing the returned files.
func Find(paths []string, skip []string) ([]string, int, error) {
var out []string
seen := map[string]bool{}
discovered := 0

for _, p := range paths {
err := filepath.WalkDir(p, func(path string, d fs.DirEntry, err error) error {
Expand All @@ -33,18 +37,22 @@ func Find(paths []string, skip []string) ([]string, error) {
if !strings.HasSuffix(path, ".php") {
return nil
}
if skipped(path, skip) || seen[path] {
if seen[path] {
return nil
}
seen[path] = true
discovered++
if skipped(path, skip) {
return nil
}
out = append(out, path)
return nil
})
if err != nil {
return nil, err
return nil, 0, err
}
}
return out, nil
return out, discovered, nil
}

// Skipped reports whether path matches any of the skip globs, using the same
Expand Down
31 changes: 30 additions & 1 deletion blink/internal/finder/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestFindSkipsDependencyDirs(t *testing.T) {
}
}

found, err := Find([]string{root}, nil)
found, discovered, err := Find([]string{root}, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -47,6 +47,35 @@ func TestFindSkipsDependencyDirs(t *testing.T) {
t.Fatalf("missing %s in %v", w, found)
}
}
// dependency dirs and non-.php files are not discovered either
if discovered != len(want) {
t.Fatalf("discovered = %d, want %d", discovered, len(want))
}
}

func TestFindCountsSkippedFiles(t *testing.T) {
root := t.TempDir()
for _, rel := range []string{"src/a.php", "src/Fixture/b.php", "src/Fixture/c.php"} {
full := filepath.Join(root, rel)
if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(full, []byte("<?php"), 0o644); err != nil {
t.Fatal(err)
}
}

found, discovered, err := Find([]string{root}, []string{filepath.FromSlash("*/Fixture/*")})
if err != nil {
t.Fatal(err)
}
// only a.php is processed, but all three .php files count toward the total
if len(found) != 1 {
t.Fatalf("found %v, want 1 file", found)
}
if discovered != 3 {
t.Fatalf("discovered = %d, want 3 (skipped files still counted)", discovered)
}
}

func TestSkippedSegmentNotSubstring(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions blink/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ type Progress interface {
// early when ctx is cancelled. Every file error is collected (not just the
// first) and returned joined.
func Run(ctx context.Context, cfg *config.Config, write bool, prog Progress) ([]FileResult, error) {
files, err := finder.Find(cfg.Paths, cfg.Skip)
files, discovered, err := finder.Find(cfg.Paths, cfg.Skip)
if err != nil {
return nil, err
}
if prog != nil {
prog.Start(len(files))
// discovered includes skip-matched files, mirroring ECS's run summary
prog.Start(discovered)
}

jobs := max(cfg.Jobs, 1)
Expand Down
Loading