now writing each TestSuite to a separate file
This commit is contained in:
parent
d97ffd7fea
commit
220b73dc49
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -64,22 +65,18 @@ func main() {
|
|||||||
testsuites := Testsuites{}
|
testsuites := Testsuites{}
|
||||||
|
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: go2junit <gotest.json>\n")
|
fmt.Fprintf(os.Stderr, "Usage: go2junit <outputdir>\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
filename := os.Args[1]
|
path := os.Args[1]
|
||||||
var file *os.File
|
path = filepath.Clean(path)
|
||||||
if filename != "-" {
|
err := os.MkdirAll(path, 0755)
|
||||||
file2, err := os.Open(filename)
|
if err != nil {
|
||||||
file = file2
|
panic(err)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
} else {
|
|
||||||
file = os.Stdin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var file = os.Stdin
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
lineno := 0
|
lineno := 0
|
||||||
|
|
||||||
@ -102,7 +99,7 @@ func main() {
|
|||||||
testsuites.Test(item.Time, item.Package, item.Test)
|
testsuites.Test(item.Time, item.Package, item.Test)
|
||||||
case "output":
|
case "output":
|
||||||
testsuites.Output(item.Time, item.Package, item.Test, item.Output)
|
testsuites.Output(item.Time, item.Package, item.Test, item.Output)
|
||||||
fmt.Fprintf(os.Stderr, "%s", item.Output)
|
fmt.Printf("%s", item.Output)
|
||||||
case "pause":
|
case "pause":
|
||||||
testsuites.Output(item.Time, item.Package, item.Test, "PAUSED")
|
testsuites.Output(item.Time, item.Package, item.Test, "PAUSED")
|
||||||
case "cont":
|
case "cont":
|
||||||
@ -119,9 +116,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
testsuites.Complete()
|
testsuites.Complete()
|
||||||
|
|
||||||
xml, err := xml.MarshalIndent(testsuites, "", " ")
|
for _, suite := range testsuites.Suites {
|
||||||
if err != nil {
|
xml, err := xml.MarshalIndent(suite, "", " ")
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fname := path + "/" + suite.Name + ".xml"
|
||||||
|
dir := filepath.Dir(fname)
|
||||||
|
err = os.MkdirAll(dir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "Writing %s\n", fname)
|
||||||
|
err = os.WriteFile(fname, xml, 0644)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("%s", xml)
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Testsuites struct {
|
type Testsuites struct {
|
||||||
XMLName xml.Name `xml:"testsuite"`
|
XMLName xml.Name `xml:"testsuites"`
|
||||||
|
|
||||||
Tests int `xml:"tests,attr"`
|
Tests int `xml:"tests,attr"`
|
||||||
Failures int `xml:"failures,attr"`
|
Failures int `xml:"failures,attr"`
|
||||||
|
Loading…
Reference in New Issue
Block a user