Skip to content

Commit 765184a

Browse files
authored
Add some basic tests for C++ module support. NFC (#23542)
1 parent 209b704 commit 765184a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/test_other.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15498,3 +15498,40 @@ def test_create_cache_directory(self):
1549815498
with env_modify({'EM_CACHE': os.path.abspath('rodir/foo')}):
1549915499
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
1550015500
self.assertContained('emcc: error: unable to create cache directory', err)
15501+
15502+
def test_cxx20_modules(self):
15503+
# Test basic use of modules by user code
15504+
create_file('Hello.cppm', r'''
15505+
module;
15506+
#include <iostream>
15507+
export module Hello;
15508+
export void hello() {
15509+
std::cout << "Hello Module!\n";
15510+
}
15511+
''')
15512+
15513+
create_file('main.cpp', '''
15514+
import Hello;
15515+
int main() {
15516+
hello();
15517+
return 0;
15518+
}
15519+
''')
15520+
15521+
self.run_process([EMXX, '-std=c++20', 'Hello.cppm', '--precompile', '-o', 'Hello.pcm'])
15522+
# Use explict `-fmodule-file=`
15523+
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodule-file=Hello=Hello.pcm', 'Hello.pcm'])
15524+
# Same again but with `-fprebuilt-module-path=`
15525+
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fprebuilt-module-path=.', 'Hello.pcm'])
15526+
15527+
def test_cxx20_modules_std_headers(self):
15528+
# Test import <header_name> usage
15529+
create_file('main.cpp', r'''
15530+
import <iostream>;
15531+
15532+
int main() {
15533+
std::cout << "Hello Module!\n";
15534+
return 0;
15535+
}
15536+
''')
15537+
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodules'])

0 commit comments

Comments
 (0)