@@ -33,7 +33,13 @@ defmodule Retry do
33
33
end
34
34
35
35
defmodule Kernel.CLITest do
36
- use ExUnit.Case , async: true
36
+ use ExUnit.Case ,
37
+ async: true ,
38
+ parameterize:
39
+ if ( PathHelpers . windows? ( ) ,
40
+ do: [ % { cli_extension: ".bat" } , % { cli_extension: ".ps1" } ] ,
41
+ else: [ % { cli_extension: "" } , % { cli_extension: ".ps1" } ]
42
+ )
37
43
38
44
import ExUnit.CaptureIO
39
45
@@ -62,86 +68,105 @@ defmodule Kernel.CLITest do
62
68
end
63
69
64
70
defmodule Kernel.CLI.ExecutableTest do
65
- use ExUnit.Case , async: true
71
+ use ExUnit.Case ,
72
+ async: true ,
73
+ parameterize:
74
+ if ( PathHelpers . windows? ( ) ,
75
+ do: [ % { cli_extension: ".bat" } , % { cli_extension: ".ps1" } ] ,
76
+ else:
77
+ [ % { cli_extension: "" } ] ++
78
+ if ( System . find_executable ( "pwsh" ) , do: [ % { cli_extension: ".ps1" } ] , else: [ ] )
79
+ )
66
80
67
81
import Retry
68
82
69
83
@ tag :tmp_dir
70
84
test "file smoke test" , context do
71
85
file = Path . join ( context . tmp_dir , "hello_world!.exs" )
72
86
File . write! ( file , "IO.puts :hello_world123" )
73
- { output , 0 } = System . cmd ( elixir_executable ( ) , [ file ] )
87
+ { output , 0 } = System . cmd ( elixir_executable ( context . cli_extension ) , [ file ] )
74
88
assert output =~ "hello_world123"
75
89
end
76
90
77
- test "--eval smoke test" do
78
- { output , 0 } = System . cmd ( elixir_executable ( ) , [ "--eval" , "IO.puts :hello_world123" ] )
91
+ test "--eval smoke test" , context do
92
+ { output , 0 } =
93
+ System . cmd ( elixir_executable ( context . cli_extension ) , [ "--eval" , "IO.puts :hello_world123" ] )
94
+
79
95
assert output =~ "hello_world123"
80
96
81
97
# Check for -e and exclamation mark handling on Windows
82
- assert { _output , 0 } = System . cmd ( elixir_executable ( ) , [ "-e" , "Time.new!(0, 0, 0)" ] )
98
+ assert { _output , 0 } =
99
+ System . cmd ( elixir_executable ( context . cli_extension ) , [ "-e" , "Time.new!(0, 0, 0)" ] )
83
100
84
101
# TODO: remove this once we bump CI to 26.3
85
102
unless windows? ( ) and System . otp_release ( ) == "26" do
86
103
{ output , 0 } =
87
- System . cmd ( iex_executable ( ) , [ "--eval" , "IO.puts :hello_world123; System.halt()" ] )
104
+ System . cmd ( iex_executable ( context . cli_extension ) , [
105
+ "--eval" ,
106
+ "IO.puts :hello_world123; System.halt()"
107
+ ] )
88
108
89
109
assert output =~ "hello_world123"
90
110
91
- { output , 0 } = System . cmd ( iex_executable ( ) , [ "-e" , "IO.puts :hello_world123; System.halt()" ] )
111
+ { output , 0 } =
112
+ System . cmd ( iex_executable ( context . cli_extension ) , [
113
+ "-e" ,
114
+ "IO.puts :hello_world123; System.halt()"
115
+ ] )
116
+
92
117
assert output =~ "hello_world123"
93
118
end
94
119
end
95
120
96
- test "--version smoke test" do
97
- output = elixir ( ~c" --version" )
121
+ test "--version smoke test" , % { cli_extension: cli_extension } do
122
+ output = elixir ( ~c" --version" , cli_extension )
98
123
assert output =~ "Erlang/OTP #{ System . otp_release ( ) } "
99
124
assert output =~ "Elixir #{ System . version ( ) } "
100
125
101
- output = iex ( ~c" --version" )
126
+ output = iex ( ~c" --version" , cli_extension )
102
127
assert output =~ "Erlang/OTP #{ System . otp_release ( ) } "
103
128
assert output =~ "IEx #{ System . version ( ) } "
104
129
105
- output = elixir ( ~c" --version -e \" IO.puts(:test_output)\" " )
130
+ output = elixir ( ~c" --version -e \" IO.puts(:test_output)\" " , cli_extension )
106
131
assert output =~ "Erlang/OTP #{ System . otp_release ( ) } "
107
132
assert output =~ "Elixir #{ System . version ( ) } "
108
133
assert output =~ "Standalone options can't be combined with other options"
109
134
end
110
135
111
- test "--short-version smoke test" do
112
- output = elixir ( ~c" --short-version" )
136
+ test "--short-version smoke test" , % { cli_extension: cli_extension } do
137
+ output = elixir ( ~c" --short-version" , cli_extension )
113
138
assert output =~ System . version ( )
114
139
refute output =~ "Erlang"
115
140
end
116
141
117
- stderr_test "--help smoke test" do
118
- output = elixir ( ~c" --help" )
142
+ stderr_test "--help smoke test" , % { cli_extension: cli_extension } do
143
+ output = elixir ( ~c" --help" , cli_extension )
119
144
assert output =~ "Usage: elixir"
120
145
end
121
146
122
- stderr_test "combining --help results in error" do
123
- output = elixir ( ~c" -e 1 --help" )
147
+ stderr_test "combining --help results in error" , % { cli_extension: cli_extension } do
148
+ output = elixir ( ~c" -e 1 --help" , cli_extension )
124
149
assert output =~ "--help : Standalone options can't be combined with other options"
125
150
126
- output = elixir ( ~c" --help -e 1" )
151
+ output = elixir ( ~c" --help -e 1" , cli_extension )
127
152
assert output =~ "--help : Standalone options can't be combined with other options"
128
153
end
129
154
130
- stderr_test "combining --short-version results in error" do
131
- output = elixir ( ~c" --short-version -e 1" )
155
+ stderr_test "combining --short-version results in error" , % { cli_extension: cli_extension } do
156
+ output = elixir ( ~c" --short-version -e 1" , cli_extension )
132
157
assert output =~ "--short-version : Standalone options can't be combined with other options"
133
158
134
- output = elixir ( ~c" -e 1 --short-version" )
159
+ output = elixir ( ~c" -e 1 --short-version" , cli_extension )
135
160
assert output =~ "--short-version : Standalone options can't be combined with other options"
136
161
end
137
162
138
- test "parses paths" do
163
+ test "parses paths" , % { cli_extension: cli_extension } do
139
164
root = fixture_path ( "../../.." ) |> to_charlist
140
165
141
166
args =
142
167
~c" -pa \" #{ root } /*\" -pz \" #{ root } /lib/*\" -e \" IO.inspect(:code.get_path(), limit: :infinity)\" "
143
168
144
- list = elixir ( args )
169
+ list = elixir ( args , cli_extension )
145
170
{ path , _ } = Code . eval_string ( list , [ ] )
146
171
147
172
# pa
@@ -153,25 +178,31 @@ defmodule Kernel.CLI.ExecutableTest do
153
178
assert to_charlist ( Path . expand ( ~c" lib/list" , root ) ) in path
154
179
end
155
180
156
- stderr_test "formats errors" do
157
- assert String . starts_with? ( elixir ( ~c" -e \" :erlang.throw 1\" " ) , "** (throw) 1" )
181
+ stderr_test "formats errors" , % { cli_extension: cli_extension } do
182
+ assert String . starts_with? ( elixir ( ~c" -e \" :erlang.throw 1\" " , cli_extension ) , "** (throw) 1" )
158
183
159
184
assert String . starts_with? (
160
- elixir ( ~c" -e \" :erlang.error 1\" " ) ,
185
+ elixir ( ~c" -e \" :erlang.error 1\" " , cli_extension ) ,
161
186
"** (ErlangError) Erlang error: 1"
162
187
)
163
188
164
- assert String . starts_with? ( elixir ( ~c" -e \" 1 +\" " ) , "** (TokenMissingError)" )
189
+ assert String . starts_with? ( elixir ( ~c" -e \" 1 +\" " , cli_extension ) , "** (TokenMissingError)" )
165
190
166
- assert elixir ( ~c" -e \" Task.async(fn -> raise ArgumentError end) |> Task.await\" " ) =~
191
+ assert elixir (
192
+ ~c" -e \" Task.async(fn -> raise ArgumentError end) |> Task.await\" " ,
193
+ cli_extension
194
+ ) =~
167
195
"an exception was raised:\n ** (ArgumentError) argument error"
168
196
169
- assert elixir ( ~c" -e \" IO.puts(Process.flag(:trap_exit, false)); exit({:shutdown, 1})\" " ) ==
197
+ assert elixir (
198
+ ~c" -e \" IO.puts(Process.flag(:trap_exit, false)); exit({:shutdown, 1})\" " ,
199
+ cli_extension
200
+ ) ==
170
201
"false\n "
171
202
end
172
203
173
- stderr_test "blames exceptions" do
174
- error = elixir ( ~c" -e \" Access.fetch :foo, :bar\" " )
204
+ stderr_test "blames exceptions" , % { cli_extension: cli_extension } do
205
+ error = elixir ( ~c" -e \" Access.fetch :foo, :bar\" " , cli_extension )
175
206
assert error =~ "** (FunctionClauseError) no function clause matching in Access.fetch/2"
176
207
assert error =~ "The following arguments were given to Access.fetch/2"
177
208
assert error =~ ":foo"
@@ -238,7 +269,15 @@ defmodule Kernel.CLI.RPCTest do
238
269
end
239
270
240
271
defmodule Kernel.CLI.CompileTest do
241
- use ExUnit.Case , async: true
272
+ use ExUnit.Case ,
273
+ async: true ,
274
+ parameterize:
275
+ if ( PathHelpers . windows? ( ) ,
276
+ do: [ % { cli_extension: ".bat" } , % { cli_extension: ".ps1" } ] ,
277
+ else:
278
+ [ % { cli_extension: "" } ] ++
279
+ if ( System . find_executable ( "pwsh" ) , do: [ % { cli_extension: ".ps1" } ] , else: [ ] )
280
+ )
242
281
243
282
import Retry
244
283
@ moduletag :tmp_dir
@@ -250,7 +289,7 @@ defmodule Kernel.CLI.CompileTest do
250
289
end
251
290
252
291
test "compiles code" , context do
253
- assert elixirc ( ~c" #{ context . fixture } -o #{ context . tmp_dir } " ) == ""
292
+ assert elixirc ( ~c" #{ context . fixture } -o #{ context . tmp_dir } " , context . cli_extension ) == ""
254
293
assert File . regular? ( context . beam_file_path )
255
294
256
295
# Assert that the module is loaded into memory with the proper destination for the BEAM file.
@@ -267,7 +306,7 @@ defmodule Kernel.CLI.CompileTest do
267
306
try do
268
307
fixture = String . replace ( context . fixture , "/" , "\\ " )
269
308
tmp_dir_path = String . replace ( context . tmp_dir , "/" , "\\ " )
270
- assert elixirc ( ~c" #{ fixture } -o #{ tmp_dir_path } " ) == ""
309
+ assert elixirc ( ~c" #{ fixture } -o #{ tmp_dir_path } " , context . cli_extension ) == ""
271
310
assert File . regular? ( context [ :beam_file_path ] )
272
311
273
312
# Assert that the module is loaded into memory with the proper destination for the BEAM file.
@@ -283,7 +322,9 @@ defmodule Kernel.CLI.CompileTest do
283
322
end
284
323
285
324
stderr_test "fails on missing patterns" , context do
286
- output = elixirc ( ~c" #{ context . fixture } non_existing.ex -o #{ context . tmp_dir } " )
325
+ output =
326
+ elixirc ( ~c" #{ context . fixture } non_existing.ex -o #{ context . tmp_dir } " , context . cli_extension )
327
+
287
328
assert output =~ "non_existing.ex"
288
329
refute output =~ "compile_sample.ex"
289
330
refute File . exists? ( context . beam_file_path )
@@ -292,7 +333,7 @@ defmodule Kernel.CLI.CompileTest do
292
333
stderr_test "fails on missing write access to .beam file" , context do
293
334
compilation_args = ~c" #{ context . fixture } -o #{ context . tmp_dir } "
294
335
295
- assert elixirc ( compilation_args ) == ""
336
+ assert elixirc ( compilation_args , context . cli_extension ) == ""
296
337
assert File . regular? ( context . beam_file_path )
297
338
298
339
# Set the .beam file to read-only
@@ -301,7 +342,7 @@ defmodule Kernel.CLI.CompileTest do
301
342
302
343
# Can only assert when read-only applies to the user
303
344
if access != :read_write do
304
- output = elixirc ( compilation_args )
345
+ output = elixirc ( compilation_args , context . cli_extension )
305
346
306
347
expected =
307
348
"(File.Error) could not write to file #{ inspect ( context . beam_file_path ) } : permission denied"
0 commit comments