Skip to content

Commit 56e12cd

Browse files
authored
Merge pull request #126 from pks-gitlab/pks-assert-use-%p
clar: use "%p" to print mismatching pointers
2 parents af2beb9 + f917d1f commit 56e12cd

File tree

22 files changed

+289
-217
lines changed

22 files changed

+289
-217
lines changed

clar.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,7 @@ void clar__assert_equal(
871871
void *p1 = va_arg(args, void *), *p2 = va_arg(args, void *);
872872
is_equal = (p1 == p2);
873873
if (!is_equal)
874-
p_snprintf(buf, sizeof(buf), "0x%"PRIxMAX" != 0x%"PRIxMAX,
875-
(uintmax_t)p1, (uintmax_t)p2);
874+
p_snprintf(buf, sizeof(buf), "%p != %p", p1, p2);
876875
}
877876
else {
878877
int i1 = va_arg(args, int), i2 = va_arg(args, int);

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)

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)

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)

test/expected/quiet

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

test/expected/specific_test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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

test/expected/stop_on_failure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ 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

test/expected/suite_names

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

test/expected/summary.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
<testcase name="bool" classname="selftest" time="0.00">
2828
<failure type="assert"><![CDATA[0 != value
2929
0 != 1]]></failure>
30-
</testcase>
31-
<testcase name="ptr" classname="selftest" time="0.00">
32-
<failure type="assert"><![CDATA[Pointer mismatch: p1 != p2
33-
0x1 != 0x2]]></failure>
3430
</testcase>
3531
<testcase name="multiline_description" classname="selftest" time="0.00">
3632
<failure type="assert"><![CDATA[Function call failed: −1

test/expected/summary_with_filename

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,48 @@
11
Loaded 1 suites:
22
Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
3-
FFFFFFFFFF
3+
FFFFFFFFF
44

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

99
2) Failure:
10-
selftest::suite::2 [file:42]
10+
combined::2 [file:42]
1111
Expression is not true: 100 == 101
1212

1313
3) Failure:
14-
selftest::suite::strings [file:42]
14+
combined::strings [file:42]
1515
String mismatch: "mismatched" != actual ("this one fails")
1616
'mismatched' != 'expected' (at byte 0)
1717

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

2323
5) Failure:
24-
selftest::suite::int [file:42]
24+
combined::int [file:42]
2525
101 != value ("extra note on failing test")
2626
101 != 100
2727

2828
6) Failure:
29-
selftest::suite::int_fmt [file:42]
29+
combined::int_fmt [file:42]
3030
022 != value
3131
0022 != 0144
3232

3333
7) Failure:
34-
selftest::suite::bool [file:42]
34+
combined::bool [file:42]
3535
0 != value
3636
0 != 1
3737

3838
8) Failure:
39-
selftest::suite::ptr [file:42]
40-
Pointer mismatch: p1 != p2
41-
0x1 != 0x2
42-
43-
9) Failure:
44-
selftest::suite::multiline_description [file:42]
39+
combined::multiline_description [file:42]
4540
Function call failed: -1
4641
description line 1
4742
description line 2
4843

49-
10) Failure:
50-
selftest::suite::null_string [file:42]
44+
9) Failure:
45+
combined::null_string [file:42]
5146
String mismatch: "expected" != actual ("this one fails")
5247
'expected' != NULL
5348

0 commit comments

Comments
 (0)