1
0
mirror of https://github.com/jstemmer/go-junit-report.git synced 2025-04-09 15:18:08 -05:00

Set non-zero exit code for build/run errors when using -set-exit-code

This commit is contained in:
Joël Stemmer 2022-03-11 23:18:52 +00:00
parent e6ab84c924
commit 43c784a63b
2 changed files with 8 additions and 5 deletions

@ -102,7 +102,7 @@ func main() {
} }
fmt.Fprintf(out, "\n") fmt.Fprintf(out, "\n")
if *setExitCode && report.HasFailures() { if *setExitCode && !report.IsSuccessful() {
os.Exit(1) os.Exit(1)
} }
} }

@ -19,16 +19,19 @@ type Report struct {
Packages []Package Packages []Package
} }
func (r *Report) HasFailures() bool { func (r *Report) IsSuccessful() bool {
for _, pkg := range r.Packages { for _, pkg := range r.Packages {
for _, t := range pkg.Tests { if pkg.BuildError.Name != "" || pkg.RunError.Name != "" {
if t.Result == Fail {
return true
}
}
}
return false return false
} }
for _, t := range pkg.Tests {
if t.Result != Pass && t.Result != Skip {
return false
}
}
}
return true
}
type Package struct { type Package struct {
Name string Name string