@@ -81,25 +81,21 @@ class CapturedIO:
81
81
82
82
83
83
@pytest .fixture
84
- def run_cli (monkeypatch ):
84
+ def run_cli (monkeypatch , capsys , cap_lisp_io ):
85
85
def _run_cli (args : Sequence [str ], input : Optional [str ] = None ):
86
+ monkeypatch .setattr ("basilisp.main._runtime_is_initialized" , False )
86
87
if input is not None :
87
88
monkeypatch .setattr (
88
89
"sys.stdin" , io .TextIOWrapper (io .BytesIO (input .encode ("utf-8" )))
89
90
)
90
- process = subprocess .run (
91
- ["basilisp" , * args ],
92
- stdin = io .StringIO (input ) if input is not None else None ,
93
- encoding = "utf-8" ,
94
- capture_output = True ,
95
- check = True ,
96
- )
97
-
91
+ invoke_cli ([* args ])
92
+ python_io = capsys .readouterr ()
93
+ lisp_out , lisp_err = cap_lisp_io
98
94
return CapturedIO (
99
- out = process . stdout ,
100
- err = process . stderr ,
101
- lisp_out = process . stdout ,
102
- lisp_err = process . stderr ,
95
+ out = python_io . out ,
96
+ err = python_io . err ,
97
+ lisp_out = lisp_out . getvalue () ,
98
+ lisp_err = lisp_err . getvalue () ,
103
99
)
104
100
105
101
return _run_cli
@@ -209,7 +205,7 @@ def test_valid_flag(self, run_cli, val):
209
205
210
206
@pytest .mark .parametrize ("val" , ["maybe" , "not-no" , "4" ])
211
207
def test_invalid_flag (self , run_cli , val ):
212
- with pytest .raises (subprocess . CalledProcessError ):
208
+ with pytest .raises (SystemExit ):
213
209
run_cli (["run" , "--warn-on-var-indirection" , val , "-c" , "(+ 1 2)" ])
214
210
215
211
@@ -360,7 +356,7 @@ def test_repl_include_extra_path(
360
356
361
357
class TestRun :
362
358
def test_run_ns_and_code_mutually_exclusive (self , run_cli ):
363
- with pytest .raises (subprocess . CalledProcessError ):
359
+ with pytest .raises (SystemExit ):
364
360
run_cli (["run" , "-c" , "-n" ])
365
361
366
362
class TestRunCode :
@@ -555,7 +551,7 @@ def test_cannot_run_namespace_with_in_ns_arg(
555
551
self , run_cli , namespace_name : str , namespace_file : pathlib .Path
556
552
):
557
553
namespace_file .write_text ("(println (+ 1 2))" )
558
- with pytest .raises (subprocess . CalledProcessError ):
554
+ with pytest .raises (SystemExit ):
559
555
run_cli (["run" , "--in-ns" , "otherpackage.core" , "-n" , namespace_name ])
560
556
561
557
def test_run_namespace (
0 commit comments