Skip to content

Commit cc954b2

Browse files
committed
Adapt mix gradient tests to use _build dir
1 parent c45a0c7 commit cc954b2

File tree

1 file changed

+31
-51
lines changed

1 file changed

+31
-51
lines changed

test/mix/tasks/gradient_test.exs

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,56 @@ defmodule Mix.Tasks.GradientTest do
55

66
@no_problems_msg "No problems found!"
77

8-
@examples_path "test/examples/"
9-
@type_path Path.join([@examples_path, "type"])
8+
@examples_path "test/examples"
9+
@build_path Path.join([@examples_path, "_build"])
1010

11-
@s_wrong_ret_beam "Elixir.SWrongRet.beam"
12-
@s_wrong_ret_ex "s_wrong_ret.ex"
11+
@s_wrong_ret_beam Path.join(@build_path, "Elixir.SWrongRet.beam")
12+
@s_wrong_ret_ex Path.join([@examples_path, "type", "s_wrong_ret.ex"])
1313

1414
test "--no-compile option" do
1515
info = "Compiling project..."
1616

17-
output = run_task(@type_path, [@s_wrong_ret_beam])
17+
output = run_task([@s_wrong_ret_beam])
1818
assert String.contains?(output, info)
1919

20-
dir = Path.join(@type_path, "_build")
21-
:os.cmd(String.to_charlist("rm -Rf " <> dir))
22-
23-
output = run_task(@type_path, ["--no-compile", "--", @s_wrong_ret_beam])
20+
output = run_task(["--no-compile", "--", @s_wrong_ret_beam])
2421
assert not String.contains?(output, info)
2522
end
2623

2724
test "path to the beam file" do
28-
output = run_task(@type_path, test_opts([@s_wrong_ret_beam]))
25+
output = run_task(test_opts([@s_wrong_ret_beam]))
2926
assert 3 == String.split(output, @s_wrong_ret_ex) |> length()
3027
end
3128

3229
test "path to the ex file" do
33-
output = run_task(@type_path, test_opts([@s_wrong_ret_ex]))
30+
output = run_task(test_opts([@s_wrong_ret_ex]))
3431
assert 3 == String.split(output, @s_wrong_ret_ex) |> length()
3532
end
3633

3734
test "no_fancy option" do
38-
output = run_task(@type_path, test_opts([@s_wrong_ret_beam]))
35+
output = run_task(test_opts([@s_wrong_ret_beam]))
3936
assert String.contains?(output, "The integer on line")
4037
assert String.contains?(output, "The tuple on line")
4138

42-
output = run_task(@type_path, test_opts(["--no-fancy", "--", @s_wrong_ret_beam]))
39+
output = run_task(test_opts(["--no-fancy", "--", @s_wrong_ret_beam]))
4340
assert String.contains?(output, "The integer \e[33m1\e[0m on line")
4441
assert String.contains?(output, "The tuple \e[33m{:ok, []}\e[0m on line")
4542
end
4643

4744
describe "colors" do
4845
test "no_colors option" do
49-
output = run_task(@type_path, test_opts([@s_wrong_ret_beam]))
46+
output = run_task(test_opts([@s_wrong_ret_beam]))
5047
assert String.contains?(output, IO.ANSI.cyan())
5148
assert String.contains?(output, IO.ANSI.red())
5249

53-
output = run_task(@type_path, test_opts(["--no-colors", "--", @s_wrong_ret_beam]))
50+
output = run_task(test_opts(["--no-colors", "--", @s_wrong_ret_beam]))
5451
assert not String.contains?(output, IO.ANSI.cyan())
5552
assert not String.contains?(output, IO.ANSI.red())
5653
end
5754

