From 8fcd615a51724d6fce7a5174fa4c24e6b6ce739d Mon Sep 17 00:00:00 2001 From: Joel Stemmer Date: Fri, 9 Mar 2012 15:38:06 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 20 ++++++++++++++++++++ README.md | 18 ++++++++++++++++++ go-junit-report.go | 34 ++++++++++++++++++++++++++++++++++ go-junit-report_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 go-junit-report.go create mode 100644 go-junit-report_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..720bda6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +go-junit-report diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f346564 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2012 Joel Stemmer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0073d01 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +go-junit-report +=============== + +Converts `go test` output to an xml report, suitable for applications that +expect junit xml reports (e.g. [Jenkins](http://jenkins-ci.org)). + +Installation +------------ + + go get github.com/jstemmer/go-junit-report + + go install github.com/jstemmer/go-junit-report + +Usage +----- + + go test -v | go-junit-report > report.xml + diff --git a/go-junit-report.go b/go-junit-report.go new file mode 100644 index 0000000..30d8145 --- /dev/null +++ b/go-junit-report.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "io" + "os" +) + +type Report struct { +} + +func main() { + // Read input + report, err := parse(os.Stdin) + if err != nil { + fmt.Printf("Error reading input: %s\n", err) + os.Exit(1) + } + + // Write xml + err = report.XML(os.Stdout) + if err != nil { + fmt.Printf("Error writing XML: %s\n", err) + os.Exit(1) + } +} + +func parse(reader io.Reader) (Report, error) { + return Report{}, nil +} + +func (r Report) XML(io.Writer) error { + return nil +} diff --git a/go-junit-report_test.go b/go-junit-report_test.go new file mode 100644 index 0000000..b5c6d9d --- /dev/null +++ b/go-junit-report_test.go @@ -0,0 +1,39 @@ +package main + +import ( + "strings" + "testing" +) + +const testOutputPass = `=== RUN TestOne +--- PASS: TestOne (0.06 seconds) +=== RUN TestTwo +--- PASS: TestTwo (0.10 seconds) +PASS +ok package/name 0.160s` + +func TestOutputPass(t *testing.T) { + _, err := parse(strings.NewReader(testOutputPass)) + if err != nil { + t.Fatalf("error parsing: %s", err) + } +} + +const testOutputFail = `=== RUN TestOne +--- FAIL: TestOne (0.02 seconds) + file_test.go:11: Error message + file_test.go:11: Longer + error + message. +=== RUN TestTwo +--- PASS: TestTwo (0.13 seconds) +FAIL +exit status 1 +FAIL package/name 0.151s` + +func TestOutputFail(t *testing.T) { + _, err := parse(strings.NewReader(testOutputPass)) + if err != nil { + t.Fatalf("error parsing: %s", err) + } +}