diff --git a/tests/functional2/testlib/fixtures/command.py b/tests/functional2/testlib/fixtures/command.py index fb91c1248..9c80ef443 100644 --- a/tests/functional2/testlib/fixtures/command.py +++ b/tests/functional2/testlib/fixtures/command.py @@ -149,6 +149,16 @@ class Command: self.argv = list(argv) return self + def with_wrapper(self, cmd: str | Path, *args: list[str]) -> "Command": + """ + Wraps the current command in the given wrapper. + e.g: Command(["nix", "eval", "1+1"]).with_wrapper("strace") => Command(["strace", "nix", "eval", "1+1"]) + """ + self.argv = [cmd, *args, *self.argv] + if self.exe: + self.exe = None if isinstance(cmd, str) else cmd + return self + def run(self) -> CommandResult: """ Runs the configured command diff --git a/tests/functional2/testlib/fixtures/test_command.py b/tests/functional2/testlib/fixtures/test_command.py index 8087e0158..19336d830 100644 --- a/tests/functional2/testlib/fixtures/test_command.py +++ b/tests/functional2/testlib/fixtures/test_command.py @@ -79,3 +79,10 @@ def test_command_exec_fails_on_other_bad_exit_code( out_msg, err_msg = msgs assert out_msg == "stdout: drgn fops\n" assert err_msg == "stderr: " + + +def test_command_wrapping(command: Callable[[list[str]], Command]): + cmd = command(["echo $0 -- $@", "wrapper", "hello", "world"]).with_wrapper("bash", "-c") + res = cmd.run().ok() + + assert res.stdout_plain == "wrapper -- hello world"