1"""Test cases that run tests as subprocesses.""" 2 3from typing import List 4 5import os 6import subprocess 7import sys 8import unittest 9 10 11base_dir = os.path.join(os.path.dirname(__file__), '..', '..') 12 13 14class TestExternal(unittest.TestCase): 15 # TODO: Get this to work on Windows. 16 # (Or don't. It is probably not a good use of time.) 17 @unittest.skipIf(sys.platform.startswith("win"), "rt tests don't work on windows") 18 def test_c_unit_test(self) -> None: 19 """Run C unit tests in a subprocess.""" 20 # Build Google Test, the C++ framework we use for testing C code. 21 # The source code for Google Test is copied to this repository. 22 cppflags = [] # type: List[str] 23 env = os.environ.copy() 24 if sys.platform == 'darwin': 25 cppflags += ['-mmacosx-version-min=10.10', '-stdlib=libc++'] 26 env['CPPFLAGS'] = ' '.join(cppflags) 27 subprocess.check_call( 28 ['make', 'libgtest.a'], 29 env=env, 30 cwd=os.path.join(base_dir, 'mypyc', 'external', 'googletest', 'make')) 31 # Build Python wrapper for C unit tests. 32 env = os.environ.copy() 33 env['CPPFLAGS'] = ' '.join(cppflags) 34 status = subprocess.check_call( 35 [sys.executable, 'setup.py', 'build_ext', '--inplace'], 36 env=env, 37 cwd=os.path.join(base_dir, 'mypyc', 'lib-rt')) 38 # Run C unit tests. 39 env = os.environ.copy() 40 if 'GTEST_COLOR' not in os.environ: 41 env['GTEST_COLOR'] = 'yes' # Use fancy colors 42 status = subprocess.call([sys.executable, '-c', 43 'import sys, test_capi; sys.exit(test_capi.run_tests())'], 44 env=env, 45 cwd=os.path.join(base_dir, 'mypyc', 'lib-rt')) 46 if status != 0: 47 raise AssertionError("make test: C unit test failure") 48