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 |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 10 | from tempfile import mkdtemp |
| 11 | |
Diana Picus | 9276b78 | 2018-01-24 14:40:46 +0100 | [diff] [blame] | 12 | from llvmtestcase import LLVMTestCase, require_command_arg, debug |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 13 | |
| 14 | |
| 15 | def create_empty_file(path): |
| 16 | open(path, "wt").close() |
| 17 | |
| 18 | |
| 19 | class Testllvmbuild(LLVMTestCase): |
| 20 | |
| 21 | @classmethod |
| 22 | def llvm_build(cls, *args, **kwargs): |
| 23 | return cls.command_with_defaults("build", *args, **kwargs) |
| 24 | |
| 25 | def setUp(self): |
| 26 | self.buildDir = mkdtemp() |
| 27 | |
| 28 | def tearDown(self): |
| 29 | rmtree(self.buildDir) |
| 30 | |
Diana Picus | 9276b78 | 2018-01-24 14:40:46 +0100 | [diff] [blame] | 31 | @require_command_arg("--build-dir") |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 32 | def test_build_dir_is_compulsory(self): |
| 33 | """Test that we get an error if we don't pass the build dir.""" |
Diana Picus | 9276b78 | 2018-01-24 14:40:46 +0100 | [diff] [blame] | 34 | self.run_with_output(self.llvm_build()) |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 35 | |
| 36 | def test_dry_run(self): |
| 37 | """ |
| 38 | Test that we at least dump the expected command. It's difficult to check |
| 39 | whether we would actually run it correctly without depending too much on |
| 40 | external factors. |
| 41 | """ |
| 42 | create_empty_file(os.path.join(self.buildDir, "build.ninja")) |
| 43 | |
| 44 | output = self.run_with_output( |
| 45 | self.llvm_build( |
| 46 | "--dry-run", |
| 47 | "--build-dir", |
| 48 | self.buildDir, |
| 49 | "--build-flag=-j8", |
| 50 | "--build-flag", |
| 51 | "llc", |
| 52 | "--build-flag", |
| 53 | "llvm-mc")) |
| 54 | |
| 55 | self.assertEqual(output, |
| 56 | "{}$ ninja -j8 llc llvm-mc\n".format(self.buildDir)) |