Skip to content

Commit 80595ab

Browse files
committed
Merge branch 'ps/unit-test-c-escape-names.txt'
The unit test helper function was taught to use backslash + mnemonic notation for certain control characters like "\t", instead of octal notation like "\011". * ps/unit-test-c-escape-names.txt: test-lib: print escape sequence names
2 parents 5a0ee6f + e30e944 commit 80595ab

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

t/helper/test-example-tap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static void t_messages(void)
6363
check_str("NULL", NULL);
6464
check_char('a', ==, '\n');
6565
check_char('\\', ==, '\'');
66+
check_char('\a', ==, '\v');
67+
check_char('\x00', ==, '\x01');
6668
}
6769

6870
static void t_empty(void)
@@ -123,6 +125,8 @@ int cmd__example_tap(int argc UNUSED, const char **argv UNUSED)
123125
check_str("NULL", NULL);
124126
check_char('a', ==, '\n');
125127
check_char('\\', ==, '\'');
128+
check_char('\a', ==, '\v');
129+
check_char('\x00', ==, '\x01');
126130
}
127131
if_test ("if_test test with no checks")
128132
; /* nothing */

t/t0080-unit-test-output.sh

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ test_description='Test the output of the unit test framework'
66

77
test_expect_success 'TAP output from unit tests' - <<\EOT
88
cat >expect <<-EOF &&
9-
# BUG: check outside of test at t/helper/test-example-tap.c:75
9+
# BUG: check outside of test at t/helper/test-example-tap.c:77
1010
ok 1 - passing test
1111
ok 2 - passing test and assertion return 1
12-
# check "1 == 2" failed at t/helper/test-example-tap.c:79
12+
# check "1 == 2" failed at t/helper/test-example-tap.c:81
1313
# left: 1
1414
# right: 2
1515
not ok 3 - failing test
@@ -34,53 +34,65 @@ test_expect_success 'TAP output from unit tests' - <<\EOT
3434
not ok 15 - failing check after TEST_TODO()
3535
ok 16 - failing check after TEST_TODO() returns 0
3636
# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
37-
# left: "\011hello\\\\"
38-
# right: "there\"\012"
37+
# left: "\thello\\\\"
38+
# right: "there\"\n"
3939
# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
4040
# left: "NULL"
4141
# right: NULL
4242
# check "'a' == '\n'" failed at t/helper/test-example-tap.c:64
4343
# left: 'a'
44-
# right: '\012'
44+
# right: '\n'
4545
# check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:65
4646
# left: '\\\\'
4747
# right: '\\''
48+
# check "'\a' == '\v'" failed at t/helper/test-example-tap.c:66
49+
# left: '\a'
50+
# right: '\v'
51+
# check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:67
52+
# left: '\000'
53+
# right: '\001'
4854
not ok 17 - messages from failing string and char comparison
49-
# BUG: test has no checks at t/helper/test-example-tap.c:94
55+
# BUG: test has no checks at t/helper/test-example-tap.c:96
5056
not ok 18 - test with no checks
5157
ok 19 - test with no checks returns 0
5258
ok 20 - if_test passing test
53-
# check "1 == 2" failed at t/helper/test-example-tap.c:100
59+
# check "1 == 2" failed at t/helper/test-example-tap.c:102
5460
# left: 1
5561
# right: 2
5662
not ok 21 - if_test failing test
5763
not ok 22 - if_test passing TEST_TODO() # TODO
58-
# todo check 'check(1)' succeeded at t/helper/test-example-tap.c:104
64+
# todo check 'check(1)' succeeded at t/helper/test-example-tap.c:106
5965
not ok 23 - if_test failing TEST_TODO()
60-
# check "0" failed at t/helper/test-example-tap.c:106
66+
# check "0" failed at t/helper/test-example-tap.c:108
6167
# skipping test - missing prerequisite
62-
# skipping check '1' at t/helper/test-example-tap.c:108
68+
# skipping check '1' at t/helper/test-example-tap.c:110
6369
ok 24 - if_test test_skip() # SKIP
6470
# skipping test - missing prerequisite
6571
ok 25 - if_test test_skip() inside TEST_TODO() # SKIP
66-
# check "0" failed at t/helper/test-example-tap.c:113
72+
# check "0" failed at t/helper/test-example-tap.c:115
6773
not ok 26 - if_test TEST_TODO() after failing check
68-
# check "0" failed at t/helper/test-example-tap.c:119
74+
# check "0" failed at t/helper/test-example-tap.c:121
6975
not ok 27 - if_test failing check after TEST_TODO()
70-
# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:122
71-
# left: "\011hello\\\\"
72-
# right: "there\"\012"
73-
# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:123
76+
# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:124
77+
# left: "\thello\\\\"
78+
# right: "there\"\n"
79+
# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:125
7480
# left: "NULL"
7581
# right: NULL
76-
# check "'a' == '\n'" failed at t/helper/test-example-tap.c:124
82+
# check "'a' == '\n'" failed at t/helper/test-example-tap.c:126
7783
# left: 'a'
78-
# right: '\012'
79-
# check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:125
84+
# right: '\n'
85+
# check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:127
8086
# left: '\\\\'
8187
# right: '\\''
88+
# check "'\a' == '\v'" failed at t/helper/test-example-tap.c:128
89+
# left: '\a'
90+
# right: '\v'
91+
# check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:129
92+
# left: '\000'
93+
# right: '\001'
8294
not ok 28 - if_test messages from failing string and char comparison
83-
# BUG: test has no checks at t/helper/test-example-tap.c:127
95+
# BUG: test has no checks at t/helper/test-example-tap.c:131
8496
not ok 29 - if_test test with no checks
8597
1..29
8698
EOF

t/unit-tests/test-lib.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,23 @@ int check_uint_loc(const char *loc, const char *check, int ok,
396396
static void print_one_char(char ch, char quote)
397397
{
398398
if ((unsigned char)ch < 0x20u || ch == 0x7f) {
399-
/* TODO: improve handling of \a, \b, \f ... */
400-
printf("\\%03o", (unsigned char)ch);
399+
char esc;
400+
switch (ch) {
401+
case '\a': esc = 'a'; break;
402+
case '\b': esc = 'b'; break;
403+
case '\t': esc = 't'; break;
404+
case '\n': esc = 'n'; break;
405+
case '\v': esc = 'v'; break;
406+
case '\f': esc = 'f'; break;
407+
case '\r': esc = 'r'; break;
408+
default: esc = 0; break;
409+
}
410+
if (esc) {
411+
putc('\\', stdout);
412+
putc(esc, stdout);
413+
} else {
414+
printf("\\%03o", (unsigned char)ch);
415+
}
401416
} else {
402417
if (ch == '\\' || ch == quote)
403418
putc('\\', stdout);

0 commit comments

Comments
 (0)