diff --git a/assertion.go b/assertion.go index 97e2a186..f1f3a9b4 100644 --- a/assertion.go +++ b/assertion.go @@ -1,7 +1,9 @@ package venom import ( + "bytes" "fmt" + "reflect" "strconv" "strings" "time" @@ -110,8 +112,30 @@ func check(assertion string, executorResult ExecutorResult, l Logger) (*Failure, if out != "" { prefix := "assertion: " + assertion - sdump, _ := dump.Sdump(executorResult) - return nil, &Failure{Value: RemoveNotPrintableChar(prefix + "\n" + out + "\n" + sdump)} + + sdump := &bytes.Buffer{} + dumpEncoder := dump.NewDefaultEncoder(sdump) + dumpEncoder.ExtraFields.DetailedMap = false + dumpEncoder.ExtraFields.DetailedStruct = false + dumpEncoder.ExtraFields.Len = false + dumpEncoder.ExtraFields.Type = false + dumpEncoder.Formatters = []dump.KeyFormatterFunc{dump.WithDefaultLowerCaseFormatter()} + + //Try to pretty print only the result + var smartPrinted bool + for k, v := range executorResult { + if k == "result" && reflect.TypeOf(v).Kind() != reflect.String { + dumpEncoder.Fdump(v) + smartPrinted = true + break + } + } + //If not succeed print all the stuff + if !smartPrinted { + dumpEncoder.Fdump(executorResult) + } + + return nil, &Failure{Value: RemoveNotPrintableChar(prefix + "\n" + out + "\n" + sdump.String())} } return nil, nil } diff --git a/extract.go b/extract.go index 8bb2b863..a601ced7 100644 --- a/extract.go +++ b/extract.go @@ -80,7 +80,7 @@ func checkExtracts(pattern, instring string, executorResult *ExecutorResult, l L func RemoveNotPrintableChar(in string) string { m := func(r rune) rune { - if unicode.IsPrint(r) { + if unicode.IsPrint(r) || unicode.IsSpace(r) || unicode.IsPunct(r) { return r } return ' '