aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests/testllvmsourceconfig.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/testllvmsourceconfig.py')
-rw-r--r--tests/unittests/testllvmsourceconfig.py93
1 files changed, 84 insertions, 9 deletions
diff --git a/tests/unittests/testllvmsourceconfig.py b/tests/unittests/testllvmsourceconfig.py
index 8a60065..2c69fa3 100644
--- a/tests/unittests/testllvmsourceconfig.py
+++ b/tests/unittests/testllvmsourceconfig.py
@@ -576,7 +576,7 @@ class TestLLVMSourceConfig(unittest.TestCase):
logPath.assert_called_with(self.temporaryLLVM.repodir)
- subprojs = LLVMSubproject.get_all_subprojects()
+ subprojs = config.subprojs
enabled = ["clang", "compiler-rt", "lld", "lldb", "libunwind"]
calls = []
@@ -594,16 +594,12 @@ class TestLLVMSourceConfig(unittest.TestCase):
logPath.assert_has_calls(calls, any_order=True)
- def _throw(self, projPath):
- if "lld" in projPath:
- raise ValueError("An error has been!!1")
-
def test_for_each_enabled_error(self):
"""Test that we rethrow exceptions correctly."""
sourcePath = self.temporaryLLVM.repodir
config = LLVMSourceConfig(self.proj, sourcePath)
- subprojs = LLVMSubproject.get_all_subprojects()
+ subprojs = config.subprojs
enabled = ["clang", "compiler-rt", "lld", "lldb", "libunwind"]
for subproj in enabled:
@@ -614,12 +610,91 @@ class TestLLVMSourceConfig(unittest.TestCase):
path,
self.temporaryLLVMbranch)
+ def throw(projPath):
+ if "lld" in projPath:
+ raise ValueError("An error has been!!1")
+
with self.assertRaises(RuntimeError) as context:
- config.for_each_enabled(self._throw)
+ config.for_each_enabled(throw)
self.assertRegex(str(context.exception),
- "(.*\n?)*Error while processing lld(.*\n)*")
+ "Error while processing lld(.*\n)*")
self.assertRegex(str(context.exception.__cause__),
- "(.*\n?)*An error has been!!1(.*\n)*")
+ "An error has been!!1(.*\n)*")
+
+ def test_for_each_subproj(self):
+ sourcePath = self.temporaryLLVM.repodir
+
+ config = LLVMSourceConfig(self.proj, sourcePath)
+
+ subprojs = config.subprojs
+ enabled = ["clang", "compiler-rt", "lld", "lldb", "libunwind"]
+ calls = []
+
+ for subproj in enabled:
+ # Make sure subproj looks enabled
+ path = subprojs[subproj].get_cmake_path(sourcePath)
+ worktree = Worktree.create(
+ self.proj,
+ self.__get_subproj_repo(subproj),
+ path,
+ self.temporaryLLVMbranch)
+ # Expect our mock to be called with the proper subproj and
+ # enabled == True
+ calls.append(call(subprojs[subproj], True))
+
+ for subproj in set(subprojs.keys()) - set(enabled):
+ # Expect our mock to be called with the proper subproj and
+ # enabled == False
+ calls.append(call(subprojs[subproj], False))
+
+ try:
+ action = MagicMock()
+ config.for_each_subproj(action)
+ except:
+ print("Exception during test?! ")
+
+ action.assert_has_calls(calls, any_order=True)
+
+ def test_for_each_subproj_error(self):
+ """Test that we rethrow exceptions correctly."""
+ sourcePath = self.temporaryLLVM.repodir
+
+ config = LLVMSourceConfig(self.proj, sourcePath)
+ subprojs = config.subprojs
+ enabled = ["clang", "compiler-rt", "lld", "lldb", "libunwind"]
+
+ for subproj in enabled:
+ path = subprojs[subproj].get_cmake_path(sourcePath)
+ worktree = Worktree.create(
+ self.proj,
+ self.__get_subproj_repo(subproj),
+ path,
+ self.temporaryLLVMbranch)
+
+ def throw_enabled(subproj, enabled):
+ # Throw for one of the enabled projects (e.g. lld)
+ if "lld" in subproj.cmake_path:
+ raise ValueError("An error has been!!1")
+
+ def throw_disabled(subproj, enabled):
+ # Throw for one of the disabled projects (e.g. libcxx)
+ if "libcxx" in subproj.cmake_path:
+ raise ValueError("An error has been!!1")
+
+ with self.assertRaises(RuntimeError) as context:
+ config.for_each_subproj(throw_enabled)
+ self.assertRegex(str(context.exception),
+ "Error while processing lld(.*\n)*")
+ self.assertRegex(str(context.exception.__cause__),
+ "An error has been!!1(.*\n)*")
+
+ with self.assertRaises(RuntimeError) as context:
+ config.for_each_subproj(throw_disabled)
+ self.assertRegex(str(context.exception),
+ "Error while processing libcxx(.*\n)*")
+ self.assertRegex(str(context.exception.__cause__),
+ "An error has been!!1(.*\n)*")
+
if __name__ == "__main__":
unittest.main()