diff options
| author | Shulhan <ms@kilabit.info> | 2021-03-14 22:37:59 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-03-14 22:40:05 +0700 |
| commit | e7552ad0189f761875bc1c2ca3dd716d43a01e0d (patch) | |
| tree | fd68ec29d23fb9a807a7382088020e3b17d446fd /lib/test/test.go | |
| parent | 882727d89c8e7f9b9761009ccdca1af8c18d0a30 (diff) | |
| download | pakakeh.go-e7552ad0189f761875bc1c2ca3dd716d43a01e0d.tar.xz | |
all: refactoring the test.Assert and test.AssertBench signature
Previously, the test.Assert and test.AssertBench functions has the
boolean parameter to print the stack trace of test in case its not equal.
Since this parameter is not mandatory and its usually always set to
"true", we remove them from function signature to simplify the call
to Assert and AssertBench.
Diffstat (limited to 'lib/test/test.go')
| -rw-r--r-- | lib/test/test.go | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/lib/test/test.go b/lib/test/test.go index a8343bd2..b28b676b 100644 --- a/lib/test/test.go +++ b/lib/test/test.go @@ -37,56 +37,35 @@ func printStackTrace(t testing.TB, trace []byte) { } // -// Assert will compare two interfaces: `exp` and `got` for equality. -// If both are not equal, the test will throw panic parameter describe the -// position (type and value) where both are not matched. +// Assert compare two interfaces: `exp` and `got` for equality. +// If both parameters are not equal, the function will call Fatalf that +// describe the position (type and value) where value are not matched. // // If `exp` implement the extended `reflect.Equaler`, then it will use the // method `IsEqual()` with `got` as parameter. // -// If debug parameter is true it will print the stack trace of testing.T -// instance. +// WARNING: this method does not support recursive pointer, for example a node +// that point to parent and parent that point back to node again. // -// WARNING: this method does not support recursive pointer, for example node -// that point to parent and parent that point back to node. -// -func Assert(t *testing.T, name string, exp, got interface{}, debug bool) { +func Assert(t *testing.T, name string, exp, got interface{}) { err := reflect.DoEqual(exp, got) if err == nil { return } - if debug { - trace := make([]byte, 1024) - runtime.Stack(trace, false) - printStackTrace(t, trace) - } + trace := make([]byte, 1024) + runtime.Stack(trace, false) + printStackTrace(t, trace) t.Fatalf("!!! %s: %s", name, err) } // -// AssertBench will compare two interfaces: `exp` and `got` whether its same -// with `equal` value. +// AssertBench will compare two interfaces: `exp` and `got` for equality. +// If both parameters are not equal, the function will call Fatalf that +// describe the position (type and value) where value are not matched. // -// If comparison result is not same with `equal`, it will print the result and -// expectation and then terminate the test routine. -// -func AssertBench(b *testing.B, name string, exp, got interface{}, equal bool) { - if reflect.IsEqual(exp, got) == equal { - return - } - - trace := make([]byte, 1024) - runtime.Stack(trace, false) - - printStackTrace(b, trace) - - b.Fatalf(">>> Got %s:\n\t'%+v';\n"+ - " want:\n\t'%+v'\n", name, got, exp) -} - -func AssertBench2(b *testing.B, name string, exp, got interface{}) { +func AssertBench(b *testing.B, name string, exp, got interface{}) { err := reflect.DoEqual(exp, got) if err == nil { return |
