mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
test: add wasi test for symlink() and readlink()
This test provides missing coverage for __wasi_path_symlink() and __wasi_path_readlink(). PR-URL: https://github.com/nodejs/node/pull/31403 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
7d5a86cc05
commit
4f11fb6410
26
test/wasi/c/create_symlink.c
Normal file
26
test/wasi/c/create_symlink.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
const char* target = "./input.txt";
|
||||
const char* linkpath = "/sandbox/subdir/test_link";
|
||||
char readlink_result[128];
|
||||
size_t result_size = sizeof(readlink_result);
|
||||
|
||||
assert(0 == symlink(target, linkpath));
|
||||
assert(readlink(linkpath, readlink_result, result_size) ==
|
||||
strlen(target) + 1);
|
||||
assert(0 == strcmp(readlink_result, target));
|
||||
|
||||
FILE* file = fopen(linkpath, "r");
|
||||
assert(file != NULL);
|
||||
|
||||
int c = fgetc(file);
|
||||
while (c != EOF) {
|
||||
int wrote = fputc(c, stdout);
|
||||
assert(wrote != EOF);
|
||||
c = fgetc(file);
|
||||
}
|
||||
}
|
@ -74,6 +74,7 @@ if (process.argv[2] === 'wasi-child') {
|
||||
assert.strictEqual(child.stdout.toString(), options.stdout || '');
|
||||
}
|
||||
|
||||
runWASI({ test: 'create_symlink', stdout: 'hello from input.txt' });
|
||||
runWASI({ test: 'follow_symlink', stdout: 'hello from input.txt' });
|
||||
runWASI({ test: 'symlink_escape' });
|
||||
runWASI({ test: 'symlink_loop' });
|
||||
|
BIN
test/wasi/wasm/create_symlink.wasm
Executable file
BIN
test/wasi/wasm/create_symlink.wasm
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user