diff --git a/tests/zxpy_test.py b/tests/zxpy_test.py index 2da8834..d819cb4 100644 --- a/tests/zxpy_test.py +++ b/tests/zxpy_test.py @@ -76,3 +76,10 @@ def test_prints(capsys: pytest.CaptureFixture[str]) -> None: def test_argv() -> None: test_file = "./tests/test_files/argv.py" subprocess.run(["zxpy", test_file]) + + +def test_raise() -> None: + with pytest.raises(ChildProcessError) as exc: + zx.run_shell("exit 1") + + assert exc.value.args == (1,) diff --git a/zx.py b/zx.py index 3b5f18f..afd8cb2 100644 --- a/zx.py +++ b/zx.py @@ -59,8 +59,15 @@ def cli() -> None: def create_shell_process(command: str) -> IO[bytes]: """Creates a shell process, returning its stdout to read data from.""" process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True + command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True, ) + process.wait() + if process.returncode != 0: + raise ChildProcessError(process.returncode) + assert process.stdout is not None return process.stdout