5855
test "--expr-color and --type-color option" do
5956
output =
6057
run_task(
61-
@type_path,
6258
test_opts([
6359
"--no-fancy",
6460
"--expr-color",
@@ -77,7 +73,6 @@ defmodule Mix.Tasks.GradientTest do
7773
test "--underscore_color option" do
7874
output =
7975
run_task(
80-
@type_path,
8176
test_opts([
8277
"--underscore-color",
8378
"green",
@@ -92,51 +87,50 @@ defmodule Mix.Tasks.GradientTest do
9287
end
9388

9489
test "--no-gradualizer-check option" do
95-
output = run_task(@type_path, test_opts(["--no-gradualizer-check", "--", @s_wrong_ret_beam]))
90+
output = run_task(test_opts(["--no-gradualizer-check", "--", @s_wrong_ret_beam]))
9691

9792
assert String.contains?(output, "No problems found!")
9893
end
9994

10095
test "--no-ex-check option" do
101-
beam = "Elixir.SpecAfterSpec.beam"
102-
ex_spec_error_msg = "The spec convert_a/1 on line"
96+
beam = Path.join(@build_path, "Elixir.SpecAfterSpec.beam")
97+
ex_spec_error_msg = "The spec convert/1 on line"
10398

104-
output = run_task(@examples_path, test_opts([beam]))
99+
output = run_task(test_opts([beam]))
105100
assert String.contains?(output, ex_spec_error_msg)
106101

107-
output = run_task(@examples_path, test_opts(["--no-ex-check", "--", beam]))
102+
output = run_task(test_opts(["--no-ex-check", "--", beam]))
108103
assert not String.contains?(output, ex_spec_error_msg)
109104
end
110105

111106
@tag if(System.version() >= "1.13", do: :skip, else: :ok)
112107
test "--no-specify option" do
113-
output = run_task(@type_path, test_opts([@s_wrong_ret_beam]))
108+
output = run_task(test_opts([@s_wrong_ret_beam]))
114109
assert String.contains?(output, "on line 3")
115110
assert String.contains?(output, "on line 6")
116111

117-
output = run_task(@type_path, test_opts(["--no-specify", "--", @s_wrong_ret_beam]))
112+
output = run_task(test_opts(["--no-specify", "--", @s_wrong_ret_beam]))
118113
assert String.contains?(output, "on line 0")
119114
assert not String.contains?(output, "on line 3")
120115
assert not String.contains?(output, "on line 6")
121116
end
122117

123118
test "--stop-on-first-error option" do
124-
output = run_task(@type_path, test_opts(["--stop-on-first-error", "--", @s_wrong_ret_beam]))
119+
output = run_task(test_opts(["--stop-on-first-error", "--", @s_wrong_ret_beam]))
125120

126121
assert 2 == String.split(output, @s_wrong_ret_ex) |> length()
127122
end
128123

129124
test "--fmt-location option" do
130-
output = run_task(@type_path, test_opts(["--fmt-location", "none", "--", @s_wrong_ret_beam]))
125+
output = run_task(test_opts(["--fmt-location", "none", "--", @s_wrong_ret_beam]))
131126

132127
assert String.contains?(output, "s_wrong_ret.ex: The integer is expected to have type")
133128

134-
output = run_task(@type_path, test_opts(["--fmt-location", "brief", "--", @s_wrong_ret_beam]))
129+
output = run_task(test_opts(["--fmt-location", "brief", "--", @s_wrong_ret_beam]))
135130

136131
assert String.contains?(output, "s_wrong_ret.ex:3: The integer is expected to have type")
137132

138-
output =
139-
run_task(@type_path, test_opts(["--fmt-location", "verbose", "--", @s_wrong_ret_beam]))
133+
output = run_task(test_opts(["--fmt-location", "verbose", "--", @s_wrong_ret_beam]))
140134

141135
assert String.contains?(
142136
output,
@@ -147,47 +141,33 @@ defmodule Mix.Tasks.GradientTest do
147141
test "--no-deps option" do
148142
info = "Loading deps..."
149143

150-
output = run_task(@type_path, ["--no-compile", "--", @s_wrong_ret_beam])
144+
output = run_task(["--no-compile", "--", @s_wrong_ret_beam])
151145
assert String.contains?(output, info)
152146

153-
output = run_task(@type_path, ["--no-compile", "--no-deps", "--", @s_wrong_ret_beam])
147+
output = run_task(["--no-compile", "--no-deps", "--", @s_wrong_ret_beam])
154148
assert not String.contains?(output, info)
155149
end
156150

157151
test "--infer option" do
158-
beam = "Elixir.ListInfer.beam"
159-
output = run_task(@type_path, test_opts([beam]))
152+
beam = Path.join(@build_path, "Elixir.ListInfer.beam")
153+
output = run_task(test_opts([beam]))
160154
assert String.contains?(output, @no_problems_msg)
161155

162-
output = run_task(@type_path, test_opts(["--infer", "--", beam]))
156+
output = run_task(test_opts(["--infer", "--", beam]))
163157
assert not String.contains?(output, @no_problems_msg)
164158
assert String.contains?(output, "list_infer.ex: The variable on line 4")
165159
end
166160

167161
test "--code-path option" do
168162
ex_file = "wrong_ret.ex"
169163

170-
output = run_task(@type_path, test_opts(["--code-path", ex_file, "--", @s_wrong_ret_beam]))
164+
output = run_task(test_opts(["--code-path", ex_file, "--", @s_wrong_ret_beam]))
171165

172166
assert not String.contains?(output, @s_wrong_ret_ex)
173167
assert String.contains?(output, ex_file)
174168
end
175169

176-
def run_task(rel_path, args) do
177-
run_in_path(rel_path, fn ->
178-
capture_io(fn -> Mix.Tasks.Gradient.run(args) end)
179-
end)
180-
end
170+
def run_task(args), do: capture_io(fn -> Mix.Tasks.Gradient.run(args) end)
181171

182-
def run_in_path(path, fun) do
183-
cwd = File.cwd!()
184-
File.cd(path)
185-
res = fun.()
186-
File.cd(cwd)
187-
res
188-
end
189-
190-
def test_opts(opts) do
191-
["--no-comile", "--no-deps"] ++ opts
192-
end
172+
def test_opts(opts), do: ["--no-comile", "--no-deps"] ++ opts
193173
end

0 commit comments

Comments
 (0)