Skip to content

Commit 1f7093c

Browse files
committed
Split out {Passed,Failed}Valid to {Passed,Failed}Encoder
Makes dealing with JSON reports a lot easier, especially when merging both the decoder and encoder tests.
1 parent 8be0db7 commit 1f7093c

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

cmd/toml-test/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func main() {
217217
printText(runner, tests, cmd, showAll, noNumber)
218218
}
219219

220-
if tests.FailedValid > 0 || tests.FailedInvalid > 0 {
220+
if tests.FailedValid > 0 || tests.FailedEncoder > 0 || tests.FailedInvalid > 0 {
221221
zli.Exit(1)
222222
}
223223
zli.Exit(0)
@@ -231,16 +231,19 @@ func printJSON(runner tomltest.Runner, tests tomltest.Tests, cmd []string, showA
231231
Flags []string `json:"flags"`
232232
Parser []string `json:"parser"`
233233
PassedValid int `json:"passed_valid"`
234+
PassedEncoder int `json:"passed_encoder"`
234235
PassedInvalid int `json:"passed_invalid"`
235236
FailedValid int `json:"failed_valid"`
237+
FailedEncoder int `json:"failed_encoder"`
236238
FailedInvalid int `json:"failed_invalid"`
237239
Skipped int `json:"skipped"`
238240
Tests []tomltest.Test `json:"tests"`
239241
}{
240242
fmt.Sprintf("toml-test v%s", date.Format("2006-01-02")),
241-
cmd, os.Args,
242-
tests.PassedValid, tests.PassedInvalid, tests.FailedValid, tests.FailedInvalid, tests.Skipped,
243-
nil,
243+
os.Args, cmd,
244+
tests.PassedValid, tests.PassedEncoder, tests.PassedInvalid,
245+
tests.FailedValid, tests.FailedEncoder, tests.FailedInvalid,
246+
tests.Skipped, nil,
244247
}
245248
for _, t := range tests.Tests {
246249
if t.Failed() || showAll >= 1 {
@@ -267,7 +270,7 @@ func printText(runner tomltest.Runner, tests tomltest.Tests, cmd []string, showA
267270

268271
fmt.Println()
269272
if runner.Encoder {
270-
fmt.Printf("encoder tests: %3d passed, %2d failed\n", tests.PassedValid, tests.FailedValid)
273+
fmt.Printf("encoder tests: %3d passed, %2d failed\n", tests.PassedEncoder, tests.FailedEncoder)
271274
} else {
272275
fmt.Printf(" valid tests: %3d passed, %2d failed\n", tests.PassedValid, tests.FailedValid)
273276
fmt.Printf("invalid tests: %3d passed, %2d failed\n", tests.PassedInvalid, tests.FailedInvalid)

runner.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ type Parser interface {
7878

7979
// Tests are tests to run.
8080
type Tests struct {
81-
Tests []Test
81+
Tests []Test `json:"tests"`
8282

8383
// Set when test are run.
8484

85-
Skipped int
86-
PassedValid, FailedValid int
87-
PassedInvalid, FailedInvalid int
85+
Skipped int `json:"skipped"`
86+
PassedValid int `json:"passed_valid"`
87+
FailedValid int `json:"failed_valid"`
88+
PassedInvalid int `json:"passed_invalid"`
89+
FailedInvalid int `json:"failed_invalid"`
90+
PassedEncoder int `json:"passed_encoder"`
91+
FailedEncoder int `json:"failed_encoder"`
8892
}
8993

9094
// Result is the result of a single test.
@@ -233,19 +237,25 @@ func (r Runner) Run() (Tests, error) {
233237
t.Failure = "Test skipped with -skip but didn't fail"
234238
if invalid {
235239
tests.FailedInvalid++
240+
} else if r.Encoder {
241+
tests.FailedEncoder++
236242
} else {
237243
tests.FailedValid++
238244
}
239245
}
240246
} else if t.Failed() {
241247
if invalid {
242248
tests.FailedInvalid++
249+
} else if r.Encoder {
250+
tests.FailedEncoder++
243251
} else {
244252
tests.FailedValid++
245253
}
246254
} else {
247255
if invalid {
248256
tests.PassedInvalid++
257+
} else if r.Encoder {
258+
tests.PassedEncoder++
249259
} else {
250260
tests.PassedValid++
251261
}

0 commit comments

Comments
 (0)