Repository navigation
Expand file tree
/
Copy pathgit_check_ignore_details_test.go
More file actions
104 lines (82 loc) · 2.53 KB
/
Copy pathgit_check_ignore_details_test.go
File metadata and controls
104 lines (82 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//go:build !windows
package gitignore_test
import (
"fmt"
"strings"
"testing"
)
// TestGitCheckIgnoreDetails validates YAML test specifications against actual Git check-ignore behavior,
// focusing only on the output of git check-ignore -v.
func TestGitCheckIgnoreDetails(t *testing.T) {
t.Parallel()
filter := ParseFilter(*testFilter)
dir := "./tests/details/**/*.{yml,yaml}"
files, err := Files(dir, filter)
if err != nil {
t.Fatalf("scan test dir %q: %v", dir, err)
}
if len(files) == 0 {
t.Fatal("no test files found")
}
// Process each test file concurrently
for _, file := range files {
base := BaseNameWithoutExt(file)
// Each test file runs as a separate subtest
t.Run(base, func(t *testing.T) {
t.Parallel()
specs, err := LoadGitIgnoreSpecs(file)
if err != nil {
t.Fatalf("load specs from %s: %v", file, err)
}
if len(specs) == 0 {
t.Fatal("no test specs found")
}
// Process each test group within the file
for _, spec := range specs {
// Each test group runs as a separate subtest
t.Run(spec.Name, func(t *testing.T) {
t.Parallel()
if len(spec.Cases) == 0 {
t.Fatal("no test cases found")
}
// Process each individual test case
for _, c := range spec.Cases {
if c.Details == nil {
t.Skip("no details expected output specified")
}
// Format test name to clearly indicate directories
testName := c.Path
if c.Dir {
testName += "/"
}
// Each test case runs as a separate subtest for precise failure reporting
t.Run(testName, func(t *testing.T) {
t.Parallel()
result := runGitCheckIgnoreTest(t, spec, c, "-v")
if !strings.Contains(result.Stdout, *c.Details) {
// Create detailed error message with hierarchical context
errorMsg := fmt.Sprintf("%s -> %s -> %s\n", base, spec.Name, testName)
// Include descriptions from YAML for better context
if spec.Description != "" {
errorMsg += fmt.Sprintf("Group: %s\n", spec.Description)
}
if c.Description != "" {
errorMsg += fmt.Sprintf("Case: %s\n", c.Description)
}
// Provide specific details about the Git validation failure
errorMsg += fmt.Sprintf(
"Git check-ignore validation failed:\n path: %v\n patterns: %v\n expected: %v\n got: %v\n",
c.Path,
strings.Split(spec.Gitignore, "\n"),
*c.Details,
result.Stdout,
)
t.Error(errorMsg)
}
})
}
})
}
})
}
}