Skip to content

Commit a13fb30

Browse files
committed
Merge branch 'sk/unit-tests-0130' into seen
Convert a handful of unit tests to work with the clar framework. * sk/unit-tests-0130: t/unit-tests: convert strcmp-offset test to use clar test framework t/unit-tests: convert strbuf test to use clar test framework t/unit-tests: adapt example decorate test to use clar test framework t/unit-tests: convert hashmap test to use clar test framework
2 parents a9c4744 + af8bf67 commit a13fb30

File tree

9 files changed

+348
-353
lines changed

9 files changed

+348
-353
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,18 +1353,20 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
13531353
THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
13541354

13551355
CLAR_TEST_SUITES += u-ctype
1356+
CLAR_TEST_SUITES += u-example-decorate
13561357
CLAR_TEST_SUITES += u-hash
1358+
CLAR_TEST_SUITES += u-hashmap
13571359
CLAR_TEST_SUITES += u-mem-pool
13581360
CLAR_TEST_SUITES += u-prio-queue
13591361
CLAR_TEST_SUITES += u-reftable-tree
1362+
CLAR_TEST_SUITES += u-strbuf
1363+
CLAR_TEST_SUITES += u-strcmp-offset
13601364
CLAR_TEST_SUITES += u-strvec
13611365
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
13621366
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
13631367
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
13641368
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13651369

1366-
UNIT_TEST_PROGRAMS += t-example-decorate
1367-
UNIT_TEST_PROGRAMS += t-hashmap
13681370
UNIT_TEST_PROGRAMS += t-oid-array
13691371
UNIT_TEST_PROGRAMS += t-oidmap
13701372
UNIT_TEST_PROGRAMS += t-oidtree
@@ -1376,8 +1378,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
13761378
UNIT_TEST_PROGRAMS += t-reftable-readwrite
13771379
UNIT_TEST_PROGRAMS += t-reftable-record
13781380
UNIT_TEST_PROGRAMS += t-reftable-stack
1379-
UNIT_TEST_PROGRAMS += t-strbuf
1380-
UNIT_TEST_PROGRAMS += t-strcmp-offset
13811381
UNIT_TEST_PROGRAMS += t-trailer
13821382
UNIT_TEST_PROGRAMS += t-urlmatch-normalization
13831383
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))

t/meson.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
clar_test_suites = [
22
'unit-tests/u-ctype.c',
3+
'unit-tests/u-example-decorate.c',
34
'unit-tests/u-hash.c',
5+
'unit-tests/u-hashmap.c',
46
'unit-tests/u-mem-pool.c',
57
'unit-tests/u-prio-queue.c',
68
'unit-tests/u-reftable-tree.c',
9+
'unit-tests/u-strbuf.c',
10+
'unit-tests/u-strcmp-offset.c',
711
'unit-tests/u-strvec.c',
812
]
913

@@ -44,8 +48,6 @@ clar_unit_tests = executable('unit-tests',
4448
test('unit-tests', clar_unit_tests)
4549

4650
unit_test_programs = [
47-
'unit-tests/t-example-decorate.c',
48-
'unit-tests/t-hashmap.c',
4951
'unit-tests/t-oid-array.c',
5052
'unit-tests/t-oidmap.c',
5153
'unit-tests/t-oidtree.c',
@@ -57,8 +59,6 @@ unit_test_programs = [
5759
'unit-tests/t-reftable-readwrite.c',
5860
'unit-tests/t-reftable-record.c',
5961
'unit-tests/t-reftable-stack.c',
60-
'unit-tests/t-strbuf.c',
61-
'unit-tests/t-strcmp-offset.c',
6262
'unit-tests/t-trailer.c',
6363
'unit-tests/t-urlmatch-normalization.c',
6464
]

t/unit-tests/t-example-decorate.c

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

t/unit-tests/t-strbuf.c

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

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

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

t/unit-tests/u-example-decorate.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
3+
#include "unit-test.h"
4+
#include "object.h"
5+
#include "decorate.h"
6+
#include "repository.h"
7+
8+
struct test_vars {
9+
struct object *one, *two, *three;
10+
struct decoration n;
11+
int decoration_a, decoration_b;
12+
};
13+
14+
static struct test_vars vars;
15+
16+
void test_example_decorate__initialize(void)
17+
{
18+
struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
19+
20+
vars.one = lookup_unknown_object(the_repository, &one_oid);
21+
vars.two = lookup_unknown_object(the_repository, &two_oid);
22+
vars.three = lookup_unknown_object(the_repository, &three_oid);
23+
}
24+
25+
void test_example_decorate__cleanup(void)
26+
{
27+
clear_decoration(&vars.n, NULL);
28+
}
29+
30+
void test_example_decorate__add(void)
31+
{
32+
cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
33+
cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
34+
}
35+
36+
void test_example_decorate__readd(void)
37+
{
38+
cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
39+
cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
40+
cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), &vars.decoration_a);
41+
cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
42+
}
43+
44+
void test_example_decorate__lookup(void)
45+
{
46+
cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
47+
cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), NULL);
48+
cl_assert_equal_p(lookup_decoration(&vars.n, vars.two), &vars.decoration_b);
49+
cl_assert_equal_p(lookup_decoration(&vars.n, vars.one), NULL);
50+
}
51+
52+
void test_example_decorate__loop(void)
53+
{
54+
int objects_noticed = 0;
55+
56+
cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
57+
cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
58+
59+
for (size_t i = 0; i < vars.n.size; i++)
60+
if (vars.n.entries[i].base)
61+
objects_noticed++;
62+
63+
cl_assert_equal_i(objects_noticed, 2);
64+
}

0 commit comments

Comments
 (0)