mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2026-05-04 18:29:33 +02:00
Compare commits
No commits in common. "43f4f33838f21a0d5424f2b13b5a6cb71b24aa65" and "9f9fcb85349003edb554574d0e3f623811866f50" have entirely different histories.
43f4f33838
...
9f9fcb8534
2 changed files with 16 additions and 9 deletions
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
"github.com/jedib0t/go-pretty/v6/text"
|
"github.com/jedib0t/go-pretty/v6/text"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
"gitlab.com/TECHNOFAB/nixtest/internal/types"
|
"gitlab.com/TECHNOFAB/nixtest/internal/types"
|
||||||
"gitlab.com/TECHNOFAB/nixtest/internal/util"
|
"gitlab.com/TECHNOFAB/nixtest/internal/util"
|
||||||
)
|
)
|
||||||
|
|
@ -24,11 +25,17 @@ func PrintErrors(results types.Results, noColor bool) {
|
||||||
fmt.Println(text.FgRed.Sprintf("⚠ Test \"%s/%s\" failed:", result.Spec.Suite, result.Spec.Name))
|
fmt.Println(text.FgRed.Sprintf("⚠ Test \"%s/%s\" failed:", result.Spec.Suite, result.Spec.Name))
|
||||||
message := result.ErrorMessage
|
message := result.ErrorMessage
|
||||||
if result.Status == types.StatusFailure && message == "" {
|
if result.Status == types.StatusFailure && message == "" {
|
||||||
|
if noColor {
|
||||||
var err error
|
var err error
|
||||||
message, err = util.ComputeDiff(result.Expected, result.Actual)
|
message, err = util.ComputeDiff(result.Expected, result.Actual)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic().Err(err).Msg("failed to compute diff")
|
log.Panic().Err(err).Msg("failed to compute diff")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
dmp := diffmatchpatch.New()
|
||||||
|
diffs := dmp.DiffMain(result.Expected, result.Actual, true)
|
||||||
|
message = fmt.Sprintf("Diff:\n%s", dmp.DiffPrettyText(diffs))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if message == "" {
|
if message == "" {
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,16 @@ function assert_not_eq() {
|
||||||
assert "$1 -ne $2" "$3"
|
assert "$1 -ne $2" "$3"
|
||||||
}
|
}
|
||||||
function assert_contains() {
|
function assert_contains() {
|
||||||
echo -n "$1" | grep -q -- "$2" || {
|
echo "$1" | grep -q -- "$2" || {
|
||||||
echo "Assertion failed: $3. The following does not contain $2: $1" >&2;
|
echo "Assertion failed: $3. $1 does not contain $2" >&2;
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function assert_not_contains() {
|
function assert_not_contains() {
|
||||||
echo -n "$1" | grep -q -- "$2" && {
|
echo "$1" | grep -q -- "$2" && {
|
||||||
echo "Assertion failed: $3. The following does contain $2: $1" >&2;
|
echo "Assertion failed: $3. $1 does contain $2" >&2;
|
||||||
exit 1;
|
exit 1;
|
||||||
} || true
|
}
|
||||||
}
|
}
|
||||||
function assert_file_contains() {
|
function assert_file_contains() {
|
||||||
grep -q -- "$2" $1 || {
|
grep -q -- "$2" $1 || {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue