Skip to content

Commit 5282183

Browse files
committed
test js built w/ extra POSIX compliant linking syntax
also refactored `other.test_l_link`.
1 parent aa3c1b7 commit 5282183

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

tests/test_other.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,12 @@ def test(args, expected, moar_expected=None):
631631
test(['-O1', '-s', 'EMULATE_FUNCTION_POINTER_CASTS=1'], '''my func\n''') # emulate so it works
632632

633633
def test_l_link(self):
634-
# Linking with -lLIBNAME and -L/DIRNAME should work
634+
# Linking with -lLIBNAME and -L/DIRNAME should work, also should work with spaces
635635

636-
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write('''
636+
def build(path, args):
637+
check_execute([PYTHON, EMCC, self.in_dir(*path)] + args)
638+
639+
open(self.in_dir('main.cpp'), 'w').write('''
637640
extern void printey();
638641
int main() {
639642
printey();
@@ -642,21 +645,35 @@ def test_l_link(self):
642645
''')
643646

644647
try:
645-
os.makedirs(os.path.join(self.get_dir(), 'libdir'));
648+
os.makedirs(self.in_dir('libdir'))
646649
except:
647650
pass
648651

649-
open(os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), 'w').write('''
652+
open(self.in_dir('libdir', 'libfile.cpp'), 'w').write('''
650653
#include <stdio.h>
651654
void printey() {
652655
printf("hello from lib\\n");
653656
}
654657
''')
655658

656-
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), '-c']).communicate()
657-
shutil.move(os.path.join(self.get_dir(), 'libfile.o'), os.path.join(self.get_dir(), 'libdir', 'libfile.so'))
658-
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile']).communicate()
659-
self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js')))
659+
libfile = self.in_dir('libdir', 'libfile.so')
660+
aout = self.in_dir('a.out.js')
661+
662+
# Test linking the library built here by emcc
663+
build(['libdir', 'libfile.cpp'], ['-c'])
664+
shutil.move(self.in_dir('libfile.o'), libfile)
665+
build(['main.cpp'], ['-L' + self.in_dir('libdir'), '-lfile'])
666+
667+
self.assertContained('hello from lib', run_js(aout))
668+
669+
# Also test execution with `-l c` and space-separated library linking syntax
670+
os.remove(aout)
671+
build(['libdir', 'libfile.cpp'], ['-c', '-l', 'c'])
672+
shutil.move(self.in_dir('libfile.o'), libfile)
673+
build(['main.cpp'], ['-L', self.in_dir('libdir'), '-l', 'file'])
674+
675+
self.assertContained('hello from lib', run_js(aout))
676+
660677
assert not os.path.exists('a.out') and not os.path.exists('a.exe'), 'Must not leave unneeded linker stubs'
661678

662679
def test_outline(self):

0 commit comments

Comments
 (0)