@@ -41,6 +41,7 @@ def test_ast_ignore
4141 def test_ast_syntax_error
4242 result = run_cli ( "ast" , contents : "foo\n <>\n bar\n " )
4343 assert_includes ( result . stderr , "syntax error" )
44+ refute_equal ( 0 , result . status )
4445 end
4546
4647 def test_check
@@ -51,6 +52,7 @@ def test_check
5152 def test_check_unformatted
5253 result = run_cli ( "check" , contents : "foo" )
5354 assert_includes ( result . stderr , "expected" )
55+ refute_equal ( 0 , result . status )
5456 end
5557
5658 def test_check_print_width
@@ -59,6 +61,17 @@ def test_check_print_width
5961 assert_includes ( result . stdio , "match" )
6062 end
6163
64+ def test_check_target_ruby_version
65+ previous = Formatter ::OPTIONS [ :target_ruby_version ]
66+
67+ begin
68+ result = run_cli ( "check" , "--target-ruby-version=2.6.0" )
69+ assert_includes ( result . stdio , "match" )
70+ ensure
71+ Formatter ::OPTIONS [ :target_ruby_version ] = previous
72+ end
73+ end
74+
6275 def test_debug
6376 result = run_cli ( "debug" )
6477 assert_includes ( result . stdio , "idempotently" )
@@ -71,6 +84,7 @@ def test_debug_non_idempotent_format
7184 SyntaxTree . stub ( :format , formatting ) do
7285 result = run_cli ( "debug" )
7386 assert_includes ( result . stderr , "idempotently" )
87+ refute_equal ( 0 , result . status )
7488 end
7589 end
7690
@@ -84,6 +98,12 @@ def test_expr
8498 assert_includes ( result . stdio , "SyntaxTree::Ident" )
8599 end
86100
101+ def test_expr_more_than_one
102+ result = run_cli ( "expr" , contents : "1; 2" )
103+ assert_includes ( result . stderr , "single expression" )
104+ refute_equal ( 0 , result . status )
105+ end
106+
87107 def test_format
88108 result = run_cli ( "format" )
89109 assert_equal ( "test\n " , result . stdio )
@@ -104,6 +124,17 @@ def test_search
104124 assert_equal ( 2 , result . stdio . lines . length )
105125 end
106126
127+ def test_search_multi_line
128+ result = run_cli ( "search" , "Binary" , contents : "1 +\n 2" )
129+ assert_equal ( 1 , result . stdio . lines . length )
130+ end
131+
132+ def test_search_invalid
133+ result = run_cli ( "search" , "FooBar" )
134+ assert_includes ( result . stderr , "unable" )
135+ refute_equal ( 0 , result . status )
136+ end
137+
107138 def test_version
108139 result = run_cli ( "version" )
109140 assert_includes ( result . stdio , SyntaxTree ::VERSION . to_s )
@@ -120,6 +151,29 @@ def test_write
120151 def test_write_syntax_tree
121152 result = run_cli ( "write" , contents : "<>" )
122153 assert_includes ( result . stderr , "syntax error" )
154+ refute_equal ( 0 , result . status )
155+ end
156+
157+ def test_write_script
158+ args = [ "write" , "-e" , "1 + 2" ]
159+ stdout , stderr = capture_io { SyntaxTree ::CLI . run ( args ) }
160+
161+ assert_includes stdout , "script"
162+ assert_empty stderr
163+ end
164+
165+ def test_write_stdin
166+ previous = $stdin
167+ $stdin = StringIO . new ( "1 + 2" )
168+
169+ begin
170+ stdout , stderr = capture_io { SyntaxTree ::CLI . run ( [ "write" ] ) }
171+
172+ assert_includes stdout , "stdin"
173+ assert_empty stderr
174+ ensure
175+ $stdin = previous
176+ end
123177 end
124178
125179 def test_help
@@ -128,8 +182,10 @@ def test_help
128182 end
129183
130184 def test_help_default
131- *, stderr = capture_io { SyntaxTree ::CLI . run ( [ "foobar" ] ) }
185+ status = 0
186+ *, stderr = capture_io { status = SyntaxTree ::CLI . run ( [ "foobar" ] ) }
132187 assert_includes ( stderr , "stree help" )
188+ refute_equal ( 0 , status )
133189 end
134190
135191 def test_no_arguments
@@ -215,6 +271,7 @@ def test_print_width_args_with_config_file_override
215271 result = run_cli ( "check" , "--print-width=82" , contents : contents )
216272
217273 assert_includes ( result . stderr , "expected" )
274+ refute_equal ( 0 , result . status )
218275 end
219276 end
220277
@@ -251,7 +308,12 @@ def run_cli(command, *args, contents: :default)
251308 status = nil
252309 stdio , stderr =
253310 capture_io do
254- status = SyntaxTree ::CLI . run ( [ command , *args , tempfile . path ] )
311+ status =
312+ begin
313+ SyntaxTree ::CLI . run ( [ command , *args , tempfile . path ] )
314+ rescue SystemExit => error
315+ error . status
316+ end
255317 end
256318
257319 Result . new ( status : status , stdio : stdio , stderr : stderr )
0 commit comments