Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 1 | """Command line interface tests for llvm.py build. |
| 2 | |
| 3 | Note that although this uses the unittest framework, it does *not* contain unit |
| 4 | tests. |
| 5 | |
| 6 | """ |
| 7 | import os |
| 8 | |
| 9 | from shutil import rmtree |
| 10 | from subprocess import CalledProcessError |
| 11 | from tempfile import mkdtemp |
| 12 | |
| 13 | from llvmtestcase import LLVMTestCase, debug |
| 14 | |
| 15 | |
| 16 | def create_empty_file(path): |
| 17 | open(path, "wt").close() |
| 18 | |
| 19 | |
| 20 | class Testllvmbuild(LLVMTestCase): |
| 21 | |
| 22 | @classmethod |
| 23 | def llvm_build(cls, *args, **kwargs): |
| 24 | return cls.command_with_defaults("build", *args, **kwargs) |
| 25 | |
| 26 | def setUp(self): |
| 27 | self.buildDir = mkdtemp() |
| 28 | |
| 29 | def tearDown(self): |
| 30 | rmtree(self.buildDir) |
| 31 | |
| 32 | def test_build_dir_is_compulsory(self): |
| 33 | """Test that we get an error if we don't pass the build dir.""" |
| 34 | with self.assertRaises(CalledProcessError) as context: |
| 35 | self.run_with_output(self.llvm_build()) |
| 36 | |
| 37 | self.assertRegex( |
| 38 | str(context.exception.output), |
| 39 | "(.*\n)*the following arguments are required: --build-dir(.*\n)*") |
| 40 | |
| 41 | def test_dry_run(self): |
| 42 | """ |
| 43 | Test that we at least dump the expected command. It's difficult to check |
| 44 | whether we would actually run it correctly without depending too much on |
| 45 | external factors. |
| 46 | """ |
| 47 | create_empty_file(os.path.join(self.buildDir, "build.ninja")) |
| 48 | |
| 49 | output = self.run_with_output( |
| 50 | self.llvm_build( |
| 51 | "--dry-run", |
| 52 | "--build-dir", |
| 53 | self.buildDir, |
| 54 | "--build-flag=-j8", |
| 55 | "--build-flag", |
| 56 | "llc", |
| 57 | "--build-flag", |
| 58 | "llvm-mc")) |
| 59 | |
| 60 | self.assertEqual(output, |
| 61 | "{}$ ninja -j8 llc llvm-mc\n".format(self.buildDir)) |