| package fxtesting |
| |
| import ( |
| "testing" |
| ) |
| |
| // T wraps a testing.T to add Fuchsia-specific test functionality. |
| // Example Usage: |
| // t.Run("a_test", func(t *testing.T) { |
| // fxt := T{t} |
| // fxt.AssertNil(MaybeError()) |
| // }) |
| type T struct { |
| *testing.T |
| } |
| |
| // IsPresubmitMode returns true iff running in short mode. To enable short mode, run |
| // `go test -short`. Long running tests and integration tests should Skip() themselves if |
| // this flag is set. See https://golang.org/pkg/testing/ for an explanation of the |
| // testing package's short flag. |
| func IsPresubmitMode() bool { |
| return testing.Short() |
| } |
| |
| // AssertNil raises a fatal error if the error is not nil. |
| func (t *T) AssertNil(err error) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| } |
| |
| // Assert raises a fatal error with the given message if a condition is not met. A single |
| // string message is required at minimum to aid in debugging test failures. |
| func (t *T) Assert(condition bool, format string, args ...interface{}) { |
| if !condition { |
| t.Fatalf(format, args...) |
| } |
| } |