Skip to content

Commit fcb5161

Browse files
authored
Fix test_utf32. NFC (#22698)
This test was never actually being run with `-fshort-wchar` because it was being passed as `args` rather than `emcc_args`, ever since the test was added back in c33af78. When actually running with `-fshort-wchar` the test fails under the sanitizers I believe because wcslen (which is part of libc) would also need to be built with this flag.
1 parent 9eb7763 commit fcb5161

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

test/test_core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,8 +5680,11 @@ def test_utf(self):
56805680
self.do_core_test('test_utf.c')
56815681

56825682
def test_utf32(self):
5683-
self.do_runf('utf32.cpp', 'OK.')
5684-
self.do_runf('utf32.cpp', 'OK.', args=['-fshort-wchar'])
5683+
self.do_runf('utf32.cpp', 'OK (long).\n')
5684+
5685+
@no_sanitize('requires libc to be built with -fshort-char')
5686+
def test_utf32_short_wchar(self):
5687+
self.do_runf('utf32.cpp', 'OK (short).\n', emcc_args=['-fshort-wchar'])
56855688

56865689
@crossplatform
56875690
def test_utf16(self):

test/utf32.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
typedef unsigned int utf32;
1313
typedef unsigned short utf16;
1414

15-
EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32");
15+
EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32,$UTF16ToString,$stringToUTF16");
1616

1717
// This code tests that Unicode std::wstrings can be marshalled between C++ and JS.
1818
int main() {
@@ -51,14 +51,16 @@ int main() {
5151
assert(memory[5] == 0);
5252

5353
delete[] memory;
54+
printf("OK (long).\n");
5455
} else {
56+
assert(sizeof(wchar_t) == 2);
5557
// sizeof(wchar_t) == 2, and we're building with -fshort-wchar.
5658
utf16 *memory = new utf16[2*wstr.length()+1];
5759

5860
EM_ASM({
5961
var str = UTF16ToString($0);
6062
out(str);
61-
var numBytesWritten = stringToUTF16(str, $1, $2);
63+
var numBytesWritten = stringToUTF16(str, $1, Number($2));
6264
if (numBytesWritten != 25*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten;
6365
}, wstr.c_str(), memory, (2*wstr.length()+1)*sizeof(utf16));
6466

@@ -74,13 +76,13 @@ int main() {
7476
EM_ASM({
7577
var str = UTF16ToString($0);
7678
out(str);
77-
var numBytesWritten = stringToUTF16(str, $1, $2);
79+
var numBytesWritten = stringToUTF16(str, $1, Number($2));
7880
if (numBytesWritten != 5*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten;
7981
}, wstr.c_str(), memory, 6*sizeof(utf16));
8082
assert(memory[5] == 0);
8183

8284
delete[] memory;
85+
printf("OK (short).\n");
8386
}
8487

85-
printf("OK.\n");
8688
}

0 commit comments

Comments
 (0)