Skip to content

Commit

Permalink
Add testing for making and removing directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed May 26, 2024
1 parent aee077c commit f7c90bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions test/suite-bundle.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f7c90bc

Please sign in to comment.