aboutsummaryrefslogtreecommitdiff
path: root/t/unit-tests
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-19 09:54:56 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-19 09:54:56 -0700
commit80595ab08ef501aef6d9b55856cdc9b092ed6e12 (patch)
tree5f628b2166955d13e40034cdce17d269dd0ce330 /t/unit-tests
parent5a0ee6f793d57510770947c51df1ce76055aa196 (diff)
parente30e9442fd9b90d96dde2fad4a6b26d7a03dee5e (diff)
downloadgit-80595ab08ef501aef6d9b55856cdc9b092ed6e12.tar.xz
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
Diffstat (limited to 't/unit-tests')
-rw-r--r--t/unit-tests/test-lib.c19
1 files changed, 17 insertions, 2 deletions
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);