Skip to content

Commit

Permalink
fix: assertion output (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and sguiheux committed Nov 10, 2017
1 parent 4502517 commit a1f5982
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions assertion.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package venom

import (
"bytes"
"fmt"
"reflect"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' '
Expand Down

0 comments on commit a1f5982

Please sign in to comment.