aboutsummaryrefslogtreecommitdiff
path: root/tests/cli
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cli')
-rw-r--r--tests/cli/testllvmprojects.py321
1 files changed, 223 insertions, 98 deletions
diff --git a/tests/cli/testllvmprojects.py b/tests/cli/testllvmprojects.py
index 8374aff..c0c1f26 100644
--- a/tests/cli/testllvmprojects.py
+++ b/tests/cli/testllvmprojects.py
@@ -81,6 +81,36 @@ class Testllvmprojs(unittest.TestCase):
return subprocess.check_call(*args, **kwargs)
@classmethod
+ def llvm_projects(cls, *args, **kwargs):
+ """
+ Build a list representing a llvm projects subcommand with the given
+ args. Unless otherwise specified in kwargs, this uses the values for
+ repos and env that it finds in cls.
+ """
+ command = [cls.python, cls.script]
+
+ repos = cls.repos
+ if "repos" in kwargs:
+ repos = kwargs["repos"]
+ if repos:
+ command.append("--repos")
+ command.append(repos)
+
+ env = cls.env
+ if "env" in kwargs:
+ env = kwargs["env"]
+ if env:
+ command.append("--env")
+ command.append(env)
+
+ command.append("projects")
+
+ if len(args):
+ command.extend(args)
+
+ return command
+
+ @classmethod
def setUpClass(cls):
"""Create the file structure and environment that llvmprojs expects"""
cls.llvm_root = mkdtemp()
@@ -99,17 +129,14 @@ class Testllvmprojs(unittest.TestCase):
@classmethod
def setUp(cls):
- cls.env = "src" + str(uuid4())
- cls.llvm_src = os.path.join(cls.llvm_root, cls.env, "llvm")
+ cls.env = os.path.join(cls.llvm_root, "env" + str(uuid4()))
+ cls.llvm_src = os.path.join(cls.env, "llvm")
# Create LLVM worktree
cls.branch = "br" + str(uuid4())
cls.__add_worktree(cls.__get_subproj_repo("llvm"), cls.llvm_src,
cls.branch)
- # Set up the environment variables
- os.environ["LLVM_ROOT"] = cls.llvm_root
-
@classmethod
def tearDown(cls):
# Clean up the directories where we might have added subprojects.
@@ -128,25 +155,86 @@ class Testllvmprojs(unittest.TestCase):
with cd(repopath):
cls.run_quietly(["git", "worktree", "prune"])
+ def test_repos_arg_is_compulsory(self):
+ """
+ Test that we must pass in the repos for various combinations of input
+ args.
+ """
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(self.llvm_projects(repos=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--repos(.*\n)*")
+
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(
+ self.llvm_projects(
+ "--add", "clang", repos=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--repos(.*\n)*")
+
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(
+ self.llvm_projects(
+ "--remove",
+ "clang",
+ repos=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--repos(.*\n)*")
+
+ def test_env_arg_is_compulsory(self):
+ """
+ Test that we must pass in the environment for various combinations of
+ input args.
+ """
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(self.llvm_projects(env=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(
+ self.llvm_projects(
+ "--add", "clang", env=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+
+ with self.assertRaises(subprocess.CalledProcessError) as context:
+ self.run_with_output(
+ self.llvm_projects(
+ "--remove", "clang", env=None))
+
+ self.assertRegex(
+ str(context.exception.output),
+ "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+
def test_dump_empty_config(self):
"""
Test that we're correctly dumping an empty configuration (i.e. no
projects linked) when running llvmprojs without arguments.
"""
- output = self.run_with_output(
- [self.python, self.script, self.env, "projects"])
+ output = self.run_with_output(self.llvm_projects())
self.assertRegex(output, "Projects linked:.*\n.*none.*")
def test_add_remove_subprojects(self):
"""
Test that we can add and remove one or several subprojects.
"""
- output = self.run_with_output(
- [self.python, self.script, self.env, "projects", "--add", "clang"])
+ output = self.run_with_output(self.llvm_projects("--add", "clang"))
self.assertRegex(output, "Projects linked:.*\n.*clang.*")
- output = self.run_with_output([self.python, self.script, self.env, "projects",
- "--add", "libcxx", "lldb"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add", "libcxx", "lldb"))
self.assertRegex(
output,
"Projects linked:.*\n" +
@@ -154,15 +242,15 @@ class Testllvmprojs(unittest.TestCase):
".*libcxx.*\n" +
".*lldb.*")
- output = self.run_with_output(
- [self.python, self.script, self.env, "projects", "--remove", "libcxx"])
+ output = self.run_with_output(self.llvm_projects("--remove", "libcxx"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*lldb.*")
- output = self.run_with_output([self.python, self.script, self.env, "projects",
- "--remove", "clang", "lldb"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--remove", "clang", "lldb"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*none.*")
@@ -173,20 +261,19 @@ class Testllvmprojs(unittest.TestCase):
subprojects.
"""
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python, self.script, self.env, "projects",
- "--add", "inventedsubproject"])
+ self.run_with_output(
+ self.llvm_projects(
+ "--add", "inventedsubproject"))
self.assertRegex(
str(context.exception.output),
"(.*\n)*.*invalid choice:.*inventedsubproject(.*\n)*")
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--remove",
- "inventedsubproject"])
+ self.run_with_output(
+ self.llvm_projects(
+ "--remove",
+ "inventedsubproject"))
self.assertRegex(
str(context.exception.output),
@@ -197,15 +284,17 @@ class Testllvmprojs(unittest.TestCase):
Test that we don't crash when trying to add / remove the same subproject
twice with the same command.
"""
- output = self.run_with_output([self.python, self.script, self.env, "projects",
- "--add", "clang", "lld", "clang"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add", "clang", "lld", "clang"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*lld.*")
- output = self.run_with_output([self.python, self.script, self.env, "projects",
- "--remove", "lld", "lld", "clang"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--remove", "lld", "lld", "clang"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*none.*")
@@ -224,14 +313,14 @@ class Testllvmprojs(unittest.TestCase):
os.path.join(self.llvm_src, "projects", "compiler-rt"),
self.branch)
- output = self.run_with_output(
- [self.python, self.script, self.env, "projects", "--add", "clang"])
+ output = self.run_with_output(self.llvm_projects("--add", "clang"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*")
- output = self.run_with_output([self.python, self.script, self.env, "projects",
- "--add", "compiler-rt", "lld"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add", "compiler-rt", "lld"))
self.assertRegex(
output,
"Projects linked:.*\n" +
@@ -239,14 +328,9 @@ class Testllvmprojs(unittest.TestCase):
".*compiler-rt.*\n" +
".*lld.*")
- output = self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--remove",
- "lldb",
- "libcxx",
- "lld"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--remove", "lldb", "libcxx", "lld"))
self.assertRegex(
output,
"Projects linked:.*\n" +
@@ -260,14 +344,12 @@ class Testllvmprojs(unittest.TestCase):
"""
# Try the really basic case and make sure we're not touching anything
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--add",
- "clang",
- "--remove",
- "clang"])
+ self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "clang",
+ "--remove",
+ "clang"))
self.assertRegex(
str(context.exception.output),
@@ -285,17 +367,15 @@ class Testllvmprojs(unittest.TestCase):
self.branch)
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--add",
- "clang",
- "lld",
- "libcxx",
- "--remove",
- "lld",
- "libcxx"])
+ self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "clang",
+ "lld",
+ "libcxx",
+ "--remove",
+ "lld",
+ "libcxx"))
self.assertRegex(
str(context.exception.output),
"(.*\n)*" +
@@ -317,59 +397,104 @@ class Testllvmprojs(unittest.TestCase):
Test that we can have multiple --add and --remove options in the same
command and that only the last one of each kind matters.
"""
- output = self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--add",
- "libcxxabi",
- "--remove",
- "lld",
- "lldb",
- "--add",
- "clang",
- "libcxx",
- "--remove",
- "libunwind"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "libcxxabi",
+ "--remove",
+ "lld",
+ "lldb",
+ "--add",
+ "clang",
+ "libcxx",
+ "--remove",
+ "libunwind"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*libcxx.*\n")
- output = self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--add",
- "libunwind",
- "libcxxabi",
- "--remove",
- "clang",
- "libcxx",
- "--add",
- "compiler-rt",
- "--remove",
- "libcxxabi"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "libunwind",
+ "libcxxabi",
+ "--remove",
+ "clang",
+ "libcxx",
+ "--add",
+ "compiler-rt",
+ "--remove",
+ "libcxxabi"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*compiler-rt.*\n" +
".*libcxx.*\n")
- output = self.run_with_output([self.python,
- self.script,
- self.env,
- "projects",
- "--add",
- "libcxx",
- "--remove",
- "lld",
- "--add",
- "lld",
- "--remove",
- "libcxx"])
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "libcxx",
+ "--remove",
+ "lld",
+ "--add",
+ "lld",
+ "--remove",
+ "libcxx"))
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*compiler-rt.*\n" +
".*lld.*\n")
+
+ def test_different_env(self):
+ """
+ Test that we can have different environments in completely different
+ paths and they don't interfere when we try to add/remove projects.
+ """
+ # Create a separate environment
+ new_env = mkdtemp()
+ new_branch = "br" + str(uuid4())
+ self.__add_worktree(self.__get_subproj_repo("llvm"),
+ os.path.join(new_env, "llvm"), new_branch)
+
+ # Check that we start with a clean slate in both the new environment and
+ # the one that's already set up
+ output = self.run_with_output(self.llvm_projects())
+ self.assertRegex(output, "Projects linked:.*\n.*none.*")
+
+ output = self.run_with_output(self.llvm_projects(env=new_env))
+ self.assertRegex(output, "Projects linked:.*\n.*none.*")
+
+ # Make sure that adding projects works
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add", "clang", "lld"))
+ self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n")
+
+ output = self.run_with_output(
+ self.llvm_projects(
+ "--add",
+ "libcxx",
+ "libcxxabi",
+ env=new_env))
+ self.assertRegex(output,
+ "Projects linked:.*\n.*libcxx.*\n.*libcxxabi.*\n.*")
+
+ output = self.run_with_output(self.llvm_projects())
+ self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n")
+
+ # Make sure that removing projects works
+ output = self.run_with_output(self.llvm_projects("--remove", "lld"))
+ self.assertRegex(output, "Projects linked:.*\n.*clang.*\n")
+
+ output = self.run_with_output(self.llvm_projects("--remove", "libcxx",
+ env=new_env))
+ self.assertRegex(output,
+ "Projects linked:.*\n.*libcxxabi.*\n.*")
+
+ output = self.run_with_output(self.llvm_projects())
+ self.assertRegex(output, "Projects linked:.*\n.*clang.*\n")
+
+ shutil.rmtree(new_env)