1
- Code . require_file "../../test_helper.exs" , __DIR__
1
+ Code . require_file ( "../../test_helper.exs" , __DIR__ )
2
2
3
3
defmodule Mix.Tasks.Profile.FprofTest do
4
4
use MixTest.Case
@@ -11,38 +11,37 @@ defmodule Mix.Tasks.Profile.FprofTest do
11
11
test "profiles evaluated expression" , context do
12
12
in_tmp context . test , fn ->
13
13
assert capture_io ( fn ->
14
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" ] )
15
- end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
14
+ Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" ] )
15
+ end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
16
16
end
17
17
end
18
18
19
19
test "profiles the script" , context do
20
20
in_tmp context . test , fn ->
21
21
profile_script_name = "profile_script.ex"
22
22
23
- File . write! profile_script_name , """
23
+ File . write! ( profile_script_name , """
24
24
Enum.each(1..5, fn(_) -> MapSet.new end)
25
- """
25
+ """ )
26
26
27
27
assert capture_io ( fn ->
28
- Fprof . run ( [ profile_script_name ] )
29
- end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
28
+ Fprof . run ( [ profile_script_name ] )
29
+ end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
30
30
end
31
31
end
32
32
33
33
test "expands callers" , context do
34
34
in_tmp context . test , fn ->
35
35
assert capture_io ( fn ->
36
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--callers" ] )
37
- end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3} +<--)
36
+ Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--callers" ] )
37
+ end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3} +<--)
38
38
end
39
39
end
40
40
41
41
test "expands processes" , context do
42
42
in_tmp context . test , fn ->
43
- output = capture_io ( fn ->
44
- Fprof . run ( [ "-e" , "spawn(fn -> Process.sleep(:infinity) end); Enum.each(1..5, fn(_) -> MapSet.new end)" , "--details" ] )
45
- end )
43
+ expr = "spawn(fn -> Process.sleep(:infinity) end); Enum.each(1..5, fn(_) -> MapSet.new end)"
44
+ output = capture_io ( fn -> Fprof . run ( [ "-e" , expr , "--details" ] ) end )
46
45
assert output =~ ~r( #{ :erlang . pid_to_list ( self ( ) ) } +\d + +\d +\. \d {3})
47
46
assert output =~ ~r( spawned by #{ :erlang . pid_to_list ( self ( ) ) } )
48
47
assert output =~ ~r( as :erlang.apply)
@@ -52,46 +51,47 @@ defmodule Mix.Tasks.Profile.FprofTest do
52
51
53
52
test "sort options" , context do
54
53
in_tmp context . test , fn ->
55
- assert capture_io ( fn ->
56
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--sort" , "acc" ] )
57
- end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
54
+ expr = "Enum.each(1..5, fn(_) -> MapSet.new end)"
55
+ assert capture_io ( fn -> Fprof . run ( [ "-e" , expr , "--sort" , "acc" ] ) end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
58
56
59
- assert capture_io ( fn ->
60
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--sort" , "own" ] )
61
- end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
57
+ expr = "Enum.each(1..5, fn(_) -> MapSet.new end)"
58
+ assert capture_io ( fn -> Fprof . run ( [ "-e" , expr , "--sort" , "own" ] ) end ) =~ ~r( MapSet\. new/0 *5 *\d +\. \d {3} *\d +\. \d {3})
62
59
end
63
60
end
64
61
65
62
test "errors on missing files" , context do
66
63
in_tmp context . test , fn ->
67
- assert_raise Mix.Error , "No files matched pattern \" non-existent\" given to --require" , fn ->
68
- capture_io ( fn -> Fprof . run [ "-r" , "non-existent" ] end )
69
- end
64
+ message = "No files matched pattern \" non-existent\" given to --require"
70
65
71
- assert_raise Mix.Error , "No files matched pattern \" non-existent \" given to --require" , fn ->
72
- capture_io ( fn -> Fprof . run [ "-pr " , "non-existent" ] end )
73
- end
66
+ assert_raise Mix.Error , message , fn ->
67
+ capture_io ( fn -> Fprof . run ( [ "-r " , "non-existent" ] ) end )
68
+ end
74
69
70
+ assert_raise Mix.Error , message , fn ->
71
+ capture_io ( fn -> Fprof . run ( [ "-pr" , "non-existent" ] ) end )
72
+ end
73
+
75
74
assert_raise Mix.Error , "No such file: non-existent" , fn ->
76
- capture_io ( fn -> Fprof . run [ "non-existent" ] end )
75
+ capture_io ( fn -> Fprof . run ( [ "non-existent" ] ) end )
77
76
end
78
77
79
78
File . mkdir_p! ( "lib" )
79
+
80
80
assert_raise Mix.Error , "No such file: lib" , fn ->
81
- capture_io ( fn -> Fprof . run [ "lib" ] end )
81
+ capture_io ( fn -> Fprof . run ( [ "lib" ] ) end )
82
82
end
83
83
end
84
84
end
85
85
86
86
test "warmup" , context do
87
87
in_tmp context . test , fn ->
88
88
assert capture_io ( fn ->
89
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" ] )
90
- end ) =~ "Warmup..."
89
+ Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" ] )
90
+ end ) =~ "Warmup..."
91
91
92
92
refute capture_io ( fn ->
93
- Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--no-warmup" ] )
94
- end ) =~ "Warmup..."
93
+ Fprof . run ( [ "-e" , "Enum.each(1..5, fn(_) -> MapSet.new end)" , "--no-warmup" ] )
94
+ end ) =~ "Warmup..."
95
95
end
96
96
end
97
97
end
0 commit comments