Skip to content

Commit 93dbb6b

Browse files
pks-tgitster
authored andcommitted
t/unit-tests: update to 10e96bc
Update to 10e96bc (Merge pull request #127 from pks-gitlab/pks-ci-improvements, 2025-09-22). This commit includes a couple of changes: - The GitHub CI has been updated to include a 32 bit CI job. Furthermore, the jobs now compile with "-Werror" and more warnings enabled. - An issue was addressed where `uintptr_t` is not available on NonStop [1]. - The clar selftests have been restructured so that it is now possible to add small test suites more readily. This was done to add tests for the above addressed issue, where we now use "%p" to print pointers in a platform dependent way. - An issue was addressed where the test output had a trailing whitespace with certain output formats, which caused whitespace issues in the test expectation files. [1]: <[email protected]> Reported-by: Randall S. Becker <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7f04f6 commit 93dbb6b

File tree

24 files changed

+320
-236
lines changed

24 files changed

+320
-236
lines changed

t/unit-tests/clar/.github/workflows/ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,47 @@ jobs:
1313
platform:
1414
- os: ubuntu-latest
1515
generator: Unix Makefiles
16+
env:
17+
CFLAGS: "-Werror -Wall -Wextra"
1618
- os: ubuntu-latest
1719
generator: Unix Makefiles
1820
env:
1921
CC: "clang"
20-
CFLAGS: "-fsanitize=leak"
22+
CFLAGS: "-Werror -Wall -Wextra -fsanitize=leak"
23+
- os: ubuntu-latest
24+
generator: Unix Makefiles
25+
image: i386/debian:latest
26+
env:
27+
CFLAGS: "-Werror -Wall -Wextra"
2128
- os: macos-latest
2229
generator: Unix Makefiles
30+
env:
31+
CFLAGS: "-Werror -Wall -Wextra"
2332
- os: windows-latest
2433
generator: Visual Studio 17 2022
2534
- os: windows-latest
2635
generator: MSYS Makefiles
36+
env:
37+
CFLAGS: "-Werror -Wall -Wextra"
2738
- os: windows-latest
2839
generator: MinGW Makefiles
40+
env:
41+
CFLAGS: "-Werror -Wall -Wextra"
2942
fail-fast: false
3043

3144
runs-on: ${{ matrix.platform.os }}
45+
container: ${{matrix.platform.image}}
3246

3347
env:
3448
CC: ${{matrix.platform.env.CC}}
3549
CFLAGS: ${{matrix.platform.env.CFLAGS}}
3650

3751
steps:
52+
- name: Prepare 32 bit container image
53+
if: matrix.platform.image == 'i386/debian:latest'
54+
run: apt -q update && apt -q -y install cmake gcc libc6-amd64 lib64stdc++6 make python3
3855
- name: Check out
39-
uses: actions/checkout@v2
56+
uses: actions/checkout@v4
4057
- name: Build
4158
shell: bash
4259
run: |

t/unit-tests/clar/clar.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct clar_suite {
195195
};
196196

197197
/* From clar_print_*.c */
198-
static void clar_print_init(int test_count, int suite_count, const char *suite_names);
198+
static void clar_print_init(int test_count, int suite_count);
199199
static void clar_print_shutdown(int test_count, int suite_count, int error_count);
200200
static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error);
201201
static void clar_print_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status failed);
@@ -592,11 +592,7 @@ clar_test_init(int argc, char **argv)
592592
if (argc > 1)
593593
clar_parse_args(argc, argv);
594594

595-
clar_print_init(
596-
(int)_clar_callback_count,
597-
(int)_clar_suite_count,
598-
""
599-
);
595+
clar_print_init((int)_clar_callback_count, (int)_clar_suite_count);
600596

