Skip to content

Commit

Permalink
Convert test_stat_fail_alongtheway to a file based test (emscripten-c…
Browse files Browse the repository at this point in the history
…ore#21138)

Also remove the special logging and just use assert which fails
fast and gives a backtrace.
  • Loading branch information
sbc100 authored Jan 24, 2024
1 parent 50a7531 commit fb4bdc7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 71 deletions.
43 changes: 43 additions & 0 deletions test/other/test_stat_fail_alongtheway.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>

int main() {
assert(mkdir("path", 0777) == 0);
assert(close(open("path/file", O_CREAT | O_WRONLY, 0644)) == 0);
{
struct stat st;
assert(stat("path", &st) == 0);
assert(st.st_mode = 0777);
}
{
struct stat st;
assert(stat("path/nosuchfile", &st) == -1);
printf("info: errno=%d %s\n", errno, strerror(errno));
assert(errno == ENOENT);
}
{
struct stat st;
assert(stat("path/file", &st) == 0);
assert(st.st_mode = 0666);
}
{
struct stat st;
assert(stat("path/file/impossible", &st) == -1);
printf("info: errno=%d %s\n", errno, strerror(errno));
assert(errno == ENOTDIR);
}
{
struct stat st;
assert(lstat("path/file/impossible", &st) == -1);
printf("info: errno=%d %s\n", errno, strerror(errno));
assert(errno == ENOTDIR);
}
return 0;
}
3 changes: 3 additions & 0 deletions test/other/test_stat_fail_alongtheway.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
info: errno=44 No such file or directory
info: errno=54 Not a directory
info: errno=54 Not a directory
72 changes: 1 addition & 71 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6122,77 +6122,7 @@ def test(opts, has, not_has):
test(['-sEXPORTED_RUNTIME_METHODS=[]', '-sEXPORTED_RUNTIME_METHODS=addRunDependency'], "Module['addRunDependency", "Module['waka")

def test_stat_fail_alongtheway(self):
create_file('src.c', r'''
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>

#define CHECK(expression) \
if(!(expression)) { \
error = errno; \
printf("FAIL: %s\n", #expression); fail = 1; \
} else { \
error = errno; \
printf("pass: %s\n", #expression); \
} \

int main() {
int error;
int fail = 0;
CHECK(mkdir("path", 0777) == 0);
CHECK(close(open("path/file", O_CREAT | O_WRONLY, 0644)) == 0);
{
struct stat st;
CHECK(stat("path", &st) == 0);
CHECK(st.st_mode = 0777);
}
{
struct stat st;
CHECK(stat("path/nosuchfile", &st) == -1);
printf("info: errno=%d %s\n", error, strerror(error));
CHECK(error == ENOENT);
}
{
struct stat st;
CHECK(stat("path/file", &st) == 0);
CHECK(st.st_mode = 0666);
}
{
struct stat st;
CHECK(stat("path/file/impossible", &st) == -1);
printf("info: errno=%d %s\n", error, strerror(error));
CHECK(error == ENOTDIR);
}
{
struct stat st;
CHECK(lstat("path/file/impossible", &st) == -1);
printf("info: errno=%d %s\n", error, strerror(error));
CHECK(error == ENOTDIR);
}
return fail;
}
''')
self.do_runf('src.c', r'''pass: mkdir("path", 0777) == 0
pass: close(open("path/file", O_CREAT | O_WRONLY, 0644)) == 0
pass: stat("path", &st) == 0
pass: st.st_mode = 0777
pass: stat("path/nosuchfile", &st) == -1
info: errno=44 No such file or directory
pass: error == ENOENT
pass: stat("path/file", &st) == 0
pass: st.st_mode = 0666
pass: stat("path/file/impossible", &st) == -1
info: errno=54 Not a directory
pass: error == ENOTDIR
pass: lstat("path/file/impossible", &st) == -1
info: errno=54 Not a directory
pass: error == ENOTDIR
''')
self.do_other_test('test_stat_fail_alongtheway.c')

def test_link_with_a_static(self):
create_file('x.c', r'''
Expand Down

0 comments on commit fb4bdc7

Please sign in to comment.