forked from getgauge-contrib/gauge-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
45 lines (37 loc) · 978 Bytes
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package testsuit
import (
"fmt"
"runtime/debug"
"strings"
)
// T is a wrapper around *testing.T
var T *testingT
type testingT struct {
errors []testError
}
type testError struct {
errMsg string
stacktrace string
}
func (t *testingT) getErrors() string {
var errs []string
for _, e := range t.errors {
errs = append(errs, e.errMsg)
}
return strings.Join(errs, "\n")
}
func (t *testingT) getStacktraces() string {
var stacktraces []string
for _, e := range t.errors {
stacktraces = append(stacktraces, e.stacktrace)
}
return strings.Join(stacktraces, "\n\n")
}
// Fail fails the step execution with the given error
func (t *testingT) Fail(err error) {
panic(err)
}
// Errorf records the error given, but step execution continues. However, the step is marked as failure.
func (t *testingT) Errorf(format string, args ...interface{}) {
t.errors = append(t.errors, testError{errMsg: fmt.Sprintf(format, args...), stacktrace: string(debug.Stack())})
}