blob: c0ddcaab13093d828026152baceb91e80ea582f5 [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
Diana Picus37126b82018-01-19 16:14:26 +010010from tempfile import mkdtemp
11
Diana Picus9276b782018-01-24 14:40:46 +010012from llvmtestcase import LLVMTestCase, require_command_arg, debug
Diana Picus37126b82018-01-19 16:14:26 +010013
14
15def create_empty_file(path):
16 open(path, "wt").close()
17
18
19class 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 Picus9276b782018-01-24 14:40:46 +010031 @require_command_arg("--build-dir")
Diana Picus37126b82018-01-19 16:14:26 +010032 def test_build_dir_is_compulsory(self):
33 """Test that we get an error if we don't pass the build dir."""
Diana Picus9276b782018-01-24 14:40:46 +010034 self.run_with_output(self.llvm_build())
Diana Picus37126b82018-01-19 16:14:26 +010035
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))