1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-23 05:36:52 +00:00

Add testing for making and removing directory.

This commit is contained in:
Calvin Rose 2024-05-26 10:21:52 -05:00
parent aee077c1bd
commit f7c90bc1ff
2 changed files with 14 additions and 2 deletions

View File

@ -2411,8 +2411,17 @@ JANET_CORE_FN(os_dir,
/* Read directory items with opendir / readdir / closedir */ /* Read directory items with opendir / readdir / closedir */
struct dirent *dp; struct dirent *dp;
DIR *dfd = opendir(dir); DIR *dfd = opendir(dir);
if (dfd == NULL) janet_panicf("cannot open directory %s", dir); if (dfd == NULL) janet_panicf("cannot open directory %s: %s", dir, janet_strerror(errno));
while ((dp = readdir(dfd)) != NULL) { 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, "..")) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
continue; continue;
} }

View File

@ -40,6 +40,9 @@
(os/rm x)) (os/rm x))
nil) nil)
# Test mkdir -> rmdir
(assert (os/mkdir "./tempdir123"))
(rmrf "./tempdir123")
# Setup a temporary syspath for manipultation # Setup a temporary syspath for manipultation
(math/seedrandom (os/cryptorand 16)) (math/seedrandom (os/cryptorand 16))