Skip to content

Commit 969de05

Browse files
authored
tests: check if test data doesn't have the corresponding test file (#226)
1 parent b4a6888 commit 969de05

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

parser_test.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"path/filepath"
1010
"reflect"
11+
"slices"
1112
"testing"
1213
)
1314

@@ -95,7 +96,8 @@ func TestValidWithWarningTestcasesV0_NoNetwork(t *testing.T) {
9596
},
9697
}
9798

98-
testFiles, _ := filepath.Glob("testdata/v0/valid_with_warnings/no-network/*yml")
99+
dir := "testdata/v0/valid_with_warnings/no-network/"
100+
testFiles, _ := filepath.Glob(dir + "*yml")
99101
for _, file := range testFiles {
100102
baseName := path.Base(file)
101103
if expected[baseName] == nil {
@@ -106,6 +108,11 @@ func TestValidWithWarningTestcasesV0_NoNetwork(t *testing.T) {
106108
checkParseErrors(t, err, testType{file, expected[baseName]})
107109
})
108110
}
111+
for file := range expected {
112+
if !slices.Contains(testFiles, dir+file) {
113+
t.Errorf("No expected file %s", dir+file)
114+
}
115+
}
109116
}
110117

111118
func TestInvalidTestcasesV0_NoNetwork(t *testing.T) {
@@ -131,7 +138,8 @@ func TestInvalidTestcasesV0_NoNetwork(t *testing.T) {
131138
},
132139
}
133140

134-
testFiles, _ := filepath.Glob("testdata/v0/invalid/no-network/*yml")
141+
dir := "testdata/v0/invalid/no-network/"
142+
testFiles, _ := filepath.Glob(dir + "*yml")
135143
for _, file := range testFiles {
136144
baseName := path.Base(file)
137145
if expected[baseName] == nil {
@@ -142,6 +150,12 @@ func TestInvalidTestcasesV0_NoNetwork(t *testing.T) {
142150
checkParseErrors(t, err, testType{file, expected[baseName]})
143151
})
144152
}
153+
for file := range expected {
154+
if !slices.Contains(testFiles, dir+file) {
155+
t.Errorf("No expected file %s", dir+file)
156+
}
157+
}
158+
145159
}
146160

147161
func TestInvalidTestcasesV0(t *testing.T) {
@@ -380,9 +394,6 @@ func TestInvalidTestcasesV0(t *testing.T) {
380394
"description_en_shortDescription_missing.yml": ValidationResults{
381395
ValidationError{"description.en.shortDescription", "shortDescription is a required field", 20, 5},
382396
},
383-
"description_en_shortDescription_too_short.yml": ValidationResults{
384-
ValidationError{"description.en.shortDescription", "shortDescription is a required field", 20, 5},
385-
},
386397
"description_en_longDescription_missing.yml": ValidationResults{
387398
ValidationError{"description.en.longDescription", "longDescription is a required field", 20, 5},
388399
},
@@ -576,7 +587,8 @@ func TestInvalidTestcasesV0(t *testing.T) {
576587
},
577588
}
578589

579-
testFiles, _ := filepath.Glob("testdata/v0/invalid/*yml")
590+
dir := "testdata/v0/invalid/"
591+
testFiles, _ := filepath.Glob(dir + "*yml")
580592
for _, file := range testFiles {
581593
baseName := path.Base(file)
582594
if expected[baseName] == nil {
@@ -587,6 +599,11 @@ func TestInvalidTestcasesV0(t *testing.T) {
587599
checkParseErrors(t, err, testType{file, expected[baseName]})
588600
})
589601
}
602+
for file := range expected {
603+
if !slices.Contains(testFiles, dir+file) {
604+
t.Errorf("No expected file %s", dir+file)
605+
}
606+
}
590607
}
591608

592609
// Test v0 valid YAML testcases (testdata/v0/valid/).
@@ -612,7 +629,8 @@ func TestValidWithWarningsTestcasesV0(t *testing.T) {
612629
},
613630
}
614631

615-
testFiles, _ := filepath.Glob("testdata/v0/valid_with_warnings/*yml")
632+
dir := "testdata/v0/valid_with_warnings/"
633+
testFiles, _ := filepath.Glob(dir + "*yml")
616634
for _, file := range testFiles {
617635
baseName := path.Base(file)
618636
if expected[baseName] == nil {
@@ -623,6 +641,11 @@ func TestValidWithWarningsTestcasesV0(t *testing.T) {
623641
checkParseErrors(t, err, testType{file, expected[baseName]})
624642
})
625643
}
644+
for file := range expected {
645+
if !slices.Contains(testFiles, dir+file) {
646+
t.Errorf("No expected file %s", dir+file)
647+
}
648+
}
626649
}
627650

628651
// Test publiccode.yml remote files for key errors.

0 commit comments

Comments
 (0)