601597
if (!_clar.summary_filename &&
602598
(summary_env = getenv("CLAR_SUMMARY")) != NULL) {
@@ -875,8 +871,7 @@ void clar__assert_equal(
875871
void *p1 = va_arg(args, void *), *p2 = va_arg(args, void *);
876872
is_equal = (p1 == p2);
877873
if (!is_equal)
878-
p_snprintf(buf, sizeof(buf), "0x%"PRIxPTR" != 0x%"PRIxPTR,
879-
(uintptr_t)p1, (uintptr_t)p2);
874+
p_snprintf(buf, sizeof(buf), "%p != %p", p1, p2);
880875
}
881876
else {
882877
int i1 = va_arg(args, int), i2 = va_arg(args, int);

t/unit-tests/clar/clar/print.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* clap: clar protocol, the traditional clar output format */
22

3-
static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
3+
static void clar_print_clap_init(int test_count, int suite_count)
44
{
55
(void)test_count;
66

77
if (_clar.verbosity < 0)
88
return;
99

10-
printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
10+
printf("Loaded %d suites:\n", (int)suite_count);
1111
printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
1212
}
1313

@@ -103,11 +103,10 @@ static void clar_print_clap_onabort(const char *fmt, va_list arg)
103103

104104
/* tap: test anywhere protocol format */
105105

106-
static void clar_print_tap_init(int test_count, int suite_count, const char *suite_names)
106+
static void clar_print_tap_init(int test_count, int suite_count)
107107
{
108108
(void)test_count;
109109
(void)suite_count;
110-
(void)suite_names;
111110
printf("TAP version 13\n");
112111
}
113112

@@ -207,9 +206,9 @@ static void clar_print_tap_onabort(const char *fmt, va_list arg)
207206
} \
208207
} while (0)
209208

210-
static void clar_print_init(int test_count, int suite_count, const char *suite_names)
209+
static void clar_print_init(int test_count, int suite_count)
211210
{
212-
PRINT(init, test_count, suite_count, suite_names);
211+
PRINT(init, test_count, suite_count);
213212
}
214213

215214
static void clar_print_shutdown(int test_count, int suite_count, int error_count)

t/unit-tests/clar/generate.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,24 @@ def should_generate(self, path):
158158

159159
def find_modules(self):
160160
modules = []
161-
for root, _, files in os.walk(self.path):
162-
module_root = root[len(self.path):]
163-
module_root = [c for c in module_root.split(os.sep) if c]
164161

165-
tests_in_module = fnmatch.filter(files, "*.c")
162+
if os.path.isfile(self.path):
163+
full_path = os.path.abspath(self.path)
164+
module_name = os.path.basename(self.path)
165+
module_name = os.path.splitext(module_name)[0]
166+
modules.append((full_path, module_name))
167+
else:
168+
for root, _, files in os.walk(self.path):
169+
module_root = root[len(self.path):]
170+
module_root = [c for c in module_root.split(os.sep) if c]
166171

167-
for test_file in tests_in_module:
168-
full_path = os.path.join(root, test_file)
169-
module_name = "_".join(module_root + [test_file[:-2]]).replace("-", "_")
172+
tests_in_module = fnmatch.filter(files, "*.c")
170173

171-
modules.append((full_path, module_name))
174+
for test_file in tests_in_module:
175+
full_path = os.path.join(root, test_file)
176+
module_name = "_".join(module_root + [test_file[:-2]]).replace("-", "_")
177+
178+
modules.append((full_path, module_name))
172179

173180
return modules
174181

@@ -217,6 +224,7 @@ def callback_count(self):
217224

218225
def write(self):
219226
output = os.path.join(self.output, 'clar.suite')
227+
os.makedirs(self.output, exist_ok=True)
220228

221229
if not self.should_generate(output):
222230
return False
@@ -258,7 +266,11 @@ def write(self):
258266
sys.exit(1)
259267

260268
path = args.pop() if args else '.'
269+
if os.path.isfile(path) and not options.output:
270+
print("Must provide --output when specifying a file")
271+
sys.exit(1)
261272
output = options.output or path
273+
262274
suite = TestSuite(path, output)
263275
suite.load(options.force)
264276
suite.disable(options.excluded)

