Skip to content

Commit

Permalink
Fix test_utf32. NFC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Oct 8, 2024
1 parent 2be0e88 commit 3a8ffc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5680,8 +5680,11 @@ def test_utf(self):
self.do_core_test('test_utf.c')

def test_utf32(self):
self.do_runf('utf32.cpp', 'OK.')
self.do_runf('utf32.cpp', 'OK.', args=['-fshort-wchar'])
self.do_runf('utf32.cpp', 'OK (long).\n')

@no_sanitize('requires libc to be built with -fshort-char')
def test_utf32_short_wchar(self):
self.do_runf('utf32.cpp', 'OK (short).\n', emcc_args=['-fshort-wchar'])

@crossplatform
def test_utf16(self):
Expand Down
6 changes: 4 additions & 2 deletions test/utf32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
typedef unsigned int utf32;
typedef unsigned short utf16;

EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32");
EM_JS_DEPS(deps, "$UTF32ToString,$stringToUTF32,$UTF16ToString,$stringToUTF16");

// This code tests that Unicode std::wstrings can be marshalled between C++ and JS.
int main() {
Expand Down Expand Up @@ -51,7 +51,9 @@ int main() {
assert(memory[5] == 0);

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

Expand Down Expand Up @@ -80,7 +82,7 @@ int main() {
assert(memory[5] == 0);

delete[] memory;
printf("OK (short).\n");
}

printf("OK.\n");
}

0 comments on commit 3a8ffc5

Please sign in to comment.