summaryrefslogtreecommitdiff
path: root/t/helper/test-dir-iterator.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-07-30 10:45:48 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-07-30 10:45:48 -0700
commit90421400977b3c80fdb8b887c61272a8f3ec0d18 (patch)
tree36078df61176c416dd93278907ba6bf6a5c851bc /t/helper/test-dir-iterator.c
parentclone: replace strcmp by fspathcmp (diff)
downloadtgif-90421400977b3c80fdb8b887c61272a8f3ec0d18.tar.xz
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>
Diffstat (limited to 't/helper/test-dir-iterator.c')
-rw-r--r--t/helper/test-dir-iterator.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
index a5b96cb0dc..c7c30664da 100644
--- a/t/helper/test-dir-iterator.c
+++ b/t/helper/test-dir-iterator.c
@@ -4,6 +4,15 @@
#include "iterator.h"
#include "dir-iterator.h"
+static const char *error_name(int error_number)
+{
+ switch (error_number) {
+ case ENOENT: return "ENOENT";
+ case ENOTDIR: return "ENOTDIR";
+ default: return "ESOMETHINGELSE";
+ }
+}
+
/*
* usage:
* tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
@@ -31,7 +40,7 @@ int cmd__dir_iterator(int argc, const char **argv)
diter = dir_iterator_begin(path.buf, flags);
if (!diter) {
- printf("dir_iterator_begin failure: %d\n", errno);
+ printf("dir_iterator_begin failure: %s\n", error_name(errno));
exit(EXIT_FAILURE);
}