From caed24ae3797438375bae75e24129e3a2dace311 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 12 Jun 2017 17:41:46 -0700 Subject: [PATCH] test-lib-functions.sh: add test_diff that uses git diff --no-index The standard "test_cmp" function cannot be relied upon to provide unified diff output everywhere since not all diffs support -u. Always use "git diff --no-index" (and a few supporting options) to get a consistent unified diff that's deterministic to boot. Signed-off-by: Kyle J. McKay --- t/README-TESTLIB | 12 ++++++++++++ t/test-lib-functions.sh | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/t/README-TESTLIB b/t/README-TESTLIB index 2e578f1..4bdbcd2 100644 --- a/t/README-TESTLIB +++ b/t/README-TESTLIB @@ -851,6 +851,7 @@ available utility functions that are TopGit-specific. $TESTLIB_TEST_CMP ... Useful because `diff -u` will be used where supported instead of `cmp`. + See also `test_diff` for an alternative. - test_cmp_bin ... @@ -939,6 +940,17 @@ available utility functions that are TopGit-specific. where the output goes). To get the Git "eval" equivalent, use `eval` as the first and the string to be "eval"'d as the second. +- test_diff ... + + Shortcut for: + + git --no-pager -c core.abbrev=16 diff --no-color --exit-code \ + --no-prefix --no-index ... + + Always gives nice diffs and they're always `-u` diffs. + This should be usable as a drop-in replacement for `test_cmp` everywhere + and its output should be deterministic as no dates or times are included. + - test_dir_is_empty Fail verbosely (with directory contents) unless is an existing diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 974dd76..a751db9 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -825,6 +825,11 @@ test_cmp_bin() { cmp "$@" } +# Use git diff --no-index for the diff (with a few supporting options) +test_diff() { + git --no-pager -c core.abbrev=16 diff --no-color --exit-code --no-prefix --no-index "$@" +} + # Call any command "$@" but be more verbose about its # failure. This is handy for commands like "test" which do # not output anything when they fail. -- 2.11.4.GIT