blob: e7295b05148478ac61448f37c64cc6efca882fa5 [file] [log] [blame]
Diana Picus37126b82018-01-19 16:14:26 +01001"""Command line interface tests for llvm.py build.
2
3Note that although this uses the unittest framework, it does *not* contain unit
4tests.
5
6"""
7import os
8
9from shutil import rmtree
10from subprocess import CalledProcessError
11from tempfile import mkdtemp
12
Diana Picus9276b782018-01-24 14:40:46 +010013from llvmtestcase import LLVMTestCase, require_command_arg, debug
Diana Picus37126b82018-01-19 16:14:26 +010014
15
16def create_empty_file(path):
17 open(path, "wt").close()
18
19
20class 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
Diana Picus9276b782018-01-24 14:40:46 +010032 @require_command_arg("--build-dir")
Diana Picus37126b82018-01-19 16:14:26 +010033 def test_build_dir_is_compulsory(self):
34 """Test that we get an error if we don't pass the build dir."""
Diana Picus9276b782018-01-24 14:40:46 +010035 self.run_with_output(self.llvm_build())
Diana Picus37126b82018-01-19 16:14:26 +010036
37 def test_dry_run(self):
38 """
39 Test that we at least dump the expected command. It's difficult to check
40 whether we would actually run it correctly without depending too much on
41 external factors.
42 """
43 create_empty_file(os.path.join(self.buildDir, "build.ninja"))
44
45 output = self.run_with_output(
46 self.llvm_build(
47 "--dry-run",
48 "--build-dir",
49 self.buildDir,
50 "--build-flag=-j8",
51 "--build-flag",
52 "llc",
53 "--build-flag",
54 "llvm-mc"))
55
56 self.assertEqual(output,
57 "{}$ ninja -j8 llc llvm-mc\n".format(self.buildDir))