@@ -155,11 +155,15 @@ defmodule IEx.HelpersTest do
155
155
end ) >= 2
156
156
end
157
157
158
+ defp purge ( mod ) do
159
+ true = :code . delete mod
160
+ :code . purge mod
161
+ end
162
+
158
163
defp cleanup_modules( mods) do
159
164
Enum. each mods , fn mod ->
160
165
File . rm! "#{ mod } .beam"
161
- true = :code . delete mod
162
- :code . purge mod
166
+ purge mod
163
167
end
164
168
end
165
169
@@ -183,7 +187,7 @@ defmodule IEx.HelpersTest do
183
187
Sample . run
184
188
end
185
189
186
- filename = "test-module-code .ex"
190
+ filename = "sample .ex"
187
191
with_file filename , test_module_code , fn ->
188
192
assert c ( filename ) == [ Sample ]
189
193
assert Sample . run == :run
@@ -197,7 +201,7 @@ defmodule IEx.HelpersTest do
197
201
Sample . run
198
202
end
199
203
200
- filename = "test-module-code .ex"
204
+ filename = "sample .ex"
201
205
with_file filename, test_module_code <> "\n " <> another_test_module , fn ->
202
206
assert c ( filename ) |> Enum . sort == [ Sample , Sample2 ]
203
207
assert Sample . run == :run
@@ -212,7 +216,7 @@ defmodule IEx.HelpersTest do
212
216
Sample . run
213
217
end
214
218
215
- filenames = [ "test-module-code-1 .ex" , "test-module-code-2 .ex" ]
219
+ filenames = [ "sample1 .ex" , "sample2 .ex" ]
216
220
with_file filenames , [ test_module_code , another_test_module ] , fn ->
217
221
assert c ( filenames ) |> Enum . sort == [ Sample , Sample2 ]
218
222
assert Sample . run == :run
@@ -229,14 +233,14 @@ defmodule IEx.HelpersTest do
229
233
230
234
assert l ( :non_existent_module ) == { :error , :nofile }
231
235
232
- filename = "test-module-code .ex"
236
+ filename = "sample .ex"
233
237
with_file filename, test_module_code , fn ->
234
238
assert c ( filename ) == [ Sample ]
235
239
assert Sample . run == :run
236
240
237
241
File . write! filename , "defmodule Sample do end"
238
242
# FIXME: is there another way to compile a file without loading its module?
239
- System . cmd "elixirc test-module-code .ex"
243
+ System . cmd "../../bin/ elixirc sample .ex"
240
244
241
245
assert l ( Sample ) == { :module , Sample }
242
246
assert_raise UndefinedFunctionError , "undefined function: Sample.run/0" , fn ->
@@ -249,25 +253,38 @@ defmodule IEx.HelpersTest do
249
253
cleanup_modules ( [ Sample ] )
250
254
end
251
255
252
- test "r helper" do
253
- assert_raise UndefinedFunctionError , "undefined function: Sample.run/0" , fn ->
254
- Sample . run
255
- end
256
-
256
+ test "r helper basic" do
257
257
assert r == [ ]
258
- assert r ( Kernel ) == :nosource
259
258
assert_raise UndefinedFunctionError , "undefined function: :non_existent_module.module_info/1" , fn ->
260
259
r :non_existent_module
261
260
end
262
261
263
- filename = "test- module-code.ex"
264
- with_file filename , test_module_code , fn ->
265
- assert c ( filename ) == [ Sample ]
266
- assert Sample . run == :run
267
- # FIXME: `r Sample` returns :nosource
268
- assert r ( Sample ) == [ Sample ]
262
+ # There is no source file for the module defined in IEx
263
+ assert ":ok \n ** (Code.LoadError) could not load" <> _
264
+ = capture_iex ( "{:module, Sample, _, {:run,0}} = #{ String . strip test_module_code } ; :ok \n r Sample" )
265
+ after
266
+ purge Sample
267
+ end
269
268
270
- assert r == [ Sample ]
269
+ test "r helper" do
270
+ assert_raise UndefinedFunctionError , "undefined function: Sample.run/0" , fn ->
271
+ Sample . run
272
+ end
273
+
274
+ filename = "sample.ex"
275
+ with_file filename , test_module_code , fn ->
276
+ assert capture_io ( :stdio , fn ->
277
+ assert c ( filename ) == [ Sample ]
278
+ assert Sample . run == :run
279
+
280
+ File . write! filename , "defmodule Sample do end"
281
+ assert { Sample , [ Sample ] } = r ( Sample )
282
+ assert_raise UndefinedFunctionError , "undefined function: Sample.run/0" , fn ->
283
+ Sample . run
284
+ end
285
+
286
+ assert [ Sample ] = r ( )
287
+ end ) =~ % r "^.+?sample\. ex:1: redefining module Sample\n .+?sample\. ex:1: redefining module Sample\n $"
271
288
end
272
289
after
273
290
# Clean up old version produced by the r helper
0 commit comments