Simplify paths in C test runner output

In a Discord #get-help thread, I noticed the C test runner uses absolute paths in its message. I’d like to propose simplifying the reported paths per The Test Runner Interface | Exercism's Docs.

Original Output
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `main':
/mnt/exercism-iteration/./test_leap.c:59: multiple definition of `main'; /tmp/ccAeFFaB.o:/mnt/exercism-iteration/./leap.c:6: first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `test_year_not_divisible_by_4_in_common_year':
/mnt/exercism-iteration/./test_leap.c:14:(.text+0x18): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_2_not_divisible_by_4_in_common_year':
/mnt/exercism-iteration/./test_leap.c:19:(.text+0x44): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_4_not_divisible_by_100_in_leap_year':
/mnt/exercism-iteration/./test_leap.c:24:(.text+0x70): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_4_and_5_is_still_a_leap_year':
/mnt/exercism-iteration/./test_leap.c:29:(.text+0x99): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_100_not_divisible_by_400_in_common_year':
/mnt/exercism-iteration/./test_leap.c:34:(.text+0xc2): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccalHfIF.o:/mnt/exercism-iteration/./test_leap.c:40: more undefined references to `leap_year' follow
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

becomes something like

Updated Output
ld: /tmp/ccalHfIF.o: in function `main':
test_leap.c:59: multiple definition of `main'; leap.c:6: first defined here
ld: /tmp/ccalHfIF.o: in function `test_year_not_divisible_by_4_in_common_year':
test_leap.c:14:(.text+0x18): undefined reference to `leap_year'
ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_2_not_divisible_by_4_in_common_year':
test_leap.c:19:(.text+0x44): undefined reference to `leap_year'
ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_4_not_divisible_by_100_in_leap_year':
test_leap.c:24:(.text+0x70): undefined reference to `leap_year'
ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_4_and_5_is_still_a_leap_year':
test_leap.c:29:(.text+0x99): undefined reference to `leap_year'
ld: /tmp/ccalHfIF.o: in function `test_year_divisible_by_100_not_divisible_by_400_in_common_year':
test_leap.c:34:(.text+0xc2): undefined reference to `leap_year'
ld: test_leap.c:40: more undefined references to `leap_year' follow
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

I experimented around in makefile a bit.
Full paths to .c source files: the -g flag in makefile seems to have something to do with forcing full path. Could be “fixed” by getting rid of -g flag, but we might need that for something.
This doesnt fix full paths to cc and ld. Maybe CC and LD can be defined in the makefile to local commands?

The -g flag add debug information to the binary (see the documentation).

I’ve used sed to replace parts of file paths in the test runner output on other tracks, and that seems to be a fairly unobtrusive band-aid fix.

1 Like