Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Apr 20, 2018
1 parent 0b33543 commit e101879
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/fs/test_unlink.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

int main() {
const char *filename = "test.dat";
const char *dirname = "test";

// Create a file
FILE *f = fopen(filename, "wb");
if (f == NULL) {
return 1;
}
if (fclose(f)) {
return 1;
}
// Check it exists
if (access(filename, F_OK) != 0) {
return 1;
}
// Delete the file
if (unlinkat(AT_FDCWD, filename, 0)) {
return 1;
}
// Check that it doesn't exist
if (access(filename, F_OK) != -1) {
return 1;
}

// Create a directory
if (mkdir(dirname, 0700)) {
return 1;
}
// Delete the directory
if (unlinkat(AT_FDCWD, dirname, AT_REMOVEDIR)) {
return 1;
}
// Check that it doesn't exist
if (access(dirname, F_OK) != -1) {
return 1;
}

return 0;
}
Empty file added tests/fs/test_unlink.out
Empty file.
6 changes: 6 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,12 @@ def test_init_file_at_offset(self):
Popen([PYTHON, EMCC, 'src.cpp']).communicate()
self.assertContained('read: 0\nfile size is 104\n', run_js('a.out.js'))

def test_unlink(self):
self.emcc_args = []
src = path_from_root('tests', 'fs', 'test_unlink.c')
out = path_from_root('tests', 'fs', 'test_unlink.out')
self.do_run_from_file(src, out, js_engines=[NODE_JS])

def test_argv0_node(self):
open('code.cpp', 'w').write(r'''
#include <stdio.h>
Expand Down

0 comments on commit e101879

Please sign in to comment.