blob: c0ddcaab13093d828026152baceb91e80ea582f5 [file] [log] [blame]
"""Command line interface tests for llvm.py build.
Note that although this uses the unittest framework, it does *not* contain unit
tests.
"""
import os
from shutil import rmtree
from tempfile import mkdtemp
from llvmtestcase import LLVMTestCase, require_command_arg, debug
def create_empty_file(path):
open(path, "wt").close()
class Testllvmbuild(LLVMTestCase):
@classmethod
def llvm_build(cls, *args, **kwargs):
return cls.command_with_defaults("build", *args, **kwargs)
def setUp(self):
self.buildDir = mkdtemp()
def tearDown(self):
rmtree(self.buildDir)
@require_command_arg("--build-dir")
def test_build_dir_is_compulsory(self):
"""Test that we get an error if we don't pass the build dir."""
self.run_with_output(self.llvm_build())
def test_dry_run(self):
"""
Test that we at least dump the expected command. It's difficult to check
whether we would actually run it correctly without depending too much on
external factors.
"""
create_empty_file(os.path.join(self.buildDir, "build.ninja"))
output = self.run_with_output(
self.llvm_build(
"--dry-run",
"--build-dir",
self.buildDir,
"--build-flag=-j8",
"--build-flag",
"llc",
"--build-flag",
"llvm-mc"))
self.assertEqual(output,
"{}$ ninja -j8 llc llvm-mc\n".format(self.buildDir))