From f7c90bc1ffe8768cd852aebe69cffec8408bb26a Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 26 May 2024 10:21:52 -0500 Subject: [PATCH] Add testing for making and removing directory. --- src/core/os.c | 13 +++++++++++-- test/suite-bundle.janet | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/os.c b/src/core/os.c index 9e0fb5dc..3155589e 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -2411,8 +2411,17 @@ JANET_CORE_FN(os_dir, /* Read directory items with opendir / readdir / closedir */ struct dirent *dp; DIR *dfd = opendir(dir); - if (dfd == NULL) janet_panicf("cannot open directory %s", dir); - while ((dp = readdir(dfd)) != NULL) { + if (dfd == NULL) janet_panicf("cannot open directory %s: %s", dir, janet_strerror(errno)); + for (;;) { + errno = 0; + dp = readdir(dfd); + if (dp == NULL) { + if (errno) { + closedir(dfd); + janet_panicf("failed to read directory %s: %s", dir, janet_strerror(errno)); + } + break; + } if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { continue; } diff --git a/test/suite-bundle.janet b/test/suite-bundle.janet index a92a318d..645616c3 100644 --- a/test/suite-bundle.janet +++ b/test/suite-bundle.janet @@ -40,6 +40,9 @@ (os/rm x)) nil) +# Test mkdir -> rmdir +(assert (os/mkdir "./tempdir123")) +(rmrf "./tempdir123") # Setup a temporary syspath for manipultation (math/seedrandom (os/cryptorand 16))