Skip to content

Run formatter on lib/test/mix/tasks/profile.fprof_test.exs #6794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions lib/mix/test/mix/tasks/profile.fprof_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code.require_file "../../test_helper.exs", __DIR__
Code.require_file("../../test_helper.exs", __DIR__)

defmodule Mix.Tasks.Profile.FprofTest do
use MixTest.Case
Expand All @@ -11,38 +11,37 @@ defmodule Mix.Tasks.Profile.FprofTest do
test "profiles evaluated expression", context do
in_tmp context.test, fn ->
assert capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
end
end

test "profiles the script", context do
in_tmp context.test, fn ->
profile_script_name = "profile_script.ex"

File.write! profile_script_name, """
File.write!(profile_script_name, """
Enum.each(1..5, fn(_) -> MapSet.new end)
"""
""")

assert capture_io(fn ->
Fprof.run([profile_script_name])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
Fprof.run([profile_script_name])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
end
end

test "expands callers", context do
in_tmp context.test, fn ->
assert capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--callers"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3} +<--)
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--callers"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3} +<--)
end
end

test "expands processes", context do
in_tmp context.test, fn ->
output = capture_io(fn ->
Fprof.run(["-e", "spawn(fn -> Process.sleep(:infinity) end); Enum.each(1..5, fn(_) -> MapSet.new end)", "--details"])
end)
expr = "spawn(fn -> Process.sleep(:infinity) end); Enum.each(1..5, fn(_) -> MapSet.new end)"
output =capture_io(fn -> Fprof.run(["-e",expr,"--details"]) end)
assert output =~ ~r(#{:erlang.pid_to_list(self())} +\d+ +\d+\.\d{3})
assert output =~ ~r(spawned by #{:erlang.pid_to_list(self())})
assert output =~ ~r(as :erlang.apply)
Expand All @@ -52,46 +51,47 @@ defmodule Mix.Tasks.Profile.FprofTest do

test "sort options", context do
in_tmp context.test, fn ->
assert capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--sort", "acc"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
expr = "Enum.each(1..5, fn(_) -> MapSet.new end)"
assert capture_io(fn -> Fprof.run(["-e",expr, "--sort", "acc"]) end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})

assert capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--sort", "own"])
end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
expr = "Enum.each(1..5, fn(_) -> MapSet.new end)"
assert capture_io(fn -> Fprof.run(["-e",expr, "--sort", "own"]) end) =~ ~r(MapSet\.new/0 *5 *\d+\.\d{3} *\d+\.\d{3})
end
end

test "errors on missing files", context do
in_tmp context.test, fn ->
assert_raise Mix.Error, "No files matched pattern \"non-existent\" given to --require", fn ->
capture_io(fn -> Fprof.run ["-r", "non-existent"] end)
end
message = "No files matched pattern \"non-existent\" given to --require"

assert_raise Mix.Error, "No files matched pattern \"non-existent\" given to --require", fn ->
capture_io(fn -> Fprof.run ["-pr", "non-existent"] end)
end
assert_raise Mix.Error,message,fn ->
capture_io(fn -> Fprof.run(["-r", "non-existent"]) end)
end

assert_raise Mix.Error,message,fn ->
capture_io(fn -> Fprof.run(["-pr", "non-existent"]) end)
end

assert_raise Mix.Error, "No such file: non-existent", fn ->
capture_io(fn -> Fprof.run ["non-existent"] end)
capture_io(fn -> Fprof.run(["non-existent"]) end)
end

File.mkdir_p!("lib")

assert_raise Mix.Error, "No such file: lib", fn ->
capture_io(fn -> Fprof.run ["lib"] end)
capture_io(fn -> Fprof.run(["lib"]) end)
end
end
end

test "warmup", context do
in_tmp context.test, fn ->
assert capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)"])
end) =~ "Warmup..."
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)"])
end) =~ "Warmup..."

refute capture_io(fn ->
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--no-warmup"])
end) =~ "Warmup..."
Fprof.run(["-e", "Enum.each(1..5, fn(_) -> MapSet.new end)", "--no-warmup"])
end) =~ "Warmup..."
end
end
end