Skip to content

Commit 4a1dfcc

Browse files
committed
Use =~ with strings where it makes sense
1 parent c62a7e1 commit 4a1dfcc

File tree

12 files changed

+97
-91
lines changed

12 files changed

+97
-91
lines changed

lib/elixir/test/elixir/exception_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ defmodule Kernel.ExceptionTest do
3434
end
3535

3636
test :format_stacktrace_entry_with_fun do
37-
assert Exception.format_stacktrace_entry({fn(x) -> x end, [1], []}) =~ %r"\(1\)"
38-
assert Exception.format_stacktrace_entry({fn(x, y) -> { x, y } end, 2, []}) =~ %r"/2"
37+
assert Exception.format_stacktrace_entry({fn(x) -> x end, [1], []}) =~ %r/#Function<.+>\(1\)/
38+
assert Exception.format_stacktrace_entry({fn(x, y) -> { x, y } end, 2, []}) =~ %r"#Function<.+>/2"
3939
end
4040

4141
test :format_module_function_arity do

lib/elixir/test/elixir/hash_dict_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ defmodule HashDictTest do
165165
end
166166

167167
test :inspect do
168-
assert inspect(filled_dict(8)) =~ %r"#HashDict<"
168+
assert inspect(filled_dict(8)) =~ "#HashDict<"
169169
end
170170

171171
test :small_range_merge do

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Kernel.WarningTest do
1212
def hello(arg), do: nil
1313
end
1414
"""
15-
end) =~ %r"variable arg is unused"
15+
end) =~ "variable arg is unused"
1616
after
1717
purge Sample
1818
end
@@ -24,7 +24,7 @@ defmodule Kernel.WarningTest do
2424
defp hello, do: nil
2525
end
2626
"""
27-
end) =~ %r"function hello/0 is unused"
27+
end) =~ "function hello/0 is unused"
2828

2929
assert capture_io(fn ->
3030
Code.eval_string """
@@ -33,7 +33,7 @@ defmodule Kernel.WarningTest do
3333
defp hello(1), do: :ok
3434
end
3535
"""
36-
end) =~ %r"function hello/1 is unused"
36+
end) =~ "function hello/1 is unused"
3737

3838
assert capture_io(fn ->
3939
Code.eval_string """
@@ -44,7 +44,7 @@ defmodule Kernel.WarningTest do
4444
defp d(x), do: x
4545
end
4646
"""
47-
end) =~ %r"function c/2 is unused"
47+
end) =~ "function c/2 is unused"
4848