t/unit-tests/clar/test/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
add_subdirectory(selftest_suite)
2-
31
find_package(Python COMPONENTS Interpreter REQUIRED)
42

53
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite"
@@ -40,15 +38,12 @@ target_include_directories(selftest PRIVATE
4038
)
4139
target_link_libraries(selftest clar)
4240

43-
add_test(NAME build_selftest_suite
44-
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target selftest_suite
45-
)
46-
set_tests_properties(build_selftest_suite PROPERTIES FIXTURES_SETUP clar_test_fixture)
47-
4841
add_test(NAME build_selftest
4942
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target selftest
5043
)
5144
set_tests_properties(build_selftest PROPERTIES FIXTURES_SETUP clar_test_fixture)
5245

53-
add_test(NAME selftest COMMAND "${CMAKE_CURRENT_BINARY_DIR}/selftest" "$<TARGET_FILE:selftest_suite>")
46+
add_subdirectory(suites)
47+
48+
add_test(NAME selftest COMMAND "${CMAKE_CURRENT_BINARY_DIR}/selftest" $<TARGET_FILE_DIR:combined_suite>)
5449
set_tests_properties(selftest PROPERTIES FIXTURES_REQUIRED clar_test_fixture)

t/unit-tests/clar/test/expected/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Usage: selftest [options]
1+
Usage: combined [options]
22

33
Options:
44
-sname Run only the suite with `name` (can go to individual test name)
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
1) Failure:
2-
selftest::suite::1 [file:42]
2+
combined::1 [file:42]
33
Function call failed: -1
44

55
2) Failure:
6-
selftest::suite::2 [file:42]
6+
combined::2 [file:42]
77
Expression is not true: 100 == 101
88

99
3) Failure:
10-
selftest::suite::strings [file:42]
10+
combined::strings [file:42]
1111
String mismatch: "mismatched" != actual ("this one fails")
1212
'mismatched' != 'expected' (at byte 0)
1313

1414
4) Failure:
15-
selftest::suite::strings_with_length [file:42]
15+
combined::strings_with_length [file:42]
1616
String mismatch: "exactly" != actual ("this one fails")
1717
'exa' != 'exp' (at byte 2)
1818

1919
5) Failure:
20-
selftest::suite::int [file:42]
20+
combined::int [file:42]
2121
101 != value ("extra note on failing test")
2222
101 != 100
2323

2424
6) Failure:
25-
selftest::suite::int_fmt [file:42]
25+
combined::int_fmt [file:42]
2626
022 != value
2727
0022 != 0144
2828

2929
7) Failure:
30-
selftest::suite::bool [file:42]
30+
combined::bool [file:42]
3131
0 != value
3232
0 != 1
3333

3434
8) Failure:
35-
selftest::suite::ptr [file:42]
36-
Pointer mismatch: p1 != p2
37-
0x1 != 0x2
38-
39-
9) Failure:
40-
selftest::suite::multiline_description [file:42]
35+
combined::multiline_description [file:42]
4136
Function call failed: -1
4237
description line 1
4338
description line 2
4439

45-
10) Failure:
46-
selftest::suite::null_string [file:42]
40+
9) Failure:
41+
combined::null_string [file:42]
4742
String mismatch: "expected" != actual ("this one fails")
4843
'expected' != NULL
4944

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Loaded 1 suites:
1+
Loaded 1 suites:
22
Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
33
F
44

55
1) Failure:
6-
selftest::suite::bool [file:42]
6+
combined::bool [file:42]
77
0 != value
88
0 != 1
99

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Loaded 1 suites:
1+
Loaded 1 suites:
22
Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
33
F
44

55
1) Failure:
6-
selftest::suite::1 [file:42]
6+
combined::1 [file:42]
77
Function call failed: -1
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Test suites (use -s<name> to run just one):
2-
0: selftest::suite
2+
0: combined

0 commit comments

Comments
 (0)