Skip to content

Commit

Permalink
test: add wasi test for freopen()
Browse files Browse the repository at this point in the history
This test provides missing coverage for __wasi_fd_renumber().

PR-URL: nodejs#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>
  • Loading branch information
cjihrig authored and Trott committed Jan 23, 2020
1 parent 30173c6 commit 96058f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/fixtures/wasi/input2.txt
@@ -0,0 +1 @@
hello from input2.txt
16 changes: 16 additions & 0 deletions test/wasi/c/freopen.c
@@ -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);
}
}
1 change: 1 addition & 0 deletions test/wasi/test-wasi.js
Expand Up @@ -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' });
Expand Down
Binary file added test/wasi/wasm/freopen.wasm
Binary file not shown.

0 comments on commit 96058f3

Please sign in to comment.