4949
after
5050
purge [Sample1, Sample2, Sample3]
@@ -58,7 +58,7 @@ defmodule Kernel.WarningTest do
5858
defp b, do: a
5959
end
6060
"""
61-
end) =~ %r"function a/0 is unused"
61+
end) =~ "function a/0 is unused"
6262
after
6363
purge Sample
6464
end
@@ -70,7 +70,7 @@ defmodule Kernel.WarningTest do
7070
defmacrop hello, do: nil
7171
end
7272
"""
73-
end) =~ %r"macro hello/0 is unused"
73+
end) =~ "macro hello/0 is unused"
7474
after
7575
purge Sample
7676
end
@@ -83,7 +83,7 @@ defmodule Kernel.WarningTest do
8383
defp b(arg1 // 1, arg2 // 2, arg3 // 3), do: [arg1, arg2, arg3]
8484
end
8585
"""
86-
end) =~ %r"default arguments in b/3 are never used"
86+
end) =~ "default arguments in b/3 are never used"
8787

8888
assert capture_io(fn ->
8989
Code.eval_string """
@@ -92,7 +92,7 @@ defmodule Kernel.WarningTest do
9292
defp b(arg1 // 1, arg2 // 2, arg3 // 3), do: [arg1, arg2, arg3]
9393
end
9494
"""
95-
end) =~ %r"the first 2 default arguments in b/3 are never used"
95+
end) =~ "the first 2 default arguments in b/3 are never used"
9696

9797
assert capture_io(fn ->
9898
Code.eval_string """
@@ -101,7 +101,7 @@ defmodule Kernel.WarningTest do
101101
defp b(arg1 // 1, arg2 // 2, arg3 // 3), do: [arg1, arg2, arg3]
102102
end
103103
"""
104-
end) =~ %r"the first default argument in b/3 is never used"
104+
end) =~ "the first default argument in b/3 is never used"
105105

106106
assert capture_io(fn ->
107107
Code.eval_string """
@@ -127,7 +127,7 @@ defmodule Kernel.WarningTest do
127127
def a, do: nil
128128
end
129129
"""
130-
end) =~ %r"unused import Sample1"
130+
end) =~ "unused import Sample1"
131131
after
132132
purge [Sample1, Sample2]
133133
end
@@ -140,7 +140,7 @@ defmodule Kernel.WarningTest do
140140
def hello, do: nil
141141
end
142142
"""
143-
end) =~ %r"this clause cannot match because a previous clause at line 2 always matches"
143+
end) =~ "this clause cannot match because a previous clause at line 2 always matches"
144144
after
145145
purge Sample
146146
end
@@ -153,7 +153,7 @@ defmodule Kernel.WarningTest do
153153
def hello(arg // 0), do: nil
154154
end
155155
"""
156-
end) =~ %r"clause with defaults should be the first clause in def hello/1"
156+
end) =~ "clause with defaults should be the first clause in def hello/1"
157157
after
158158
purge Sample
159159
end
@@ -166,7 +166,7 @@ defmodule Kernel.WarningTest do
166166
def hello(arg // 1), do: nil
167167
end
168168
"""
169-
end) =~ %r"def hello/1 has default values and multiple clauses, use a separate clause for declaring defaults"
169+
end) =~ "def hello/1 has default values and multiple clauses, use a separate clause for declaring defaults"
170170
after
171171
purge Sample
172172
end
@@ -181,7 +181,7 @@ defmodule Kernel.WarningTest do
181181
def hello, do: :ok
182182
end
183183
"""
184-
end) =~ %r"function world/0 is unused"
184+
end) =~ "function world/0 is unused"
185185
after
186186
purge Sample
187187
end

lib/ex_unit/test/ex_unit/cli_formatter_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ defmodule ExUnit.CLIFormatterTest do
2525
"""
2626

