// assert fails the test if the condition is false.
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
tb.FailNow()
}
}// assert fails the test if the condition is false.func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
tb.Helper()
if !condition { tb.Fatalf("\033[31m "+msg+"\033[39m\n\n", v...) }}--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package bug
// Pow returns x raised to the power of y i.e. x^y.func Pow(x, y int) int { return x ^ y}package bug_test
import ( "fmt" "testing"
)
func TestPow(t *testing.T) { tests := []struct { x, y, z int }{ {0, 0, 0}, {1, 0, 1}, {0, 1, 11}, }
for _, tt := range tests { t.Run("", func(t *testing.T) { z := bug.Pow(tt.x, tt.y) assert(t, tt.z == z, fmt.Sprintf("exp: %d, got: %d", tt.z, z)) }) }}
// assert fails the test if the condition is false.func assert(tb testing.TB, condition bool, msg string, v ...interface{}) { tb.Helper() if !condition { tb.Fatalf("\033[31m "+msg+"\033[39m\n\n", v...) }}--- FAIL: TestPow (0.00s)
--- FAIL: TestPow/#02 (0.00s)
bug_test.go:22: exp: 11, got: 1
FAIL
coverage: 100.0% of statements
exit status 1
FAIL github.com/lukasmalkmus/bug 0.008s
--- FAIL: TestPow (0.00s)
--- FAIL: TestPow/#02 (0.00s)
<autogenerated>:1: exp: 11, got: 1
FAIL
coverage: 100.0% of statements
FAIL github.com/lukasmalkmus/bug 0.015s