Skip to content

Commit 9e46438

Browse files
committed
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 <[email protected]>
1 parent 8a8f56b commit 9e46438

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

t/helper/test-strcmp-offset.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,28 @@ int try_pair(const char *sa, const char *sb, int first_change)
2323
{
2424
int failed = 0;
2525
int offset, r_exp, r_tst;
26-
26+
2727
r_exp = strcmp(sa, sb);
2828
r_tst = strcmp_offset(sa, sb, &offset);
2929
if (r_tst != r_exp) {
30-
error("FAIL: '%s' vs '%s', result expect %d, observed %d\n",
31-
sa, sb, r_exp, r_tst);
32-
failed = 1;
30+
if ((r_tst < 0 && r_exp < 0) || (r_tst > 0 && r_exp > 0))
31+
warning("'%s' vs '%s', imprecise result: %d != %d",
32+
sa, sb, r_exp, r_tst);
33+
else {
34+
error("'%s' vs '%s', result expect %d, observed %d",
35+
sa, sb, r_exp, r_tst);
36+
failed = 1;
37+
}
3338
}
3439
if (offset != first_change) {
35-
error("FAIL: '%s' vs '%s', offset expect %d, observed %d\n",
36-
sa, sb, first_change, offset);
40+
error("'%s' vs '%s', offset expect %d, observed %d",
41+
sa, sb, first_change, offset);
3742
failed = 1;
3843
}
3944

4045
return failed;
4146
}
42-
47+
4348
int cmd_main(int argc, const char **argv)
4449
{
4550
int failed = 0;

t/t0065-strcmp-offset.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)