summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-06-22 11:02:37 +1000
committerMaxime Coste <mawww@kakoune.org>2025-06-23 10:25:29 +1000
commitd51d50efb767f4af4c960398e987e39026788fdc (patch)
tree1f80227ebb026be8198e1aead7faa43090a06971
parente3b002d014ce89474154317f4e8739e7561d5774 (diff)
Use word-diff when possible when comparing json ui output in tests
If git is present we can rely on git-diff word support to get a much easier to understand diff.
-rwxr-xr-xtest/run14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/run b/test/run
index a26642da..8ce73f2a 100755
--- a/test/run
+++ b/test/run
@@ -136,10 +136,16 @@ fail_ifn() {
fi
}
-assert_eq() {
+check_json_eq() {
if [ ! "$1" = "$2" ]; then
fail_ifn
- printf "${indent} ${red}- %s\n${indent} ${green}+ %s${none}\n" "$1" "$2"
+ if command -v git > /dev/null; then
+ echo "$1" > expected
+ echo "$2" > actual
+ git --no-pager diff --color-words --no-index expected actual
+ else
+ printf "${indent} ${red}- %s\n${indent} ${green}+ %s${none}\n" "$1" "$2"
+ fi
fi
}
@@ -204,7 +210,7 @@ ui_out() {
while read -r event <&4; do
if printf %s "$event" | "${arg#-until-}" "$pattern" >/dev/null; then
if [ $# -ne 0 ]; then
- assert_eq "$1" "$event"
+ check_json_eq "$1" "$event"
shift
fi
break
@@ -213,7 +219,7 @@ ui_out() {
;;
*)
read -r event <&4
- assert_eq "$arg" "$event"
+ check_json_eq "$arg" "$event"
;;
esac
}