@@ -5,12 +5,6 @@ defmodule Mix.Tasks.CompileTest do
5
5
6
6
defmacro position ( line , column ) , do: { line , column }
7
7
8
- defmodule CustomCompilers do
9
- def project do
10
- [ compilers: [ :elixir , :app , :custom ] ]
11
- end
12
- end
13
-
14
8
defmodule DepsApp do
15
9
def project do
16
10
[ app: :deps_app , version: "0.1.0" , deps: [ { :ok , "0.1.0" , path: "deps/ok" } ] ]
@@ -23,7 +17,8 @@ defmodule Mix.Tasks.CompileTest do
23
17
end
24
18
end
25
19
26
- setup do
20
+ setup tags do
21
+ Mix.ProjectStack . post_config ( Map . get ( tags , :project , [ ] ) )
27
22
Mix.Project . push ( MixTest.Case.Sample )
28
23
:ok
29
24
end
@@ -37,17 +32,16 @@ defmodule Mix.Tasks.CompileTest do
37
32
assert_received { :mix_shell , :info , [ "mix compile.elixir # " <> _ ] }
38
33
end
39
34
35
+ @ tag project: [ compilers: [ :elixir , :app , :custom ] ]
40
36
test "compiles --list with custom mixfile" do
41
- Mix.Project . pop ( )
42
- Mix.Project . push ( CustomCompilers )
43
37
Mix.Task . run ( "compile" , [ "--list" ] )
44
38
assert_received { :mix_shell , :info , [ "\n Enabled compilers: elixir, app, custom, protocols" ] }
45
39
end
46
40
41
+ @ tag project: [ compilers: [ :elixir , :app , :custom ] ]
47
42
test "compiles does not require all compilers available on manifest" do
48
- Mix.Project . pop ( )
49
- Mix.Project . push ( CustomCompilers )
50
- assert Mix.Tasks.Compile . manifests ( ) |> Enum . map ( & Path . basename / 1 ) == [ "compile.elixir" ]
43
+ assert Mix.Tasks.Compile . manifests ( ) |> Enum . map ( & Path . basename / 1 ) ==
44
+ [ "compile.yecc" , "compile.leex" , "compile.elixir" ]
51
45
end
52
46
53
47
test "compiles a project with mixfile" do
@@ -101,6 +95,34 @@ defmodule Mix.Tasks.CompileTest do
101
95
end )
102
96
end
103
97
98
+ @ tag project: [ compilers: Mix . compilers ( ) ++ [ :my_custom_compiler ] ]
99
+ test "compiles a project with custom in-project compiler" do
100
+ in_fixture ( "no_mixfile" , fn ->
101
+ File . mkdir_p! ( "lib" )
102
+
103
+ File . write! ( "lib/a.ex" , """
104
+ defmodule Mix.Tasks.Compile.MyCustomCompiler do
105
+ use Mix.Task.Compiler
106
+
107
+ @impl true
108
+ def run(_args) do
109
+ Mix.shell().info("Compiling...")
110
+ :ok
111
+ end
112
+ end
113
+ """ )
114
+
115
+ assert Mix.Task . run ( "compile" ) == { :ok , [ ] }
116
+ assert_receive { :mix_shell , :info , [ "Compiling..." ] }
117
+ Code . delete_path ( Mix.Project . compile_path ( ) )
118
+ purge ( [ Mix.Tasks.Compile.MyCustomCompiler ] )
119
+ false = Code . ensure_loaded? ( Mix.Tasks.Compile.MyCustomCompiler )
120
+
121
+ Mix.Task . clear ( )
122
+ assert Mix.Task . rerun ( "compile" )
123
+ end )
124
+ end
125
+
104
126
test "recompiles app cache if manifest changes" do
105
127
in_fixture ( "no_mixfile" , fn ->
106
128
Mix.Tasks.Compile . run ( [ "--force" ] )
0 commit comments