* [GSoC PATCH] test-lib: print escape sequence names
@ 2026-03-10 18:35 Pablo Sabater
2026-03-10 18:48 ` Pablo
2026-03-11 3:14 ` [GSoC PATCH v2] " Pablo Sabater
0 siblings, 2 replies; 5+ messages in thread
From: Pablo Sabater @ 2026-03-10 18:35 UTC (permalink / raw)
To: git; +Cc: Pablo Sabater
When printing expected/actual characters in failed checks, use
their names (\a, \b, \n, ...) instead of their octal representation,
making it easier to read
- Add tests to test-example-tap.c
- Update t0080-unit-test-output.sh
to match the desired output
Teach 'print_one_char()' the equivalent name
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
t/helper/test-example-tap.c | 4 +++
t/t0080-unit-test-output.sh | 58 ++++++++++++++++++++++---------------
t/unit-tests/test-lib.c | 19 ++++++++++--
3 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/t/helper/test-example-tap.c b/t/helper/test-example-tap.c
index 229d495ecf..998a1f0b42 100644
--- a/t/helper/test-example-tap.c
+++ b/t/helper/test-example-tap.c
@@ -63,6 +63,8 @@ static void t_messages(void)
check_str("NULL", NULL);
check_char('a', ==, '\n');
check_char('\\', ==, '\'');
+ check_char('\a', ==, '\v');
+ check_char('\x00', ==, '\x01');
}
static void t_empty(void)
@@ -123,6 +125,8 @@ int cmd__example_tap(int argc UNUSED, const char **argv UNUSED)
check_str("NULL", NULL);
check_char('a', ==, '\n');
check_char('\\', ==, '\'');
+ check_char('\a', ==, '\v');
+ check_char('\x00', ==, '\x01');
}
if_test ("if_test test with no checks")
; /* nothing */
diff --git a/t/t0080-unit-test-output.sh b/t/t0080-unit-test-output.sh
index 3db10f095c..11ab8b53bb 100755
--- a/t/t0080-unit-test-output.sh
+++ b/t/t0080-unit-test-output.sh
@@ -6,10 +6,10 @@ test_description='Test the output of the unit test framework'
test_expect_success 'TAP output from unit tests' - <<\EOT
cat >expect <<-EOF &&
- # BUG: check outside of test at t/helper/test-example-tap.c:75
+ # BUG: check outside of test at t/helper/test-example-tap.c:77
ok 1 - passing test
ok 2 - passing test and assertion return 1
- # check "1 == 2" failed at t/helper/test-example-tap.c:79
+ # check "1 == 2" failed at t/helper/test-example-tap.c:81
# left: 1
# right: 2
not ok 3 - failing test
@@ -34,53 +34,65 @@ test_expect_success 'TAP output from unit tests' - <<\EOT
not ok 15 - failing check after TEST_TODO()
ok 16 - failing check after TEST_TODO() returns 0
# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
- # left: "\011hello\\\\"
- # right: "there\"\012"
+ # left: "\thello\\\\"
+ # right: "there\"\n"
# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
# left: "NULL"
# right: NULL
# check "'a' == '\n'" failed at t/helper/test-example-tap.c:64
# left: 'a'
- # right: '\012'
- # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:65
+ # right: '\n'
+ # check "'\\\\' == '\''" failed at t/helper/test-example-tap.c:65
# left: '\\\\'
- # right: '\\''
+ # right: '\''
+ # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:66
+ # left: '\a'
+ # right: '\v'
+ # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:67
+ # left: '\000'
+ # right: '\001'
not ok 17 - messages from failing string and char comparison
- # BUG: test has no checks at t/helper/test-example-tap.c:94
+ # BUG: test has no checks at t/helper/test-example-tap.c:96
not ok 18 - test with no checks
ok 19 - test with no checks returns 0
ok 20 - if_test passing test
- # check "1 == 2" failed at t/helper/test-example-tap.c:100
+ # check "1 == 2" failed at t/helper/test-example-tap.c:102
# left: 1
# right: 2
not ok 21 - if_test failing test
not ok 22 - if_test passing TEST_TODO() # TODO
- # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:104
+ # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:106
not ok 23 - if_test failing TEST_TODO()
- # check "0" failed at t/helper/test-example-tap.c:106
+ # check "0" failed at t/helper/test-example-tap.c:108
# skipping test - missing prerequisite
- # skipping check '1' at t/helper/test-example-tap.c:108
+ # skipping check '1' at t/helper/test-example-tap.c:110
ok 24 - if_test test_skip() # SKIP
# skipping test - missing prerequisite
ok 25 - if_test test_skip() inside TEST_TODO() # SKIP
- # check "0" failed at t/helper/test-example-tap.c:113
+ # check "0" failed at t/helper/test-example-tap.c:115
not ok 26 - if_test TEST_TODO() after failing check
- # check "0" failed at t/helper/test-example-tap.c:119
+ # check "0" failed at t/helper/test-example-tap.c:121
not ok 27 - if_test failing check after TEST_TODO()
- # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:122
- # left: "\011hello\\\\"
- # right: "there\"\012"
- # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:123
+ # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:124
+ # left: "\thello\\\\"
+ # right: "there\"\n"
+ # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:125
# left: "NULL"
# right: NULL
- # check "'a' == '\n'" failed at t/helper/test-example-tap.c:124
+ # check "'a' == '\n'" failed at t/helper/test-example-tap.c:126
# left: 'a'
- # right: '\012'
- # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:125
+ # right: '\n'
+ # check "'\\\\' == '\''" failed at t/helper/test-example-tap.c:127
# left: '\\\\'
- # right: '\\''
+ # right: '\''
+ # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:128
+ # left: '\a'
+ # right: '\v'
+ # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:129
+ # left: '\000'
+ # right: '\001'
not ok 28 - if_test messages from failing string and char comparison
- # BUG: test has no checks at t/helper/test-example-tap.c:127
+ # BUG: test has no checks at t/helper/test-example-tap.c:131
not ok 29 - if_test test with no checks
1..29
EOF
diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
index 87e1f5c201..72ee20a06f 100644
--- a/t/unit-tests/test-lib.c
+++ b/t/unit-tests/test-lib.c
@@ -396,8 +396,23 @@ int check_uint_loc(const char *loc, const char *check, int ok,
static void print_one_char(char ch, char quote)
{
if ((unsigned char)ch < 0x20u || ch == 0x7f) {
- /* TODO: improve handling of \a, \b, \f ... */
- printf("\\%03o", (unsigned char)ch);
+ char esc;
+ switch (ch) {
+ case '\a': esc = 'a'; break;
+ case '\b': esc = 'b'; break;
+ case '\t': esc = 't'; break;
+ case '\n': esc = 'n'; break;
+ case '\v': esc = 'v'; break;
+ case '\f': esc = 'f'; break;
+ case '\r': esc = 'r'; break;
+ default: esc = 0; break;
+ }
+ if (esc) {
+ putc('\\', stdout);
+ putc(esc, stdout);
+ } else {
+ printf("\\%03o", (unsigned char)ch);
+ }
} else {
if (ch == '\\' || ch == quote)
putc('\\', stdout);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [GSoC PATCH] test-lib: print escape sequence names
2026-03-10 18:35 [GSoC PATCH] test-lib: print escape sequence names Pablo Sabater
@ 2026-03-10 18:48 ` Pablo
2026-03-11 3:14 ` [GSoC PATCH v2] " Pablo Sabater
1 sibling, 0 replies; 5+ messages in thread
From: Pablo @ 2026-03-10 18:48 UTC (permalink / raw)
To: git
I'm sorry, just rereading, on the expected output,
I just saw that when updating lines because of
the new tests added, it got changed:
# check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:65
to:
# check "'\\\\' == '\''" failed at t/helper/test-example-tap.c:65
and one more identical check some lines below
It should work the same way but it isn't directly related with what I did.
I can undo this change on a v2 if necessary
^ permalink raw reply [flat|nested] 5+ messages in thread
* [GSoC PATCH v2] test-lib: print escape sequence names
2026-03-10 18:35 [GSoC PATCH] test-lib: print escape sequence names Pablo Sabater
2026-03-10 18:48 ` Pablo
@ 2026-03-11 3:14 ` Pablo Sabater
2026-03-11 10:53 ` Pablo
2026-03-11 20:49 ` Junio C Hamano
1 sibling, 2 replies; 5+ messages in thread
From: Pablo Sabater @ 2026-03-11 3:14 UTC (permalink / raw)
To: git; +Cc: Pablo Sabater
When printing expected/actual characters in failed checks, use
their names (\a, \b, \n, ...) instead of their octal representation,
making it easier to read.
Add tests to test-example-tap.c
Update t0080-unit-test-output.sh to match the desired output
Teach 'print_one_char()' the equivalent name
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
Changes from v1:
reverted unrelated test change '\'' to '\\'' in t0080
t/helper/test-example-tap.c | 4 +++
t/t0080-unit-test-output.sh | 52 +++++++++++++++++++++++--------------
t/unit-tests/test-lib.c | 19 ++++++++++++--
3 files changed, 53 insertions(+), 22 deletions(-)
diff --git a/t/helper/test-example-tap.c b/t/helper/test-example-tap.c
index 229d495ecf..998a1f0b42 100644
--- a/t/helper/test-example-tap.c
+++ b/t/helper/test-example-tap.c
@@ -63,6 +63,8 @@ static void t_messages(void)
check_str("NULL", NULL);
check_char('a', ==, '\n');
check_char('\\', ==, '\'');
+ check_char('\a', ==, '\v');
+ check_char('\x00', ==, '\x01');
}
static void t_empty(void)
@@ -123,6 +125,8 @@ int cmd__example_tap(int argc UNUSED, const char **argv UNUSED)
check_str("NULL", NULL);
check_char('a', ==, '\n');
check_char('\\', ==, '\'');
+ check_char('\a', ==, '\v');
+ check_char('\x00', ==, '\x01');
}
if_test ("if_test test with no checks")
; /* nothing */
diff --git a/t/t0080-unit-test-output.sh b/t/t0080-unit-test-output.sh
index 3db10f095c..66838a00b2 100755
--- a/t/t0080-unit-test-output.sh
+++ b/t/t0080-unit-test-output.sh
@@ -6,10 +6,10 @@ test_description='Test the output of the unit test framework'
test_expect_success 'TAP output from unit tests' - <<\EOT
cat >expect <<-EOF &&
- # BUG: check outside of test at t/helper/test-example-tap.c:75
+ # BUG: check outside of test at t/helper/test-example-tap.c:77
ok 1 - passing test
ok 2 - passing test and assertion return 1
- # check "1 == 2" failed at t/helper/test-example-tap.c:79
+ # check "1 == 2" failed at t/helper/test-example-tap.c:81
# left: 1
# right: 2
not ok 3 - failing test
@@ -34,53 +34,65 @@ test_expect_success 'TAP output from unit tests' - <<\EOT
not ok 15 - failing check after TEST_TODO()
ok 16 - failing check after TEST_TODO() returns 0
# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
- # left: "\011hello\\\\"
- # right: "there\"\012"
+ # left: "\thello\\\\"
+ # right: "there\"\n"
# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
# left: "NULL"
# right: NULL
# check "'a' == '\n'" failed at t/helper/test-example-tap.c:64
# left: 'a'
- # right: '\012'
+ # right: '\n'
# check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:65
# left: '\\\\'
# right: '\\''
+ # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:66
+ # left: '\a'
+ # right: '\v'
+ # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:67
+ # left: '\000'
+ # right: '\001'
not ok 17 - messages from failing string and char comparison
- # BUG: test has no checks at t/helper/test-example-tap.c:94
+ # BUG: test has no checks at t/helper/test-example-tap.c:96
not ok 18 - test with no checks
ok 19 - test with no checks returns 0
ok 20 - if_test passing test
- # check "1 == 2" failed at t/helper/test-example-tap.c:100
+ # check "1 == 2" failed at t/helper/test-example-tap.c:102
# left: 1
# right: 2
not ok 21 - if_test failing test
not ok 22 - if_test passing TEST_TODO() # TODO
- # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:104
+ # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:106
not ok 23 - if_test failing TEST_TODO()
- # check "0" failed at t/helper/test-example-tap.c:106
+ # check "0" failed at t/helper/test-example-tap.c:108
# skipping test - missing prerequisite
- # skipping check '1' at t/helper/test-example-tap.c:108
+ # skipping check '1' at t/helper/test-example-tap.c:110
ok 24 - if_test test_skip() # SKIP
# skipping test - missing prerequisite
ok 25 - if_test test_skip() inside TEST_TODO() # SKIP
- # check "0" failed at t/helper/test-example-tap.c:113
+ # check "0" failed at t/helper/test-example-tap.c:115
not ok 26 - if_test TEST_TODO() after failing check
- # check "0" failed at t/helper/test-example-tap.c:119
+ # check "0" failed at t/helper/test-example-tap.c:121
not ok 27 - if_test failing check after TEST_TODO()
- # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:122
- # left: "\011hello\\\\"
- # right: "there\"\012"
- # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:123
+ # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:124
+ # left: "\thello\\\\"
+ # right: "there\"\n"
+ # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:125
# left: "NULL"
# right: NULL
- # check "'a' == '\n'" failed at t/helper/test-example-tap.c:124
+ # check "'a' == '\n'" failed at t/helper/test-example-tap.c:126
# left: 'a'
- # right: '\012'
- # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:125
+ # right: '\n'
+ # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:127
# left: '\\\\'
# right: '\\''
+ # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:128
+ # left: '\a'
+ # right: '\v'
+ # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:129
+ # left: '\000'
+ # right: '\001'
not ok 28 - if_test messages from failing string and char comparison
- # BUG: test has no checks at t/helper/test-example-tap.c:127
+ # BUG: test has no checks at t/helper/test-example-tap.c:131
not ok 29 - if_test test with no checks
1..29
EOF
diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
index 87e1f5c201..72ee20a06f 100644
--- a/t/unit-tests/test-lib.c
+++ b/t/unit-tests/test-lib.c
@@ -396,8 +396,23 @@ int check_uint_loc(const char *loc, const char *check, int ok,
static void print_one_char(char ch, char quote)
{
if ((unsigned char)ch < 0x20u || ch == 0x7f) {
- /* TODO: improve handling of \a, \b, \f ... */
- printf("\\%03o", (unsigned char)ch);
+ char esc;
+ switch (ch) {
+ case '\a': esc = 'a'; break;
+ case '\b': esc = 'b'; break;
+ case '\t': esc = 't'; break;
+ case '\n': esc = 'n'; break;
+ case '\v': esc = 'v'; break;
+ case '\f': esc = 'f'; break;
+ case '\r': esc = 'r'; break;
+ default: esc = 0; break;
+ }
+ if (esc) {
+ putc('\\', stdout);
+ putc(esc, stdout);
+ } else {
+ printf("\\%03o", (unsigned char)ch);
+ }
} else {
if (ch == '\\' || ch == quote)
putc('\\', stdout);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [GSoC PATCH v2] test-lib: print escape sequence names
2026-03-11 3:14 ` [GSoC PATCH v2] " Pablo Sabater
@ 2026-03-11 10:53 ` Pablo
2026-03-11 20:49 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Pablo @ 2026-03-11 10:53 UTC (permalink / raw)
To: git, christian.couder, karthik nayak, jltobler, Ayush Chandekar,
Siddharth Asthana, Chandra Pratap
Adding project mentors to CC, sorry I should have done this earlier,
but I didn't have the project clear and didn't want to spam, I'll CC
on the proposal, introduction and microproject as well.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [GSoC PATCH v2] test-lib: print escape sequence names
2026-03-11 3:14 ` [GSoC PATCH v2] " Pablo Sabater
2026-03-11 10:53 ` Pablo
@ 2026-03-11 20:49 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2026-03-11 20:49 UTC (permalink / raw)
To: Pablo Sabater; +Cc: git
Pablo Sabater <pabloosabaterr@gmail.com> writes:
> When printing expected/actual characters in failed checks, use
> their names (\a, \b, \n, ...) instead of their octal representation,
> making it easier to read.
>
> Add tests to test-example-tap.c
> Update t0080-unit-test-output.sh to match the desired output
>
> Teach 'print_one_char()' the equivalent name
>
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
> Changes from v1:
> reverted unrelated test change '\'' to '\\'' in t0080
>
> t/helper/test-example-tap.c | 4 +++
> t/t0080-unit-test-output.sh | 52 +++++++++++++++++++++++--------------
> t/unit-tests/test-lib.c | 19 ++++++++++++--
> 3 files changed, 53 insertions(+), 22 deletions(-)
Looking good. Will queue. Thanks.
>
> diff --git a/t/helper/test-example-tap.c b/t/helper/test-example-tap.c
> index 229d495ecf..998a1f0b42 100644
> --- a/t/helper/test-example-tap.c
> +++ b/t/helper/test-example-tap.c
> @@ -63,6 +63,8 @@ static void t_messages(void)
> check_str("NULL", NULL);
> check_char('a', ==, '\n');
> check_char('\\', ==, '\'');
> + check_char('\a', ==, '\v');
> + check_char('\x00', ==, '\x01');
> }
>
> static void t_empty(void)
> @@ -123,6 +125,8 @@ int cmd__example_tap(int argc UNUSED, const char **argv UNUSED)
> check_str("NULL", NULL);
> check_char('a', ==, '\n');
> check_char('\\', ==, '\'');
> + check_char('\a', ==, '\v');
> + check_char('\x00', ==, '\x01');
> }
> if_test ("if_test test with no checks")
> ; /* nothing */
> diff --git a/t/t0080-unit-test-output.sh b/t/t0080-unit-test-output.sh
> index 3db10f095c..66838a00b2 100755
> --- a/t/t0080-unit-test-output.sh
> +++ b/t/t0080-unit-test-output.sh
> @@ -6,10 +6,10 @@ test_description='Test the output of the unit test framework'
>
> test_expect_success 'TAP output from unit tests' - <<\EOT
> cat >expect <<-EOF &&
> - # BUG: check outside of test at t/helper/test-example-tap.c:75
> + # BUG: check outside of test at t/helper/test-example-tap.c:77
> ok 1 - passing test
> ok 2 - passing test and assertion return 1
> - # check "1 == 2" failed at t/helper/test-example-tap.c:79
> + # check "1 == 2" failed at t/helper/test-example-tap.c:81
> # left: 1
> # right: 2
> not ok 3 - failing test
> @@ -34,53 +34,65 @@ test_expect_success 'TAP output from unit tests' - <<\EOT
> not ok 15 - failing check after TEST_TODO()
> ok 16 - failing check after TEST_TODO() returns 0
> # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
> - # left: "\011hello\\\\"
> - # right: "there\"\012"
> + # left: "\thello\\\\"
> + # right: "there\"\n"
> # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
> # left: "NULL"
> # right: NULL
> # check "'a' == '\n'" failed at t/helper/test-example-tap.c:64
> # left: 'a'
> - # right: '\012'
> + # right: '\n'
> # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:65
> # left: '\\\\'
> # right: '\\''
> + # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:66
> + # left: '\a'
> + # right: '\v'
> + # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:67
> + # left: '\000'
> + # right: '\001'
> not ok 17 - messages from failing string and char comparison
> - # BUG: test has no checks at t/helper/test-example-tap.c:94
> + # BUG: test has no checks at t/helper/test-example-tap.c:96
> not ok 18 - test with no checks
> ok 19 - test with no checks returns 0
> ok 20 - if_test passing test
> - # check "1 == 2" failed at t/helper/test-example-tap.c:100
> + # check "1 == 2" failed at t/helper/test-example-tap.c:102
> # left: 1
> # right: 2
> not ok 21 - if_test failing test
> not ok 22 - if_test passing TEST_TODO() # TODO
> - # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:104
> + # todo check 'check(1)' succeeded at t/helper/test-example-tap.c:106
> not ok 23 - if_test failing TEST_TODO()
> - # check "0" failed at t/helper/test-example-tap.c:106
> + # check "0" failed at t/helper/test-example-tap.c:108
> # skipping test - missing prerequisite
> - # skipping check '1' at t/helper/test-example-tap.c:108
> + # skipping check '1' at t/helper/test-example-tap.c:110
> ok 24 - if_test test_skip() # SKIP
> # skipping test - missing prerequisite
> ok 25 - if_test test_skip() inside TEST_TODO() # SKIP
> - # check "0" failed at t/helper/test-example-tap.c:113
> + # check "0" failed at t/helper/test-example-tap.c:115
> not ok 26 - if_test TEST_TODO() after failing check
> - # check "0" failed at t/helper/test-example-tap.c:119
> + # check "0" failed at t/helper/test-example-tap.c:121
> not ok 27 - if_test failing check after TEST_TODO()
> - # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:122
> - # left: "\011hello\\\\"
> - # right: "there\"\012"
> - # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:123
> + # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:124
> + # left: "\thello\\\\"
> + # right: "there\"\n"
> + # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:125
> # left: "NULL"
> # right: NULL
> - # check "'a' == '\n'" failed at t/helper/test-example-tap.c:124
> + # check "'a' == '\n'" failed at t/helper/test-example-tap.c:126
> # left: 'a'
> - # right: '\012'
> - # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:125
> + # right: '\n'
> + # check "'\\\\' == '\\''" failed at t/helper/test-example-tap.c:127
> # left: '\\\\'
> # right: '\\''
> + # check "'\a' == '\v'" failed at t/helper/test-example-tap.c:128
> + # left: '\a'
> + # right: '\v'
> + # check "'\x00' == '\x01'" failed at t/helper/test-example-tap.c:129
> + # left: '\000'
> + # right: '\001'
> not ok 28 - if_test messages from failing string and char comparison
> - # BUG: test has no checks at t/helper/test-example-tap.c:127
> + # BUG: test has no checks at t/helper/test-example-tap.c:131
> not ok 29 - if_test test with no checks
> 1..29
> EOF
> diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
> index 87e1f5c201..72ee20a06f 100644
> --- a/t/unit-tests/test-lib.c
> +++ b/t/unit-tests/test-lib.c
> @@ -396,8 +396,23 @@ int check_uint_loc(const char *loc, const char *check, int ok,
> static void print_one_char(char ch, char quote)
> {
> if ((unsigned char)ch < 0x20u || ch == 0x7f) {
> - /* TODO: improve handling of \a, \b, \f ... */
> - printf("\\%03o", (unsigned char)ch);
> + char esc;
> + switch (ch) {
> + case '\a': esc = 'a'; break;
> + case '\b': esc = 'b'; break;
> + case '\t': esc = 't'; break;
> + case '\n': esc = 'n'; break;
> + case '\v': esc = 'v'; break;
> + case '\f': esc = 'f'; break;
> + case '\r': esc = 'r'; break;
> + default: esc = 0; break;
> + }
> + if (esc) {
> + putc('\\', stdout);
> + putc(esc, stdout);
> + } else {
> + printf("\\%03o", (unsigned char)ch);
> + }
> } else {
> if (ch == '\\' || ch == quote)
> putc('\\', stdout);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-11 20:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 18:35 [GSoC PATCH] test-lib: print escape sequence names Pablo Sabater
2026-03-10 18:48 ` Pablo
2026-03-11 3:14 ` [GSoC PATCH v2] " Pablo Sabater
2026-03-11 10:53 ` Pablo
2026-03-11 20:49 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox