test-dir-iterator: do not assume errno values
A few tests printed 'errno' as an integer and compared with hardcoded integers; this is obviously not portable. A two things to note are: - the string obtained by strerror() is not portable, and cannot be used for the purpose of these tests. - there unfortunately isn't a portable way to map error numbers to error names. As we only care about a few selected errors, just map the error number to the name before emitting for comparison. Reported-by: Randall S. Becker <rsbecker@nexbridge.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 30, 2019 at 10:45 UTC
90421400977b3c80fdb8b887c61272a8f3ec0d18
2 files changed
+12
-3
t/helper/test-dir-iterator.c
+10
-1
@@ -4,6 +4,15 @@
4
#include "iterator.h"
5
#include "dir-iterator.h"
6
7
+static const char *error_name(int error_number)
8
+{
9
+ switch (error_number) {
10
+ case ENOENT: return "ENOENT";
11
+ case ENOTDIR: return "ENOTDIR";
12
+ default: return "ESOMETHINGELSE";
13
+ }
14
+}
15
+
16
/*
17
* usage:
18
* tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
@@ -31,7 +40,7 @@ int cmd__dir_iterator(int argc, const char **argv)
40
diter = dir_iterator_begin(path.buf, flags);
41
42
if (!diter) {
34
- printf("dir_iterator_begin failure: %d\n", errno);
43
+ printf("dir_iterator_begin failure: %s\n", error_name(errno));
44
exit(EXIT_FAILURE);
45
}
46
t/t0066-dir-iterator.sh
+2
-2
@@ -55,13 +55,13 @@ test_expect_success 'dir-iterator should list files in the correct order' '
55
test_expect_success 'begin should fail upon inexistent paths' '
56
test_must_fail test-tool dir-iterator ./inexistent-path \
57
>actual-inexistent-path-output &&
58
- echo "dir_iterator_begin failure: 2" >expected-inexistent-path-output &&
58
+ echo "dir_iterator_begin failure: ENOENT" >expected-inexistent-path-output &&
59
test_cmp expected-inexistent-path-output actual-inexistent-path-output
60
'
61
62
test_expect_success 'begin should fail upon non directory paths' '
63
test_must_fail test-tool dir-iterator ./dir/b >actual-non-dir-output &&
64
- echo "dir_iterator_begin failure: 20" >expected-non-dir-output &&
64
+ echo "dir_iterator_begin failure: ENOTDIR" >expected-non-dir-output &&
65
test_cmp expected-non-dir-output actual-non-dir-output
66
'
67