@@ -21,6 +21,46 @@ static struct {
21
21
.result = RESULT_NONE ,
22
22
};
23
23
24
+ #ifndef _MSC_VER
25
+ #define make_relative (location ) location
26
+ #else
27
+ /*
28
+ * Visual C interpolates the absolute Windows path for `__FILE__`,
29
+ * but we want to see relative paths, as verified by t0080.
30
+ */
31
+ #include "dir.h"
32
+
33
+ static const char * make_relative (const char * location )
34
+ {
35
+ static char prefix [] = __FILE__ , buf [PATH_MAX ], * p ;
36
+ static size_t prefix_len ;
37
+
38
+ if (!prefix_len ) {
39
+ size_t len = strlen (prefix );
40
+ const char * needle = "\\t\\unit-tests\\test-lib.c" ;
41
+ size_t needle_len = strlen (needle );
42
+
43
+ if (len < needle_len || strcmp (needle , prefix + len - needle_len ))
44
+ die ("unexpected suffix of '%s'" , prefix );
45
+
46
+ /* let it end in a directory separator */
47
+ prefix_len = len - needle_len + 1 ;
48
+ }
49
+
50
+ /* Does it not start with the expected prefix? */
51
+ if (fspathncmp (location , prefix , prefix_len ))
52
+ return location ;
53
+
54
+ strlcpy (buf , location + prefix_len , sizeof (buf ));
55
+ /* convert backslashes to forward slashes */
56
+ for (p = buf ; * p ; p ++ )
57
+ if (* p == '\\' )
58
+ * p = '/' ;
59
+
60
+ return buf ;
61
+ }
62
+ #endif
63
+
24
64
static void msg_with_prefix (const char * prefix , const char * format , va_list ap )
25
65
{
26
66
fflush (stderr );
@@ -147,7 +187,8 @@ int test__run_end(int was_run UNUSED, const char *location, const char *format,
147
187
break ;
148
188
149
189
case RESULT_NONE :
150
- test_msg ("BUG: test has no checks at %s" , location );
190
+ test_msg ("BUG: test has no checks at %s" ,
191
+ make_relative (location ));
151
192
printf ("not ok %d" , ctx .count );
152
193
print_description (format , ap );
153
194
ctx .result = RESULT_FAILURE ;
@@ -193,14 +234,16 @@ int test_assert(const char *location, const char *check, int ok)
193
234
assert (ctx .running );
194
235
195
236
if (ctx .result == RESULT_SKIP ) {
196
- test_msg ("skipping check '%s' at %s" , check , location );
237
+ test_msg ("skipping check '%s' at %s" , check ,
238
+ make_relative (location ));
197
239
return 1 ;
198
240
}
199
241
if (!ctx .todo ) {
200
242
if (ok ) {
201
243
test_pass ();
202
244
} else {
203
- test_msg ("check \"%s\" failed at %s" , check , location );
245
+ test_msg ("check \"%s\" failed at %s" , check ,
246
+ make_relative (location ));
204
247
test_fail ();
205
248
}
206
249
}
@@ -225,7 +268,8 @@ int test__todo_end(const char *location, const char *check, int res)
225
268
if (ctx .result == RESULT_SKIP )
226
269
return 1 ;
227
270
if (res ) {
228
- test_msg ("todo check '%s' succeeded at %s" , check , location );
271
+ test_msg ("todo check '%s' succeeded at %s" , check ,
272
+ make_relative (location ));
229
273
test_fail ();
230
274
} else {
231
275
test_todo ();
0 commit comments