From 9e46438a63c7991eb394fb752fa0ccf2eb63e248 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 11 Jan 2017 22:06:35 +0100 Subject: [PATCH] fixup! test-strcmp-offset: created test for strcmp_offset The return value of strcmp() is actually not defined apart from the sign... So while MSVC's strcmp() returns -1, 0 or +1 (which is perfectly legal), GNU libc's strcmp() returns the difference of the differing byte, if any. Let's adjust our test to account for that. While at it, also fix white-space issues and mark the test script as executable. With this patch, the tests pass on Linux, too. Signed-off-by: Johannes Schindelin --- t/helper/test-strcmp-offset.c | 19 ++++++++++++------- t/t0065-strcmp-offset.sh | 0 2 files changed, 12 insertions(+), 7 deletions(-) mode change 100644 => 100755 t/t0065-strcmp-offset.sh diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c index c50d99947b..56fd8c1e41 100644 --- a/t/helper/test-strcmp-offset.c +++ b/t/helper/test-strcmp-offset.c @@ -23,23 +23,28 @@ int try_pair(const char *sa, const char *sb, int first_change) { int failed = 0; int offset, r_exp, r_tst; - + r_exp = strcmp(sa, sb); r_tst = strcmp_offset(sa, sb, &offset); if (r_tst != r_exp) { - error("FAIL: '%s' vs '%s', result expect %d, observed %d\n", - sa, sb, r_exp, r_tst); - failed = 1; + if ((r_tst < 0 && r_exp < 0) || (r_tst > 0 && r_exp > 0)) + warning("'%s' vs '%s', imprecise result: %d != %d", + sa, sb, r_exp, r_tst); + else { + error("'%s' vs '%s', result expect %d, observed %d", + sa, sb, r_exp, r_tst); + failed = 1; + } } if (offset != first_change) { - error("FAIL: '%s' vs '%s', offset expect %d, observed %d\n", - sa, sb, first_change, offset); + error("'%s' vs '%s', offset expect %d, observed %d", + sa, sb, first_change, offset); failed = 1; } return failed; } - + int cmd_main(int argc, const char **argv) { int failed = 0; diff --git a/t/t0065-strcmp-offset.sh b/t/t0065-strcmp-offset.sh old mode 100644 new mode 100755