2727
out_put = exec_test("raising_test.exs")
28-
assert out_put =~ %r/stacktrace:/
29-
refute out_put =~ %r/ExUnit\.Runner/
28+
assert out_put =~ "stacktrace:"
29+
refute out_put =~ "ExUnit.Runner"
3030
after
3131
File.rm("raising_test.exs")
3232
end
@@ -44,7 +44,7 @@ defmodule ExUnit.CLIFormatterTest do
4444
"""
4545

4646
out_put = exec_test("failure_test.exs")
47-
assert out_put =~ %r/at failure_test.exs:6/
47+
assert out_put =~ "at failure_test.exs:6"
4848
after
4949
File.rm("failure_test.exs")
5050
end

lib/mix/test/mix/cli_test.exs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ defmodule Mix.CLITest do
66
test "env" do
77
in_fixture "custom_mixfile", fn ->
88
env = System.cmd %b(MIX_ENV=prod #{elixir_executable} #{mix_executable} run "IO.puts Mix.env")
9-
assert env =~ %r"prod"
9+
assert env =~ "prod"
1010
end
1111
end
1212

1313
test "default task" do
1414
in_fixture "custom_mixfile", fn ->
1515
output = mix ""
1616
assert File.regular?("ebin/Elixir.A.beam")
17-
assert output =~ %r"Compiled lib/a.ex"
17+
assert output =~ "Compiled lib/a.ex"
1818
end
1919
end
2020

@@ -32,86 +32,86 @@ defmodule Mix.CLITest do
3232
assert File.regular?("ebin/Elixir.B.beam")
3333
assert File.regular?("ebin/Elixir.C.beam")
3434

35-
assert output =~ %r"Compiled lib/a\.ex"
35+
assert output =~ "Compiled lib/a.ex"
3636
end
3737
end
3838

3939
test "test smoke test" do
4040
in_fixture "custom_mixfile", fn ->
4141
output = mix "test"
4242
assert File.regular?("ebin/Elixir.A.beam")
43-
assert output =~ %r"1 tests, 0 failures"
43+
assert output =~ "1 tests, 0 failures"
4444

4545
output = mix "test test/hidden.ex --cover cover"
46-
assert output =~ %r"1 tests, 1 failures"
47-
assert output =~ %r"Generating cover results ... ok"
46+
assert output =~ "1 tests, 1 failures"
47+
assert output =~ "Generating cover results ... ok"
4848
assert File.regular?("cover/Elixir.A.html")
4949
end
5050
end
5151

5252
test "help smoke test" do
5353
in_fixture "only_mixfile", fn ->
5454
output = mix "help"
55-
assert output =~ %r"mix compile\s+# Compile source files"
56-
assert output =~ %r"mix hello\s+# Hello"
57-
refute output =~ %r"mix invalid"
55+
assert output =~ %r/mix compile\s+# Compile source files/
56+
assert output =~ %r/mix hello\s+# Hello/
57+
refute output =~ "mix invalid"
5858
end
5959
end
6060

6161
test "--help smoke test" do
6262
in_fixture "only_mixfile", fn ->
6363
output = mix "--help"
64-
assert output =~ %r"mix compile\s+# Compile source files"
65-
refute output =~ %r"mix invalid"
64+
assert output =~ %r/mix compile\s+# Compile source files/
65+
refute output =~ "mix invalid"
6666
end
6767
end
6868

6969
test "--version smoke test" do
7070
in_fixture "only_mixfile", fn ->
7171
output = mix "--version"
72-
assert output =~ %r"Elixir [0-9\.a-z]+"
73-
refute output =~ %r"Something silly"
72+
assert output =~ %r/Elixir [0-9\.a-z]+/
73+
refute output =~ "Something silly"
7474
end
7575
end
7676

7777
test "help TASK smoke test" do
7878
in_fixture "only_mixfile", fn ->
7979
output = mix "help compile"
80-
assert output =~ %r"# mix help compile"
81-
assert output =~ %r"## Command line options"
82-
assert output =~ %r"^Location:"m
80+
assert output =~ "# mix help compile"
81+
assert output =~ "## Command line options"
82+
assert output =~ %r/^Location:/m
8383
end
8484
end
8585

8686
test "do smoke test" do
8787
in_fixture "only_mixfile", fn ->
8888
output = mix "do compile --list, help compile"
89-
assert output =~ %r"# mix help compile"
90-
assert output =~ %r"mix compile.elixir #"
89+
assert output =~ "# mix help compile"
90+
assert output =~ "mix compile.elixir #"
9191
end
9292
end
9393

9494
test "new with tests smoke test" do
9595
in_tmp "new_with_tests", fn ->
9696
output = mix "new ."
97-
assert output =~ %r(\* creating lib/new_with_tests.ex)
97+
assert output =~ "* creating lib/new_with_tests.ex"
9898

9999
output = mix "test"
100100
assert File.regular?("ebin/Elixir.NewWithTests.beam")
101-
assert output =~ %r"1 tests, 0 failures"
101+
assert output =~ "1 tests, 0 failures"
102102
end
103103
end
104104

105105
test "new --sup with tests smoke test" do
106106
in_tmp "new_with_tests", fn ->
107107
output = mix "new . --sup"
108-
assert output =~ %r(\* creating lib/new_with_tests.ex)
109-
assert output =~ %r(\* creating lib/new_with_tests/supervisor.ex)
108+
assert output =~ "* creating lib/new_with_tests.ex"
109+
assert output =~ "* creating lib/new_with_tests/supervisor.ex"
110110

111111
output = mix "test"
112112
assert File.regular?("ebin/Elixir.NewWithTests.beam")
113-
assert output =~ %r"1 tests, 0 failures"
113+
assert output =~ "1 tests, 0 failures"
114114
end
115115
end
116116

117-
end
117+
end

lib/mix/test/mix/generator_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule Mix.GeneratorTest do
1818
end
1919

2020
test :from_file do
21-
assert self_text =~ %r/import Mix\.Generator/
21+
assert self_text =~ "import Mix.Generator"
2222
end
2323

2424
test :create_file do
@@ -54,4 +54,4 @@ defmodule Mix.GeneratorTest do
5454
assert_received { :mix_shell, :yes?, [^msg] }
5555
end
5656
end
57-
end
57+
end

lib/mix/test/mix/tasks/compile.app_test.exs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ defmodule Mix.Tasks.Compile.AppTest do
4646
assert Mix.Tasks.Compile.App.run([]) == :ok
4747

4848
contents = File.read!("ebin/simple_project.app")
49-
assert contents =~ %r/\{application,simple_project/
50-
assert contents =~ %r/0.1.0/
51-
assert contents =~ %r/'Elixir.A'/
52-
assert contents =~ %r/\{applications,\[kernel,stdlib,elixir\]\}/
49+
assert contents =~ "{application,simple_project"
50+
assert contents =~ "0.1.0"
51+
assert contents =~ "'Elixir.A'"
52+
assert contents =~ "{applications,[kernel,stdlib,elixir]}"
5353

5454
assert Mix.Tasks.Compile.App.run([]) == :noop
5555
end
@@ -65,8 +65,8 @@ defmodule Mix.Tasks.Compile.AppTest do
6565
Mix.Tasks.Compile.Elixir.run([])
6666
Mix.Tasks.Compile.App.run([])
6767
contents = File.read!("ebin/custom_project.app")
68-
assert contents =~ %r/0.2.0/
69-
assert contents =~ %r/{maxT,infinity}/
68+
assert contents =~ "0.2.0"
69+
assert contents =~ "{maxT,infinity}"
7070
end
7171
after
7272
purge [A, B, C]
@@ -82,13 +82,21 @@ defmodule Mix.Tasks.Compile.AppTest do
8282
Process.put(:error, error)
8383
e = catch_error(Mix.Tasks.Compile.App.run([]))
8484
assert Mix.Error[] = e
85-
assert e.message =~ %r/:#{error}/
86-
assert e.message =~ %r/#{inspect InvalidProject.application[error]}/
85+
assert e.message =~ ":#{error}"
86+
87+
err_token = InvalidProject.application[error]
88+
cond do
89+
is_list(err_token) ->
90+
[tok] = err_token
91+
assert e.message =~ inspect(tok)
92+
true ->
93+
assert e.message =~ inspect(err_token)
94+
end
8795
end
8896
Process.delete(:error)
8997
end
9098
after
91-
purge [A, B, C]
99+
purge [A, B, C]
92100
Mix.Project.pop
93101
end
94102

@@ -102,12 +110,12 @@ defmodule Mix.Tasks.Compile.AppTest do
102110
{:ok, [{_app, _, properties}]} = :file.consult("ebin/simple_project.app")
103111
properties = Keyword.from_enum(properties)
104112
assert properties[:registered] == []
105-
assert properties[:description] == 'simple_project'
113+
assert properties[:description] == 'simple_project'
106114

107115
assert Mix.Tasks.Compile.App.run([]) == :noop
108116
end
109117
after
110118
purge [A, B, C]
111119
Mix.Project.pop
112-
end
113-
end
120+
end
121+
end

0 commit comments

Comments
 (0)