@@ -5,7 +5,7 @@ import PathHelpers
5
5
defmodule Kernel.CLI.InitTest do
6
6
use ExUnit.Case , async: true
7
7
8
- test :code_init do
8
+ test "handles code on initialization" do
9
9
assert elixir ( '-e "IO.puts [?3]"' ) == '3\n '
10
10
11
11
result = elixir ( '-e "IO.puts inspect(System.argv)" #{ fixture_path ( "init_sample.exs" ) } -o 1 2 3' )
16
16
defmodule Kernel.CLI.OptionParsingTest do
17
17
use ExUnit.Case , async: true
18
18
19
- test :path do
19
+ test "properly parses paths" do
20
20
root = fixture_path ( "../../.." ) |> to_char_list
21
21
list = elixir ( '-pa "#{ root } /*" -pz "#{ root } /lib/*" -e "IO.inspect(:code.get_path, limit: :infinity)"' )
22
22
{ path , _ } = Code . eval_string list , [ ]
34
34
defmodule Kernel.CLI.AtExitTest do
35
35
use ExUnit.Case , async: true
36
36
37
- test : at_exit do
37
+ test "invokes at_exit callbacks" do
38
38
assert elixir ( fixture_path ( "at_exit.exs" ) |> to_char_list ) ==
39
39
'goodbye cruel world with status 0\n '
40
40
end
43
43
defmodule Kernel.CLI.ErrorTest do
44
44
use ExUnit.Case , async: true
45
45
46
- test :code_error do
46
+ test "properly format errors" do
47
47
assert :string . str ( '** (throw) 1' , elixir ( '-e "throw 1"' ) ) == 0
48
48
assert :string . str ( '** (ErlangError) erlang error: 1' , elixir ( '-e "error 1"' ) ) == 0
49
49
@@ -52,32 +52,18 @@ defmodule Kernel.CLI.ErrorTest do
52
52
end
53
53
end
54
54
55
- defmodule Kernel.CLI.SyntaxErrorTest do
56
- use ExUnit.Case , async: true
57
-
58
- defp check_output ( elixir_cmd , expected_msg ) do
59
- o = elixir ( elixir_cmd )
60
- assert :string . str ( o , expected_msg ) == 1 , "Expected this output: `#{ expected_msg } `\n but got this output: `#{ o } `"
61
- end
62
-
63
- test :syntax_code_error do
64
- check_output ( '-e "[1,2"' , '** (TokenMissingError) nofile:1: missing terminator: ]' )
65
- check_output ( '-e "case 1 end"' , % C "** (SyntaxError) nofile:1: unexpected token: end" )
66
- end
67
- end
68
-
69
55
defmodule Kernel.CLI.CompileTest do
70
56
use ExUnit.Case , async: true
71
57
72
- test :compile_code do
58
+ test "compiles code" do
73
59
fixture = fixture_path "compile_sample.ex"
74
60
assert elixirc ( '#{ fixture } -o #{ tmp_path } ' ) == ''
75
61
assert File . regular? ( tmp_path "Elixir.CompileSample.beam" )
76
62
after
77
63
File . rm ( tmp_path ( "Elixir.CompileSample.beam" ) )
78
64
end
79
65
80
- test :compile_code_verbose do
66
+ test "compiles code with verbose mode" do
81
67
fixture = fixture_path "compile_sample.ex"
82
68
assert elixirc ( '#{ fixture } -o #{ tmp_path } --verbose' ) ==
83
69
'Compiled #{ fixture } \n '
@@ -86,16 +72,7 @@ defmodule Kernel.CLI.CompileTest do
86
72
File . rm ( tmp_path ( "Elixir.CompileSample.beam" ) )
87
73
end
88
74
89
- test :possible_deadlock do
90
- output = elixirc ( '#{ fixture_path ( "parallel_deadlock" ) } -o #{ tmp_path } ' )
91
- foo = '* #{ fixture_path "parallel_deadlock/foo.ex" } is missing module Bar'
92
- bar = '* #{ fixture_path "parallel_deadlock/bar.ex" } is missing module Foo'
93
- assert :string . str ( output , foo ) > 0 , "expected foo.ex to miss module Bar"
94
- assert :string . str ( output , bar ) > 0 , "expected bar.ex to miss module Foo"
95
- assert :string . str ( output , 'elixir_compiler' ) == 0 , "expected elixir_compiler to not be in output"
96
- end
97
-
98
- test :compile_missing_patterns do
75
+ test "fails on missing patterns" do
99
76
fixture = fixture_path "compile_sample.ex"
100
77
output = elixirc ( '#{ fixture } non_existing.ex -o #{ tmp_path } ' )
101
78
assert :string . str ( output , 'non_existing.ex' ) > 0 , "expected non_existing.ex to be mentionned"
@@ -108,14 +85,36 @@ defmodule Kernel.CLI.ParallelCompilerTest do
108
85
use ExUnit.Case
109
86
import ExUnit.CaptureIO
110
87
111
- test : files do
88
+ test "compiles files solving dependencies" do
112
89
fixtures = [ fixture_path ( "parallel_compiler/bar.ex" ) , fixture_path ( "parallel_compiler/foo.ex" ) ]
113
90
assert capture_io ( fn ->
114
91
assert [ Bar , Foo ] = Kernel.ParallelCompiler . files fixtures
115
92
end ) =~ "message_from_foo"
116
93
end
117
94
118
- test :warnings_as_errors do
95
+ test "does not hang on missing dependencies" do
96
+ fixtures = [ fixture_path ( "parallel_compiler/bat.ex" ) ]
97
+ assert capture_io ( fn ->
98
+ assert_raise CompileError , fn ->
99
+ Kernel.ParallelCompiler . files fixtures
100
+ end
101
+ end ) =~ "Compilation error"
102
+ end
103
+
104
+ test "handles possible deadlocks" do
105
+ fixtures = [ fixture_path ( "parallel_deadlock/foo.ex" ) , fixture_path ( "parallel_deadlock/bar.ex" ) ]
106
+
107
+ msg = capture_io ( fn ->
108
+ assert_raise UndefinedFunctionError , fn ->
109
+ Kernel.ParallelCompiler . files fixtures
110
+ end
111
+ end )
112
+
113
+ assert msg =~ "* #{ fixture_path "parallel_deadlock/foo.ex" } is missing module Bar"
114
+ assert msg =~ "* #{ fixture_path "parallel_deadlock/bar.ex" } is missing module Foo"
115
+ end
116
+
117
+ test "warnings_as_errors" do
119
118
warnings_as_errors = Code . compiler_options [ :warnings_as_errors ]
120
119
121
120
try do
0 commit comments