Skip to content

Commit

Permalink
Fix asserts deep call stack
Browse files Browse the repository at this point in the history
  • Loading branch information
fulldump committed May 19, 2018
1 parent 6da1eab commit 969d9b2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"reflect"
Expand Down Expand Up @@ -111,14 +112,28 @@ func (a *A) AssertNotNil(obtained interface{}) bool {
// and exit.
func (a *A) AssertTrue(obtained interface{}) bool {

return a.AssertEqual(obtained, true)
if reflect.DeepEqual(true, obtained) {
printShould(true)
return true
}

printExpectedObtained(true, obtained)

return false
}

// AssertFalse return true if `obtained` is false, otherwise it will print trace
// and exit.
func (a *A) AssertFalse(obtained interface{}) bool {

return a.AssertEqual(obtained, false)
if reflect.DeepEqual(false, obtained) {
printShould(false)
return true
}

printExpectedObtained(true, obtained)

return false
}

// AssertInArray return true if `item` match at least with one element of the
Expand Down Expand Up @@ -219,7 +234,7 @@ func printShould(value interface{}) {
}

aFuncExpr, ok := aFunc.Args[0].(*ast.IndexExpr)
if ok {
if ok && aFuncExpr.Pos() > 0 && (aFuncExpr.End()-1) < token.Pos(len(l)) {
variable = l[aFuncExpr.Pos()-1 : aFuncExpr.End()-1]
return
}
Expand Down

0 comments on commit 969d9b2

Please sign in to comment.