Skip to content

Commit 57f6a64

Browse files
Seyi007gitster
authored andcommitted
t/unit-tests: adapt example decorate test to clar framework
Adapts example decorate test script to clar framework by using clar assertions where necessary. Test functions are created as standalone to test different test cases. Mentored-by: Patrick Steinhardt <[email protected]> Signed-off-by: Seyi Kuforiji <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 094eff5 commit 57f6a64

File tree

4 files changed

+78
-76
lines changed

4 files changed

+78
-76
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
13401340
THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
13411341

13421342
CLAR_TEST_SUITES += u-ctype
1343+
CLAR_TEST_SUITES += u-example-decorate
13431344
CLAR_TEST_SUITES += u-hash
13441345
CLAR_TEST_SUITES += u-hashmap
13451346
CLAR_TEST_SUITES += u-mem-pool
@@ -1351,7 +1352,6 @@ CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
13511352
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
13521353
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13531354

1354-
UNIT_TEST_PROGRAMS += t-example-decorate
13551355
UNIT_TEST_PROGRAMS += t-oid-array
13561356
UNIT_TEST_PROGRAMS += t-oidmap
13571357
UNIT_TEST_PROGRAMS += t-oidtree

t/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
clar_test_suites = [
22
'unit-tests/u-ctype.c',
3+
'unit-tests/u-example-decorate.c',
34
'unit-tests/u-hash.c',
45
'unit-tests/u-hashmap.c',
56
'unit-tests/u-mem-pool.c',
@@ -45,7 +46,6 @@ clar_unit_tests = executable('unit-tests',
4546
test('unit-tests', clar_unit_tests)
4647

4748
unit_test_programs = [
48-
'unit-tests/t-example-decorate.c',
4949
'unit-tests/t-oid-array.c',
5050
'unit-tests/t-oidmap.c',
5151
'unit-tests/t-oidtree.c',

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

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

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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__add(void)
17+
{
18+
void *ret = add_decoration(&vars.n, vars.one, &vars.decoration_a);
19+
cl_assert(ret == NULL);
20+
ret = add_decoration(&vars.n, vars.two, NULL);
21+
cl_assert(ret == NULL);
22+
}
23+
24+
void test_example_decorate__readd(void)
25+
{
26+
void *ret;
27+
28+
cl_assert(add_decoration(&vars.n, vars.one, &vars.decoration_a) == NULL);
29+
cl_assert(add_decoration(&vars.n, vars.two, NULL) == NULL);
30+
31+
ret = add_decoration(&vars.n, vars.one, NULL);
32+
cl_assert(ret == &vars.decoration_a);
33+
ret = add_decoration(&vars.n, vars.two, &vars.decoration_b);
34+
cl_assert(ret == NULL);
35+
}
36+
37+
void test_example_decorate__lookup(void)
38+
{
39+
void *ret;
40+
41+
add_decoration(&vars.n, vars.two, &vars.decoration_b);
42+
add_decoration(&vars.n, vars.one, NULL);
43+
44+
ret = lookup_decoration(&vars.n, vars.two);
45+
cl_assert(ret == &vars.decoration_b);
46+
ret = lookup_decoration(&vars.n, vars.one);
47+
cl_assert(ret == NULL);
48+
}
49+
50+
void test_example_decorate__loop(void)
51+
{
52+
int objects_noticed = 0;
53+
54+
add_decoration(&vars.n, vars.one, &vars.decoration_a);
55+
add_decoration(&vars.n, vars.two, &vars.decoration_b);
56+
57+
for (size_t i = 0; i < vars.n.size; i++) {
58+
if (vars.n.entries[i].base)
59+
objects_noticed++;
60+
}
61+
cl_assert_equal_i(objects_noticed, 2);
62+
}
63+
64+
void test_example_decorate__initialize(void)
65+
{
66+
struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
67+
68+
vars.one = lookup_unknown_object(the_repository, &one_oid);
69+
vars.two = lookup_unknown_object(the_repository, &two_oid);
70+
vars.three = lookup_unknown_object(the_repository, &three_oid);
71+
}
72+
73+
void test_example_decorate__cleanup(void)
74+
{
75+
clear_decoration(&vars.n, NULL);
76+
}

0 commit comments

Comments
 (0)