diff --git a/modules/algebra/test/expensive_test_vectord_mismatch.py b/modules/algebra/test/expensive_test_vectord_mismatch.py index fade7d72d9..a55939cf60 100644 --- a/modules/algebra/test/expensive_test_vectord_mismatch.py +++ b/modules/algebra/test/expensive_test_vectord_mismatch.py @@ -7,7 +7,7 @@ def test_vectord_mismatch(self): """Test combination of VectorD of different dimensions""" # Should be a compile-time error to combine VectorD of different sizes self.assertCompileFails( - includes=['IMP/algebra/VectorD.h'], + headers=['IMP/algebra/VectorD.h'], body=""" IMP::algebra::Vector3D v1(1,2,3); IMP::algebra::Vector4D v3(7,8,9,10); diff --git a/modules/kernel/test/expensive_test_get_array.py b/modules/kernel/test/expensive_test_get_array.py index 99d2b72f3c..089c20657a 100644 --- a/modules/kernel/test/expensive_test_get_array.py +++ b/modules/kernel/test/expensive_test_get_array.py @@ -7,7 +7,7 @@ def test_get_array(self): """Test std::get""" # Should be a compile-time error to access an out of range element self.assertCompileFails( - includes=['IMP/base_types.h'], + headers=['IMP/base_types.h'], body=""" IMP::ParticleIndexPair pp(IMP::ParticleIndex(1), IMP::ParticleIndex(3)); IMP::ParticleIndex p = std::get<2>(pp);""") diff --git a/modules/test/pyext/src/__init__.py b/modules/test/pyext/src/__init__.py index 4cbe9f0e4e..b4b281d028 100644 --- a/modules/test/pyext/src/__init__.py +++ b/modules/test/pyext/src/__init__.py @@ -320,31 +320,42 @@ def assertSequenceAlmostEqual(self, first, second, places=None, msg=None, def _read_cmake_cache(self, cmake_cache): """Parse CMakeCache and extract info on the C++ compiler""" - cxx = flags = None + cxx = flags = sysroot = None + includes = [] with open(cmake_cache) as fh: for line in fh: if line.startswith('CMAKE_CXX_COMPILER:'): - cxx = line.split('=', 1)[1].rstrip('\r\n') + cxx = line.split('=', 1)[1].strip() elif line.startswith('CMAKE_CXX_FLAGS:'): - flags = line.split('=', 1)[1].rstrip('\r\n') - return cxx, flags - - def assertCompileFails(self, includes, body): + flags = line.split('=', 1)[1].strip() + elif line.startswith('CMAKE_OSX_SYSROOT:'): + sysroot = line.split('=', 1)[1].strip() + elif line.startswith('Boost_INCLUDE_DIR:'): + includes.append(line.split('=', 1)[1].strip()) + elif line.startswith('EIGEN3_INCLUDE_DIR:'): + includes.append(line.split('=', 1)[1].strip()) + return cxx, flags, includes, sysroot + + def assertCompileFails(self, headers, body): """Test that the given C++ code fails to compile with a static assertion.""" libdir = os.path.dirname(IMP.__file__) cmake_cache = os.path.join(libdir, '..', '..', 'CMakeCache.txt') - include = os.path.join(libdir, '..', '..', 'include') if not os.path.exists(cmake_cache): self.skipTest("cannot find CMakeCache.txt") - cxx, flags = self._read_cmake_cache(cmake_cache) + cxx, flags, includes, sysroot = self._read_cmake_cache(cmake_cache) + # On Mac we need to point to the SDK + if sys.platform == 'darwin' and sysroot: + flags = flags + " -isysroot" + sysroot + includes.append(os.path.join(libdir, '..', '..', 'include')) + include = " ".join("-I" + inc for inc in includes) with temporary_directory() as tmpdir: fname = os.path.join(tmpdir, 'test.cpp') with open(fname, 'w') as fh: - for inc in includes: - fh.write("#include <%s>\n" % inc) + for h in headers: + fh.write("#include <%s>\n" % h) fh.write("\nint main() {\n" + body + "\n return 0;\n}\n") - cmdline = "%s %s -I%s %s" % (cxx, flags, include, fname) + cmdline = "%s %s %s %s" % (cxx, flags, include, fname) print(cmdline) p = subprocess.Popen(cmdline, shell=True, stdout=subprocess.PIPE,