41 lines
973 B
Go
41 lines
973 B
Go
|
package testequal
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestHelper(t *testing.T) {
|
||
|
if os.Getenv("FAIL_ASSERTIONS") == "1" {
|
||
|
AssertEqual(t, 1, 2, "%d must be equal to %d", 1, 2)
|
||
|
AssertNotEqual(t, 1, 1, "1 != 1")
|
||
|
RequireEqual(t, 1, 2, errMsgLog{Exp: 1, Act: 2})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
cmd := exec.Command(os.Args[0], "-test.v", "-test.run=TestHelper")
|
||
|
cmd.Env = append(os.Environ(), "FAIL_ASSERTIONS=1")
|
||
|
var buf bytes.Buffer
|
||
|
cmd.Stdout = &buf
|
||
|
|
||
|
err := cmd.Run()
|
||
|
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
|
||
|
require.Contains(t, buf.String(), "helper_test.go:14")
|
||
|
require.Contains(t, buf.String(), "1 must be equal to 2")
|
||
|
require.Contains(t, buf.String(), "helper_test.go:15")
|
||
|
require.Contains(t, buf.String(), "1 != 1")
|
||
|
require.Contains(t, buf.String(), "helper_test.go:16")
|
||
|
return
|
||
|
}
|
||
|
t.Fatalf("process ran with err %v, want exit status 1", err)
|
||
|
}
|
||
|
|
||
|
type errMsgLog struct {
|
||
|
Exp int
|
||
|
Act int
|
||
|
}
|