@@ -1584,11 +1584,11 @@ def test_export_in_a(self):
1584
1584
1585
1585
# Sanity check: exporting without a definition does not cause it to appear.
1586
1586
# Note: exporting main prevents emcc from warning that it generated no code.
1587
- run_process ([PYTHON , EMCC , 'main.c' , '-s' , ''' EXPORTED_FUNCTIONS=['_main', '%s']''' % full_export_name ])
1587
+ run_process ([PYTHON , EMCC , 'main.c' , '-s' , 'ERROR_ON_UNDEFINED_SYMBOLS=0' , '-s' , " EXPORTED_FUNCTIONS=['_main', '%s']" % full_export_name ])
1588
1588
self .assertFalse (self .is_exported_in_wasm (expect_export , 'a.out.wasm' ))
1589
1589
1590
1590
# Actual test: defining symbol in library and exporting it causes it to appear in the output.
1591
- run_process ([PYTHON , EMCC , 'main.c' , '-L.' , '-lexport' , '-s' , ''' EXPORTED_FUNCTIONS=['%s']''' % full_export_name ])
1591
+ run_process ([PYTHON , EMCC , 'main.c' , '-L.' , '-lexport' , '-s' , " EXPORTED_FUNCTIONS=['%s']" % full_export_name ])
1592
1592
self .assertTrue (self .is_exported_in_wasm (expect_export , 'a.out.wasm' ))
1593
1593
1594
1594
def test_embed_file (self ):
@@ -1840,6 +1840,20 @@ def test_link_memcpy(self):
1840
1840
''' , output )
1841
1841
self .assertNotContained ('warning: library.js memcpy should not be running, it is only for testing!' , output )
1842
1842
1843
+ def test_undefined_function (self ):
1844
+ cmd = [PYTHON , EMCC , path_from_root ('tests' , 'hello_world.cpp' )]
1845
+ run_process (cmd )
1846
+
1847
+ # adding a missing symbol to EXPORTED_FUNCTIONS should cause failure
1848
+ cmd += ['-s' , "EXPORTED_FUNCTIONS=['foobar']" ]
1849
+ proc = run_process (cmd , stderr = PIPE , check = False )
1850
+ self .assertNotEqual (proc .returncode , 0 )
1851
+ self .assertContained ('undefined exported function: "foobar"' , proc .stderr )
1852
+
1853
+ # setting ERROR_ON_UNDEFINED_SYMBOLS=0 suppresses error
1854
+ cmd += ['-s' , 'ERROR_ON_UNDEFINED_SYMBOLS=0' ]
1855
+ proc = run_process (cmd )
1856
+
1843
1857
def test_undefined_symbols (self ):
1844
1858
with open ('main.cpp' , 'w' ) as f :
1845
1859
f .write (r'''
@@ -3969,9 +3983,9 @@ def test_bad_export(self):
3969
3983
self .clear ()
3970
3984
cmd = [PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-s' , 'EXPORTED_FUNCTIONS=["' + m + '_main"]' ]
3971
3985
print (cmd )
3972
- stderr = run_process (cmd , stderr = PIPE ).stderr
3986
+ stderr = run_process (cmd , stderr = PIPE , check = False ).stderr
3973
3987
if m :
3974
- assert 'function requested to be exported, but not implemented : " _main"' in stderr , stderr
3988
+ self . assertContained ( 'undefined exported function : " _main"' , stderr )
3975
3989
else :
3976
3990
self .assertContained ('hello, world!' , run_js ('a.out.js' ))
3977
3991
@@ -8792,20 +8806,21 @@ def test_emcc_parsing(self):
8792
8806
# extra newline in response file - should be ignored
8793
8807
("EXPORTED_FUNCTIONS=@response" , '' ),
8794
8808
# stray slash
8795
- ("EXPORTED_FUNCTIONS=['_a', '_b', \\ '_c', '_d']" , '''function requested to be exported, but not implemented : "\\ \\ '_c'"''' ),
8809
+ ("EXPORTED_FUNCTIONS=['_a', '_b', \\ '_c', '_d']" , '''undefined exported function : "\\ \\ '_c'"''' ),
8796
8810
# stray slash
8797
- ("EXPORTED_FUNCTIONS=['_a', '_b',\ '_c', '_d']" , '''function requested to be exported, but not implemented : "\\ \\ '_c'"''' ),
8811
+ ("EXPORTED_FUNCTIONS=['_a', '_b',\ '_c', '_d']" , '''undefined exported function : "\\ \\ '_c'"''' ),
8798
8812
# stray slash
8799
- ('EXPORTED_FUNCTIONS=["_a", "_b", \\ "_c", "_d"]' , 'function requested to be exported, but not implemented : "\\ \\ "_c""' ),
8813
+ ('EXPORTED_FUNCTIONS=["_a", "_b", \\ "_c", "_d"]' , 'undefined exported function : "\\ \\ "_c""' ),
8800
8814
# stray slash
8801
- ('EXPORTED_FUNCTIONS=["_a", "_b",\ "_c", "_d"]' , 'function requested to be exported, but not implemented : "\\ \\ "_c"' ),
8815
+ ('EXPORTED_FUNCTIONS=["_a", "_b",\ "_c", "_d"]' , 'undefined exported function : "\\ \\ "_c"' ),
8802
8816
# missing comma
8803
- ('EXPORTED_FUNCTIONS=["_a", "_b" "_c", "_d"]' , 'function requested to be exported, but not implemented : "_b" "_c"' ),
8817
+ ('EXPORTED_FUNCTIONS=["_a", "_b" "_c", "_d"]' , 'undefined exported function : "_b" "_c"' ),
8804
8818
]:
8805
8819
print (export_arg )
8806
- err = run_process ([PYTHON , EMCC , 'src.c' , '-s' , export_arg ], stdout = PIPE , stderr = PIPE ). stderr
8807
- print (err )
8820
+ proc = run_process ([PYTHON , EMCC , 'src.c' , '-s' , export_arg ], stdout = PIPE , stderr = PIPE , check = not expected )
8821
+ print (proc . stderr )
8808
8822
if not expected :
8809
- assert not err
8823
+ assert not proc . stderr
8810
8824
else :
8811
- self .assertContained (expected , err )
8825
+ self .assertNotEqual (proc .returncode , 0 )
8826
+ self .assertContained (expected , proc .stderr )
0 commit comments