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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2017-01-11 22:06:35 +01:00
parent 8a8f56b776
commit 9e46438a63
2 changed files with 12 additions and 7 deletions

View File

@@ -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;

0
t/t0065-strcmp-offset.sh Normal file → Executable file
View File