mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
test: add wasi test for freopen()
This test provides missing coverage for __wasi_fd_renumber(). PR-URL: https://github.com/nodejs/node/pull/31432 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
parent
30173c6087
commit
96058f33a9
4 changed files with 18 additions and 0 deletions
1
test/fixtures/wasi/input2.txt
vendored
Normal file
1
test/fixtures/wasi/input2.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
hello from input2.txt
|
16
test/wasi/c/freopen.c
Normal file
16
test/wasi/c/freopen.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
FILE* file_orig = fopen("/sandbox/input.txt", "r");
|
||||
assert(file_orig != NULL);
|
||||
FILE* file_new = freopen("/sandbox/input2.txt", "r", file_orig);
|
||||
assert(file_new != NULL);
|
||||
|
||||
int c = fgetc(file_new);
|
||||
while (c != EOF) {
|
||||
int wrote = fputc((char)c, stdout);
|
||||
assert(wrote != EOF);
|
||||
c = fgetc(file_new);
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@ if (process.argv[2] === 'wasi-child') {
|
|||
runWASI({ test: 'clock_getres' });
|
||||
runWASI({ test: 'exitcode', exitCode: 120 });
|
||||
runWASI({ test: 'fd_prestat_get_refresh' });
|
||||
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
|
||||
runWASI({ test: 'getentropy' });
|
||||
runWASI({ test: 'getrusage' });
|
||||
runWASI({ test: 'gettimeofday' });
|
||||
|
|
BIN
test/wasi/wasm/freopen.wasm
Executable file
BIN
test/wasi/wasm/freopen.wasm
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue