Skip to content

Commit 371471c

Browse files
dschogitster
authored andcommitted
t0060: loosen overly strict expectations
The dirname() tests file were developed and tested on only the five platforms available to the developer at the time, namely: Linux (both 32 and 64bit), Windows XP 32-bit (MSVC), MinGW 32-bit and Cygwin 32-bit. http://pubs.opengroup.org/onlinepubs/9699919799/functions/basename.html (i.e. the POSIX spec) says, in part: If the string pointed to by path consists entirely of the '/' character, basename() shall return a pointer to the string "/". If the string pointed to by path is exactly "//", it is implementation-defined whether "/" or "//" is returned. The thinking behind testing precise, OS-dependent output values was to document that different setups produce different values. However, as the test failures on MacOSX illustrated eloquently: hardcoding pretty much each and every setup's expectations is pretty fragile. This is not limited to the "//" vs "/" case, of course, other inputs are also allowed to produce multiple outputs by the POSIX specs. So let's just test for all allowed values and be done with it. This still documents that Git cannot rely on one particular output value in those cases, so the intention of the original tests is still met. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d1aaa6 commit 371471c

File tree

1 file changed

+21
-57
lines changed

1 file changed

+21
-57
lines changed

test-path-utils.c

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void normalize_argv_string(const char **var, const char *input)
4242
struct test_data {
4343
const char *from; /* input: transform from this ... */
4444
const char *to; /* output: ... to this. */
45+
const char *alternative; /* output: ... or this. */
4546
};
4647

4748
static int test_function(struct test_data *data, char *(*func)(char *input),
@@ -58,11 +59,18 @@ static int test_function(struct test_data *data, char *(*func)(char *input),
5859
strcpy(buffer, data[i].from);
5960
to = func(buffer);
6061
}
61-
if (strcmp(to, data[i].to)) {
62+
if (!strcmp(to, data[i].to))
63+
continue;
64+
if (!data[i].alternative)
6265
error("FAIL: %s(%s) => '%s' != '%s'\n",
6366
funcname, data[i].from, to, data[i].to);
64-
failed = 1;
65-
}
67+
else if (!strcmp(to, data[i].alternative))
68+
continue;
69+
else
70+
error("FAIL: %s(%s) => '%s' != '%s', '%s'\n",
71+
funcname, data[i].from, to, data[i].to,
72+
data[i].alternative);
73+
failed = 1;
6674
}
6775
return failed;
6876
}
@@ -74,15 +82,9 @@ static struct test_data basename_data[] = {
7482
{ ".", "." },
7583
{ "..", ".." },
7684
{ "/", "/" },
77-
#if defined(__CYGWIN__) && !defined(NO_LIBGEN_H)
78-
{ "//", "//" },
79-
{ "///", "//" },
80-
{ "////", "//" },
81-
#else
82-
{ "//", "/" },
83-
{ "///", "/" },
84-
{ "////", "/" },
85-
#endif
85+
{ "//", "/", "//" },
86+
{ "///", "/", "//" },
87+
{ "////", "/", "//" },
8688
{ "usr", "usr" },
8789
{ "/usr", "usr" },
8890
{ "/usr/", "usr" },
@@ -92,7 +94,6 @@ static struct test_data basename_data[] = {
9294
{ "usr/lib///", "lib" },
9395

9496
#if defined(__MINGW32__) || defined(_MSC_VER)
95-
9697
/* --- win32 type paths --- */
9798
{ "\\usr", "usr" },
9899
{ "\\usr\\", "usr" },
@@ -111,26 +112,9 @@ static struct test_data basename_data[] = {
111112
{ "C:a", "a" },
112113
{ "C:/", "/" },
113114
{ "C:///", "/" },
114-
#if defined(NO_LIBGEN_H)
115-
{ "\\", "\\" },
116-
{ "\\\\", "\\" },
117-
{ "\\\\\\", "\\" },
118-
#else
119-
120-
/* win32 platform variations: */
121-
#if defined(__MINGW32__)
122-
{ "\\", "/" },
123-
{ "\\\\", "/" },
124-
{ "\\\\\\", "/" },
125-
#endif
126-
127-
#if defined(_MSC_VER)
128-
{ "\\", "\\" },
129-
{ "\\\\", "\\" },
130-
{ "\\\\\\", "\\" },
131-
#endif
132-
133-
#endif
115+
{ "\\", "\\", "/" },
116+
{ "\\\\", "\\", "/" },
117+
{ "\\\\\\", "\\", "/" },
134118
#endif
135119
{ NULL, NULL }
136120
};
@@ -142,14 +126,9 @@ static struct test_data dirname_data[] = {
142126
{ ".", "." },
143127
{ "..", "." },
144128
{ "/", "/" },
145-
{ "//", "//" },
146-
#if defined(__CYGWIN__) && !defined(NO_LIBGEN_H)
147-
{ "///", "//" },
148-
{ "////", "//" },
149-
#else
150-
{ "///", "/" },
151-
{ "////", "/" },
152-
#endif
129+
{ "//", "/", "//" },
130+
{ "///", "/", "//" },
131+
{ "////", "/", "//" },
153132
{ "usr", "." },
154133
{ "/usr", "/" },
155134
{ "/usr/", "/" },
@@ -159,7 +138,6 @@ static struct test_data dirname_data[] = {
159138
{ "usr/lib///", "usr" },
160139

161140
#if defined(__MINGW32__) || defined(_MSC_VER)
162-
163141
/* --- win32 type paths --- */
164142
{ "\\", "\\" },
165143
{ "\\\\", "\\\\" },
@@ -180,21 +158,7 @@ static struct test_data dirname_data[] = {
180158
{ "C:usr/lib///", "C:usr" },
181159
{ "\\\\\\", "\\" },
182160
{ "\\\\\\\\", "\\" },
183-
#if defined(NO_LIBGEN_H)
184-
{ "C:", "C:." },
185-
#else
186-
187-
/* win32 platform variations: */
188-
#if defined(__MINGW32__)
189-
/* the following is clearly wrong ... */
190-
{ "C:", "." },
191-
#endif
192-
193-
#if defined(_MSC_VER)
194-
{ "C:", "C:." },
195-
#endif
196-
197-
#endif
161+
{ "C:", "C:.", "." },
198162
#endif
199163
{ NULL, NULL }
200164
};

0 commit comments

Comments
 (0)