Skip to content

Commit

Permalink
Merge 6001c1d into 550948b
Browse files Browse the repository at this point in the history
  • Loading branch information
jwfearn committed Jan 31, 2017
2 parents 550948b + 6001c1d commit 6f3b586
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions lib/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule JUnitFormatter do
require Logger
Logger.debug "Wrote JUnit report to: #{file_name}"
end

# Release handler
:remove_handler
end
Expand Down Expand Up @@ -123,7 +123,7 @@ defmodule JUnitFormatter do
def format_time(time), do: time |> us_to_ms |> format_ms

@doc """
Helper function to get the full path of the generated report file.
Helper function to get the full path of the generated report file.
It can be passed 2 configurations
- report_dir: full path of a directory (defaults to `Mix.Project.app_path()`)
- report_file: name of the generated file (defaults to "test-junit-report.xml")
Expand All @@ -133,7 +133,7 @@ defmodule JUnitFormatter do
report_dir = Application.get_env :junit_formatter, :report_dir, Mix.Project.app_path
"#{report_dir}/#{report_file}"
end

# PRIVATE ------------

defp adjust_case_stats(%ExUnit.Test{} = test, config) do
Expand All @@ -147,9 +147,9 @@ defmodule JUnitFormatter do
defp get_file_name(_config) do
require Logger

report_path = get_report_file_path
report_path = get_report_file_path()
debug = Application.get_env :junit_formatter, :print_report_file, false

if debug,
do: Logger.debug fn -> "Junit-formatter report at: #{report_path}" end

Expand Down Expand Up @@ -178,7 +178,7 @@ defmodule JUnitFormatter do
"#{div(ms, 10)}.#{rem(ms, 10)}"
end
end

defp generate_testcases(test) do
{:testcase, [classname: Atom.to_char_list(test.case),
name: Atom.to_char_list(test.name),
Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ defmodule Formatter.Mixfile do
use Mix.Project

@version "1.2.0"

def project do
[app: :junit_formatter,
version: @version,
elixir: "~> 1.1",
deps: deps,
package: package,
deps: deps(),
package: package(),
consolidate_protocols: Mix.env != :test,
description: description,
description: description(),
name: "JUnit Formatter",
test_coverage: [tool: ExCoveralls],
docs: [extras: ["README.md": [title: "Overview"],
Expand Down
20 changes: 10 additions & 10 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
"credo": {:hex, :credo, "0.5.1", "2395862b94628cadf0f5c68975c1440393f425b955f1e70ce1aea267e00187a1", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [], []},
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.7", "5d26e4a7cdf08294217594a1b0643636accc2ad30e984d62f1d166f70629ff50", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"credo": {:hex, :credo, "0.6.0", "44a82f82b94eeb4ba6092c89b8a6730ca1a3291c7940739d5acc8806d25ac991", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"earmark": {:hex, :earmark, "1.1.0", "8c2bf85d725050a92042bc1edf362621004d43ca6241c756f39612084e95487f", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.6.1", "9e946b6db84dba592f47632157ecd135a46384b98a430fd16007dc910c70348b", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:mix, :rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [], []},
"jsx": {:hex, :jsx, "2.8.0", "749bec6d205c694ae1786d62cea6cc45a390437e24835fd16d12d74f07097727", [:mix, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], []},
"hackney": {:hex, :hackney, "1.6.5", "8c025ee397ac94a184b0743c73b33b96465e85f90a02e210e86df6cbafaa5065", [:rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.8.1", "1453b4eb3615acb3e2cd0a105d27e6761e2ed2e501ac0b390f5bbec497669846", [:mix, :rebar3], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}}
24 changes: 12 additions & 12 deletions test/formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ defmodule FormatterTest do
use ExUnit.Case, async: false

test "that a valid test generates a proper report" do

defmodule ValidTest do
use ExUnit.Case

test "the truth" do
assert 1 + 1 == 2
end
end

output = run_and_capture_output |> strip_time_and_line_number
output = run_and_capture_output() |> strip_time_and_line_number
assert output =~ read_fixture("valid_test.xml")
end

Expand All @@ -25,7 +25,7 @@ defmodule FormatterTest do
end
end

output = run_and_capture_output |> strip_time_and_line_number
output = run_and_capture_output() |> strip_time_and_line_number
assert output =~ read_fixture("invalid_test.xml")
end

Expand All @@ -43,7 +43,7 @@ defmodule FormatterTest do
end
end

output = run_and_capture_output |> strip_time_and_line_number
output = run_and_capture_output() |> strip_time_and_line_number

# can't ensure order. Assert it contains both cases
assert output =~ "<testcase classname=\"Elixir.FormatterTest.ValidAndInvalidTest\" name=\"test the truth\" />"
Expand All @@ -62,7 +62,7 @@ defmodule FormatterTest do
end
end

output = run_and_capture_output |> strip_time_and_line_number
output = run_and_capture_output() |> strip_time_and_line_number

assert output =~ "<testsuite errors=\"0\" failures=\"1\" name=\"Elixir.FormatterTest.RaiseAsFailureTest\" tests=\"1\""
assert output =~ "<testcase classname=\"Elixir.FormatterTest.RaiseAsFailureTest\" name=\"test it counts raises\" ><failure message=\"error: argument error\"> test/formatter_test.exs FormatterTest.RaiseAsFailureTest.\"test it counts raises\"/1"
Expand All @@ -77,8 +77,8 @@ defmodule FormatterTest do
end
end

output = run_and_capture_output |> strip_time_and_line_number
output = run_and_capture_output() |> strip_time_and_line_number

assert output =~ "<testcase classname=\"Elixir.FormatterTest.RaiseWithNoReason\" name=\"test it raises without reason\" ><failure message=\"throw: nil\"> test/formatter_test.exs FormatterTest.RaiseWithNoReason.\"test it raises without reason\"/1\n</failure></testcase>"
end

Expand All @@ -103,11 +103,11 @@ defmodule FormatterTest do
put_config(:report_dir, "/tmp")
assert JUnitFormatter.get_report_file_path == "/tmp/abc.xml"
end

# Utilities --------------------
defp get_config(name), do: Application.get_env(:junit_formatter, name)
defp put_config(name, value), do: Application.put_env(:junit_formatter, name, value)

defp read_fixture(extra) do
Path.expand("fixtures", __DIR__) |> Path.join(extra) |> File.read!
end
Expand All @@ -121,7 +121,7 @@ defmodule FormatterTest do
ExUnit.Server.cases_loaded()
end

ExUnit.run
ExUnit.run
File.read!(JUnitFormatter.get_report_file_path) <> "\n"
end

Expand All @@ -130,5 +130,5 @@ defmodule FormatterTest do
file = List.last String.split __ENV__.file, ~r/\//
String.replace output, ~r/#{file}:[0-9]+:/, file
end

end

0 comments on commit 6f3b586

Please sign in to comment.