diff options
-rw-r--r-- | tests/cli/testllvmconfigure.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/cli/testllvmconfigure.py b/tests/cli/testllvmconfigure.py new file mode 100644 index 0000000..fd68bde --- /dev/null +++ b/tests/cli/testllvmconfigure.py @@ -0,0 +1,92 @@ +"""Command line interface tests for llvm.py configure. + +Note that although this uses the unittest framework, it does *not* contain unit +tests. + +""" +from os import path +from subprocess import CalledProcessError +from tempfile import mkdtemp +from uuid import uuid4 + +from llvmtestcase import LLVMTestCase, debug + +class Testllvmconfigure(LLVMTestCase): + + @classmethod + def llvm_configure(cls, *args, **kwargs): + return cls.command_with_defaults("configure", *args, **kwargs) + + @classmethod + def setUpClass(cls): + cls.env = mkdtemp() + + cls.llvm_repo = path.join(cls.env, "llvm-repo") + cls.create_dummy_repo(cls.llvm_repo) + + cls.llvm_worktree = path.join(cls.env, "llvm") + cls.add_worktree(cls.llvm_repo, cls.llvm_worktree, "br") + + def test_build_dir_is_compulsory(self): + """Test that we get an error if we don't pass the build dir.""" + with self.assertRaises(CalledProcessError) as context: + self.run_with_output(self.llvm_configure()) + + self.assertRegex( + str(context.exception.output), + "(.*\n)*the following arguments are required: --build-dir(.*\n)*") + + def test_default_args(self): + """Test that we can get a simple configure command.""" + output = self.run_with_output(self.llvm_configure("--dry-run", + "--build-dir", + "anywhere")) + self.assertRegex(output, + "anywhere\$ cmake -G Ninja .* {}".format(self.llvm_worktree)) + + def test_generator(self): + """Test that we can specify a custom generator.""" + output = self.run_with_output(self.llvm_configure("--dry-run", + "--build-dir", + "anywhere", + "--cmake-generator", + "\"Unix Makefiles\"")) + self.assertRegex(output, + "anywhere\$ cmake -G \"Unix Makefiles\" .* {}".format(self.llvm_worktree)) + + def test_cmake_vars(self): + """Test that we can specify custom cmake variables.""" + output = self.run_with_output(self.llvm_configure( + "--dry-run", + "--build-dir", "anywhere", + "--cmake-def", "VAR1=VAL1", + "--cmake-def", "VAR2=\"-not --so simple\"")) + + self.assertRegex(output, + "anywhere\$ cmake -G Ninja .* -DVAR1=VAL1 -DVAR2=\"-not --so simple\" {}".format(self.llvm_worktree)) + + def test_create_build_dir(self): + """ + Test that we create the build directory if it doesn't already exist (but + not in dry-run). + """ + buildDir = path.join(self.env, "brand-new-build-dir") + self.assertFalse(path.isdir(buildDir)) + + self.run_with_output(self.llvm_configure("--dry-run", + "--build-dir", buildDir)) + self.assertFalse(path.isdir(buildDir)) + + # When not running in dry run mode, we're going to try to execute a + # CMake command that's going to fail because we don't have a valid LLVM + # source directory. This is fine, since the purpose of this test isn't + # to check the integration with CMake. + with self.assertRaises(Exception) as context: + print(self.run_with_output(self.llvm_configure("--build-dir", + buildDir))) + + self.assertRegex( + str(context.exception.output), + "(.*\n)*The source directory .* does not appear to contain CMakeLists.txt(.*\n)*") + + self.assertTrue(path.isdir(buildDir)) |