Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert test_stat_fail_alongtheway to a file based test #21138

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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