@@ -13,46 +13,10 @@ defmodule Mix.Tasks.EscriptTest do
13
13
end
14
14
end
15
15
16
- defmodule EscriptWithDebugInfo do
17
- def project do
18
- [
19
- app: :escript_test_with_debug_info ,
20
- version: "0.0.1" ,
21
- escript: [ main_module: EscriptTest , strip_beams: false ]
22
- ]
23
- end
24
- end
25
-
26
- defmodule EscriptWithPath do
27
- def project do
28
- [
29
- app: :escript_test_with_path ,
30
- version: "0.0.1" ,
31
- escript: [
32
- app: nil ,
33
- embed_elixir: true ,
34
- main_module: EscriptTest ,
35
- path: Path . join ( "ebin" , "escript_test_with_path" )
36
- ]
37
- ]
38
- end
39
- end
40
-
41
- defmodule EscriptWithDeps do
42
- def project do
43
- [
44
- app: :escript_test_with_deps ,
45
- version: "0.0.1" ,
46
- escript: [ main_module: EscriptTest ] ,
47
- deps: [ { :ok , path: fixture_path ( "deps_status/deps/ok" ) } ]
48
- ]
49
- end
50
- end
51
-
52
16
defmodule EscriptErlangWithDeps do
53
17
def project do
54
18
[
55
- app: :escript_test_erlang_with_deps ,
19
+ app: :escript_test ,
56
20
version: "0.0.1" ,
57
21
language: :erlang ,
58
22
escript: [ main_module: :escript_test ] ,
@@ -65,57 +29,18 @@ defmodule Mix.Tasks.EscriptTest do
65
29
end
66
30
end
67
31
68
- defmodule EscriptErlangMainModule do
69
- def project do
70
- [
71
- app: :escript_test_erlang_main_module ,
72
- version: "0.0.1" ,
73
- escript: [ main_module: :escript_test ]
74
- ]
75
- end
76
- end
77
-
78
- defmodule EscriptWithUnknownMainModule do
79
- def project do
80
- [
81
- app: :escript_test_with_unknown_main_module ,
82
- version: "0.0.1" ,
83
- escript: [ main_module: BogusEscriptTest ]
84
- ]
85
- end
86
- end
87
-
88
- defmodule EscriptConsolidated do
89
- def project do
90
- [
91
- app: :escript_test_consolidated ,
92
- build_embedded: true ,
93
- version: "0.0.1" ,
94
- escript: [ main_module: EscriptTest ]
95
- ]
96
- end
97
- end
98
-
99
- defmodule EscriptWithPrivs do
100
- def project do
101
- [
102
- app: :escript_test_with_priv ,
103
- version: "0.0.1" ,
104
- escript: [ main_module: EscriptTest , include_priv_for: [ :escript_test_with_priv , :ok ] ] ,
105
- deps: [ { :ok , path: fixture_path ( "deps_status/deps/ok" ) } ]
106
- ]
107
- end
108
- end
109
-
110
32
test "generate escript" do
111
33
in_fixture ( "escript_test" , fn ->
112
- Mix.Project . push ( Escript )
34
+ push_project_with_config ( Escript )
113
35
114
36
Mix.Tasks.Escript.Build . run ( [ ] )
115
37
assert_received { :mix_shell , :info , [ "Generated escript escript_test with MIX_ENV=dev" ] }
116
38
assert System . cmd ( "escript" , [ "escript_test" ] ) == { "TEST\n " , 0 }
117
39
assert count_abstract_code ( "escript_test" ) == 0
118
40
41
+ # Consolidates protocols
42
+ assert System . cmd ( "escript" , [ "escript_test" , "--protocol" , "Enumerable" ] ) == { "true\n " , 0 }
43
+
119
44
# Each app has a distinct, valid path
120
45
assert System . cmd ( "escript" , [ "escript_test" , "--app-paths" ] ) == { "{true, true, true}\n " , 0 }
121
46
@@ -127,7 +52,7 @@ defmodule Mix.Tasks.EscriptTest do
127
52
128
53
test "generate escript with --no-compile option" do
129
54
in_fixture ( "escript_test" , fn ->
130
- Mix.Project . push ( Escript )
55
+ push_project_with_config ( Escript )
131
56
132
57
Mix.Tasks.Compile . run ( [ ] )
133
58
purge ( [ EscriptTest ] )
@@ -139,7 +64,7 @@ defmodule Mix.Tasks.EscriptTest do
139
64
140
65
test "generate escript with compile config" do
141
66
in_fixture ( "escript_test" , fn ->
142
- Mix.Project . push ( Escript )
67
+ push_project_with_config ( Escript )
143
68
144
69
File . mkdir_p! ( "config" )
145
70
@@ -156,7 +81,7 @@ defmodule Mix.Tasks.EscriptTest do
156
81
157
82
test "generate escript with runtime config" do
158
83
in_fixture ( "escript_test" , fn ->
159
- Mix.Project . push ( Escript )
84
+ push_project_with_config ( Escript )
160
85
161
86
File . mkdir_p! ( "config" )
162
87
@@ -183,15 +108,15 @@ defmodule Mix.Tasks.EscriptTest do
183
108
184
109
test "generate escript with debug information" do
185
110
in_fixture ( "escript_test" , fn ->
186
- Mix.Project . push ( EscriptWithDebugInfo )
111
+ push_project_with_config ( Escript , escript: [ main_module: EscriptTest , strip_beams: false ] )
187
112
188
113
Mix.Tasks.Escript.Build . run ( [ ] )
189
114
190
- msg = "Generated escript escript_test_with_debug_info with MIX_ENV=dev"
115
+ msg = "Generated escript escript_test with MIX_ENV=dev"
191
116
assert_received { :mix_shell , :info , [ ^ msg ] }
192
117
193
- assert System . cmd ( "escript" , [ "escript_test_with_debug_info " ] ) == { "TEST\n " , 0 }
194
- assert count_abstract_code ( "escript_test_with_debug_info " ) > 0
118
+ assert System . cmd ( "escript" , [ "escript_test " ] ) == { "TEST\n " , 0 }
119
+ assert count_abstract_code ( "escript_test " ) > 0
195
120
end )
196
121
end
197
122
@@ -226,46 +151,55 @@ defmodule Mix.Tasks.EscriptTest do
226
151
227
152
test "generate escript with path" do
228
153
in_fixture ( "escript_test" , fn ->
229
- Mix.Project . push ( EscriptWithPath )
154
+ push_project_with_config ( Escript ,
155
+ escript: [
156
+ app: nil ,
157
+ embed_elixir: true ,
158
+ main_module: EscriptTest ,
159
+ path: Path . join ( "ebin" , "escript_test" )
160
+ ]
161
+ )
230
162
231
163
Mix.Tasks.Escript.Build . run ( [ ] )
232
164
233
- message = "Generated escript ebin/escript_test_with_path with MIX_ENV=dev"
165
+ message = "Generated escript ebin/escript_test with MIX_ENV=dev"
234
166
assert_received { :mix_shell , :info , [ ^ message ] }
235
167
236
- assert System . cmd ( "escript" , [ "ebin/escript_test_with_path " ] ) == { "TEST\n " , 0 }
168
+ assert System . cmd ( "escript" , [ "ebin/escript_test " ] ) == { "TEST\n " , 0 }
237
169
end )
238
170
end
239
171
240
172
test "generate escript with deps" do
241
173
in_fixture ( "escript_test" , fn ->
242
- Mix.Project . push ( EscriptWithDeps )
174
+ push_project_with_config ( Escript ,
175
+ escript: [ main_module: EscriptTest ] ,
176
+ deps: [ { :ok , path: fixture_path ( "deps_status/deps/ok" ) } ]
177
+ )
243
178
244
179
Mix.Tasks.Escript.Build . run ( [ ] )
245
180
246
- message = "Generated escript escript_test_with_deps with MIX_ENV=dev"
181
+ message = "Generated escript escript_test with MIX_ENV=dev"
247
182
assert_received { :mix_shell , :info , [ ^ message ] }
248
183
249
- assert System . cmd ( "escript" , [ "escript_test_with_deps " ] ) == { "TEST\n " , 0 }
184
+ assert System . cmd ( "escript" , [ "escript_test " ] ) == { "TEST\n " , 0 }
250
185
251
186
# Does not include priv for deps by default
252
- assert System . cmd ( "escript" , [ "escript_test_with_deps" , "--list-priv" , "ok" ] ) ==
253
- { ":error\n " , 0 }
187
+ assert System . cmd ( "escript" , [ "escript_test" , "--list-priv" , "ok" ] ) == { ":error\n " , 0 }
254
188
end )
255
189
after
256
190
purge ( [ Ok.MixProject ] )
257
191
end
258
192
259
193
test "generate escript with Erlang and deps" do
260
194
in_fixture ( "escript_test" , fn ->
261
- Mix.Project . push ( EscriptErlangWithDeps )
195
+ push_project_with_config ( EscriptErlangWithDeps )
262
196
263
197
Mix.Tasks.Escript.Build . run ( [ ] )
264
198
265
- message = "Generated escript escript_test_erlang_with_deps with MIX_ENV=dev"
199
+ message = "Generated escript escript_test with MIX_ENV=dev"
266
200
assert_received { :mix_shell , :info , [ ^ message ] }
267
201
268
- assert System . cmd ( "escript" , [ "escript_test_erlang_with_deps " , "arg1" , "arg2" ] ) ==
202
+ assert System . cmd ( "escript" , [ "escript_test " , "arg1" , "arg2" ] ) ==
269
203
{ ~s( ["arg1","arg2"]) , 0 }
270
204
end )
271
205
after
@@ -274,50 +208,36 @@ defmodule Mix.Tasks.EscriptTest do
274
208
275
209
test "generate escript with Erlang main module" do
276
210
in_fixture ( "escript_test" , fn ->
277
- Mix.Project . push ( EscriptErlangMainModule )
211
+ push_project_with_config ( Escript , escript: [ main_module: :escript_test ] )
278
212
279
213
Mix.Tasks.Escript.Build . run ( [ ] )
280
214
281
- message = "Generated escript escript_test_erlang_main_module with MIX_ENV=dev"
215
+ message = "Generated escript escript_test with MIX_ENV=dev"
282
216
assert_received { :mix_shell , :info , [ ^ message ] }
283
217
284
- assert System . cmd ( "escript" , [ "escript_test_erlang_main_module " , "arg1" , "arg2" ] ) ==
218
+ assert System . cmd ( "escript" , [ "escript_test " , "arg1" , "arg2" ] ) ==
285
219
{ ~s( [<<"arg1">>,<<"arg2">>]) , 0 }
286
220
end )
287
221
after
288
222
purge ( [ Ok.MixProject ] )
289
223
end
290
224
291
- test "generate escript with consolidated protocols" do
292
- in_fixture ( "escript_test" , fn ->
293
- Mix.Project . push ( EscriptConsolidated )
294
-
295
- Mix.Tasks.Escript.Build . run ( [ ] )
296
-
297
- message = "Generated escript escript_test_consolidated with MIX_ENV=dev"
298
- assert_received { :mix_shell , :info , [ ^ message ] }
299
-
300
- assert System . cmd ( "escript" , [ "escript_test_consolidated" , "--protocol" , "Enumerable" ] ) ==
301
- { "true\n " , 0 }
302
- end )
303
- end
304
-
305
225
test "generate escript with priv" do
306
226
in_fixture ( "escript_test" , fn ->
307
- Mix.Project . push ( EscriptWithPrivs )
227
+ push_project_with_config ( Escript ,
228
+ escript: [ main_module: EscriptTest , include_priv_for: [ :escript_test , :ok ] ] ,
229
+ deps: [ { :ok , path: fixture_path ( "deps_status/deps/ok" ) } ]
230
+ )
308
231
309
232
Mix.Tasks.Escript.Build . run ( [ ] )
310
233
311
- message = "Generated escript escript_test_with_priv with MIX_ENV=dev"
234
+ message = "Generated escript escript_test with MIX_ENV=dev"
312
235
assert_received { :mix_shell , :info , [ ^ message ] }
313
236
314
- assert System . cmd ( "escript" , [
315
- "escript_test_with_priv" ,
316
- "--list-priv" ,
317
- "escript_test_with_priv"
318
- ] ) == { ~s/ {:ok, [~c"hello"]}\n / , 0 }
237
+ assert System . cmd ( "escript" , [ "escript_test" , "--list-priv" , "escript_test" ] ) ==
238
+ { ~s/ {:ok, [~c"hello"]}\n / , 0 }
319
239
320
- assert System . cmd ( "escript" , [ "escript_test_with_priv " , "--list-priv" , "ok" ] ) ==
240
+ assert System . cmd ( "escript" , [ "escript_test " , "--list-priv" , "ok" ] ) ==
321
241
{ ~s/ {:ok, [~c"sample"]}\n / , 0 }
322
242
end )
323
243
end
@@ -326,7 +246,7 @@ defmodule Mix.Tasks.EscriptTest do
326
246
File . rm_rf! ( tmp_path ( ".mix/escripts" ) )
327
247
328
248
in_fixture ( "escript_test" , fn ->
329
- Mix.Project . push ( Escript )
249
+ push_project_with_config ( Escript )
330
250
331
251
# check that no escripts are installed
332
252
Mix.Tasks.Escript . run ( [ ] )
@@ -362,7 +282,7 @@ defmodule Mix.Tasks.EscriptTest do
362
282
File . rm_rf! ( tmp_path ( ".mix/escripts" ) )
363
283
364
284
in_fixture ( "escript_test" , fn ->
365
- Mix.Project . push ( Escript )
285
+ push_project_with_config ( Escript )
366
286
367
287
Mix.Tasks.Escript.Install . run ( [ "--force" ] )
368
288
@@ -392,7 +312,7 @@ defmodule Mix.Tasks.EscriptTest do
392
312
393
313
test "escript invalid main module" do
394
314
in_fixture ( "escript_test" , fn ->
395
- Mix.Project . push ( EscriptWithUnknownMainModule )
315
+ push_project_with_config ( Escript , escript: [ main_module: BogusEscriptTest ] )
396
316
397
317
message =
398
318
"Could not generate escript, module Elixir.BogusEscriptTest defined as :main_module could not be loaded"
@@ -446,4 +366,9 @@ defmodule Mix.Tasks.EscriptTest do
446
366
after
447
367
purge ( [ GitRepo , GitRepo.MixProject ] )
448
368
end
369
+
370
+ defp push_project_with_config ( module , config \\ [ ] ) do
371
+ Mix.ProjectStack . post_config ( config )
372
+ Mix.Project . push ( module )
373
+ end
449
374
end
0 commit comments