I need to run my GoConvey tests as part of my build how do i make sure go test
exits with error exit code (not 0)?
Ok found the bug:
I have TestMain in my code that runs before the tests:
func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard) // Disable logs.
m.Run()
}
m.Run
should be wrapped with os.Exit
so it can be used with error status codes:
func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard) // Disable logs.
os.Exit(m.Run())
}
that fixed the problem
You can run goconvey as a normal test, you can test this very simply by writing a small test which gives a predictable result, like this
package c
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestConvey(t *testing.T){
Convey("TestConvey", t, func() {
So(false, ShouldBeTrue)
})
}
This should be the result xxx 14:44:03 ~/GO/src/c/c > go test x Failures:
* /home/xxx/GO/src/c/c/a_test.go
Line 10:
Expected: true
Actual: false
1 total assertion
--- FAIL: TestConvey (0.00s)
FAIL
exit status 1
FAIL c/c 0.006s