Skip to content

Commit f772205

Browse files
authored
Cleanup test_fs_write. NFC (#24701)
- Rename test (test_write.cpp is very generic and test_fs_write matches the name of the test) - Convert to C - Format code
1 parent 404cce8 commit f772205

File tree

4 files changed

+48
-50
lines changed

4 files changed

+48
-50
lines changed

test/fs/test_fs_write.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2016 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
// https://github.com/emscripten-core/emscripten/pull/4705: Test that FS.write() with canOwn=true works.
7+
8+
#include <stdio.h>
9+
10+
#include <emscripten/emscripten.h>
11+
12+
int main() {
13+
EM_ASM(
14+
var stream = FS.open('testfile', 'w+');
15+
16+
var data = new Uint8Array(128);
17+
var str = "Hello! ";
18+
stringToUTF8Array(str, data, 0, lengthBytesUTF8(str)+1);
19+
data = data.subarray(0, lengthBytesUTF8(str));
20+
FS.write(stream, data, 0, lengthBytesUTF8(str), 0, /*canOwn=*/true);
21+
var pos = lengthBytesUTF8(str);
22+
23+
str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';
24+
data = new Uint8Array(str.length+1);
25+
stringToUTF8Array(str, data, 0, lengthBytesUTF8(str)+1);
26+
FS.write(stream, data, 0, lengthBytesUTF8(str)+1, pos, /*canOwn=*/false);
27+
28+
FS.close(stream);
29+
30+
var ex;
31+
try {
32+
FS.write(stream, data, 0, lengthBytesUTF8(str)+1, pos, /*canOwn=*/false);
33+
} catch (err) {
34+
ex = err;
35+
}
36+
assert(ex.name === 'ErrnoError' && ex.errno === 8 /* EBADF */)
37+
);
38+
39+
FILE* file = fopen("testfile", "r");
40+
char* line = NULL;
41+
size_t n;
42+
getline(&line, &n, file);
43+
printf("read %s\n", line);
44+
45+
return 0;
46+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
read Hello! 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1+
read Hello! 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

test/fs/test_write.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5905,7 +5905,7 @@ def test_fs_js_api(self):
59055905
def test_fs_write(self):
59065906
if self.get_setting('WASMFS'):
59075907
self.set_setting("FORCE_FILESYSTEM")
5908-
self.do_run_in_out_file_test('fs/test_write.cpp')
5908+
self.do_run_in_out_file_test('fs/test_fs_write.c')
59095909

59105910
@also_with_noderawfs
59115911
def test_fs_emptyPath(self):

0 commit comments

Comments
 (0)