Skip to content

Commit 99d3cbe

Browse files
committed
Merge branch 'gt/unit-test-strcmp-offset'
The strcmp-offset tests have been rewritten using the unit test framework. * gt/unit-test-strcmp-offset: t/: port helper/test-strcmp-offset.c to unit-tests/t-strcmp-offset.c
2 parents b3ba0f2 + 4d00d94 commit 99d3cbe

File tree

6 files changed

+36
-48
lines changed

6 files changed

+36
-48
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ TEST_BUILTINS_OBJS += test-sha1.o
839839
TEST_BUILTINS_OBJS += test-sha256.o
840840
TEST_BUILTINS_OBJS += test-sigchain.o
841841
TEST_BUILTINS_OBJS += test-simple-ipc.o
842-
TEST_BUILTINS_OBJS += test-strcmp-offset.o
843842
TEST_BUILTINS_OBJS += test-string-list.o
844843
TEST_BUILTINS_OBJS += test-submodule-config.o
845844
TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
@@ -1338,6 +1337,7 @@ UNIT_TEST_PROGRAMS += t-ctype
13381337
UNIT_TEST_PROGRAMS += t-mem-pool
13391338
UNIT_TEST_PROGRAMS += t-prio-queue
13401339
UNIT_TEST_PROGRAMS += t-strbuf
1340+
UNIT_TEST_PROGRAMS += t-strcmp-offset
13411341
UNIT_TEST_PROGRAMS += t-trailer
13421342
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
13431343
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))

t/helper/test-strcmp-offset.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

t/helper/test-tool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ static struct test_cmd cmds[] = {
7878
{ "sha256", cmd__sha256 },
7979
{ "sigchain", cmd__sigchain },
8080
{ "simple-ipc", cmd__simple_ipc },
81-
{ "strcmp-offset", cmd__strcmp_offset },
8281
{ "string-list", cmd__string_list },
8382
{ "submodule", cmd__submodule },
8483
{ "submodule-config", cmd__submodule_config },

t/helper/test-tool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ int cmd__oid_array(int argc, const char **argv);
7171
int cmd__sha256(int argc, const char **argv);
7272
int cmd__sigchain(int argc, const char **argv);
7373
int cmd__simple_ipc(int argc, const char **argv);
74-
int cmd__strcmp_offset(int argc, const char **argv);
7574
int cmd__string_list(int argc, const char **argv);
7675
int cmd__submodule(int argc, const char **argv);
7776
int cmd__submodule_config(int argc, const char **argv);

t/t0065-strcmp-offset.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

t/unit-tests/t-strcmp-offset.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "test-lib.h"
2+
#include "read-cache-ll.h"
3+
4+
static void check_strcmp_offset(const char *string1, const char *string2,
5+
int expect_result, uintmax_t expect_offset)
6+
{
7+
size_t offset;
8+
int result = strcmp_offset(string1, string2, &offset);
9+
10+
/*
11+
* Because different CRTs behave differently, only rely on signs of the
12+
* result values.
13+
*/
14+
result = (result < 0 ? -1 :
15+
result > 0 ? 1 :
16+
0);
17+
18+
check_int(result, ==, expect_result);
19+
check_uint((uintmax_t)offset, ==, expect_offset);
20+
}
21+
22+
#define TEST_STRCMP_OFFSET(string1, string2, expect_result, expect_offset) \
23+
TEST(check_strcmp_offset(string1, string2, expect_result, \
24+
expect_offset), \
25+
"strcmp_offset(%s, %s) works", #string1, #string2)
26+
27+
int cmd_main(int argc, const char **argv)
28+
{
29+
TEST_STRCMP_OFFSET("abc", "abc", 0, 3);
30+
TEST_STRCMP_OFFSET("abc", "def", -1, 0);
31+
TEST_STRCMP_OFFSET("abc", "abz", -1, 2);
32+
TEST_STRCMP_OFFSET("abc", "abcdef", -1, 3);
33+
34+
return test_done();
35+
}

0 commit comments

Comments
 (0)