Skip to content

Commit

Permalink
chore: improve output on vm tests
Browse files Browse the repository at this point in the history
Instead of printing the expected and actual output, create a diff to see
what specifically changed.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
  • Loading branch information
ajnavarro committed Apr 25, 2023
1 parent 096f117 commit 33075e3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions gnovm/tests/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strconv"
"strings"

"github.com/pmezard/go-difflib/difflib"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/stdlibs"
"github.com/gnolang/gno/tm2/pkg/crypto"
Expand Down Expand Up @@ -297,7 +299,16 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
if resWanted == "" {
panic(fmt.Sprintf("fail on %s: got unexpected output: %s", path, res))
} else {
panic(fmt.Sprintf("fail on %s: got:\n%s\n\nwant:\n%s\n", path, res, resWanted))
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(resWanted),
B: difflib.SplitLines(res),
FromFile: "Expected",
FromDate: "",
ToFile: "Actual",
ToDate: "",
Context: 1,
})
panic(fmt.Sprintf("fail on %s: diff:\n%s\n", path, diff))
}
}
}
Expand All @@ -318,7 +329,16 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
// write output to file.
replaceWantedInPlace(path, "Realm", rops2)
} else {
panic(fmt.Sprintf("fail on %s: got:\n%s\n\nwant:\n%s\n", path, rops2, rops))
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(rops),
B: difflib.SplitLines(rops2),
FromFile: "Expected",
FromDate: "",
ToFile: "Actual",
ToDate: "",
Context: 1,
})
panic(fmt.Sprintf("fail on %s: diff:\n%s\n", path, diff))
}
}
}
Expand Down

0 comments on commit 33075e3

Please sign in to comment.