Skip to content

Commit

Permalink
Check that there aren't any unused test files
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Sep 26, 2024
1 parent a5e0616 commit 7ea45bf
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/scip/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"slices"
Expand Down Expand Up @@ -61,6 +62,31 @@ func testMain(
) error {
hasFailure := false

fileFilterSet := map[string]struct{}{}
for _, file := range fileFilters {
fileFilterSet[file] = struct{}{}
}

allTestFilesSet := map[string]struct{}{}
if err := filepath.WalkDir(directory, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if filepath.Ext(path) == ".scip" {
return nil
}
if len(fileFilterSet) > 0 {
if _, ok := fileFilterSet[path]; ok {
allTestFilesSet[path] = struct{}{}
}
} else if !d.IsDir() {
allTestFilesSet[path] = struct{}{}
}
return nil
}); err != nil {
return err
}

for _, document := range index.Documents {
sourceFilePath := filepath.Join(directory, document.RelativePath)

Expand All @@ -74,6 +100,7 @@ func testMain(
if err != nil {
return err
}
delete(allTestFilesSet, sourceFilePath)

failures := []string{}
successCount := 0
Expand Down Expand Up @@ -115,6 +142,20 @@ func testMain(
}
}

if len(allTestFilesSet) > 0 {
sortedFiles := []string{}
for f, _ := range allTestFilesSet {
sortedFiles = append(sortedFiles, f)
}
slices.Sort(sortedFiles)
red := color.New(color.FgRed)
red.Fprintf(output, "✗ Missing documents in SCIP index\n")
for _, path := range sortedFiles {
fmt.Fprintf(output, " %s\n", path)
}
hasFailure = true
}

if hasFailure {
return cli.Exit("", 1)
}
Expand Down

0 comments on commit 7ea45bf

Please sign in to comment.