Skip to content

Commit

Permalink
Misc doc changes (#38)
Browse files Browse the repository at this point in the history
List of changes:
- Fix typos
- Bump deps version
- Fix markdown
- Badges and more badges!
- Add link to ExUnit
- Use common source url
- Fix license spdx
- Add changelog link to hex info page
- Refactor module config
  • Loading branch information
kianmeng committed Jan 2, 2021
1 parent 3c60aa5 commit a704697
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 47 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Expand Up @@ -10,7 +10,7 @@

### Fixed

- Converts String to utf8 charlist, instead of unicode (#34 thank to @mrmstn)
- Converts String to utf8 charlist, instead of Unicode (#34 thank to @mrmstn)

## 3.0.0

Expand All @@ -34,7 +34,7 @@

### Bugfixes:

- Fix unicode characters in test names on OTP 20. It is important to notice that test names with unicode characters that are not ascii will **ONLY** work if running on OTP 20. Thanks to @sparta-developers
- Fix Unicode characters in test names on OTP 20. It is important to notice that test names with Unicode characters that are not ASCII will **ONLY** work if running on OTP 20. Thanks to @sparta-developers
- Add option of prepending the project name to the report file to avoid overriding the results when in umbrella project. README was also updated. Thanks to @axelson for bringing the issue.

## 2.1.0
Expand Down Expand Up @@ -87,11 +87,11 @@

### Features:

- `ExUnit.Formatter` implementation that prints an xml to the build directory.
- `ExUnit.Formatter` implementation that prints an XML to the build directory.

### Bugfixes:

- Correctly show time of testsuite in seconds rather than micro seconds (thanks to [@ibizaman](https://github.com/ibizaman))
- Correctly handle errors with empty messages (thanks to [@Reimerei](https://github.com/Reimerei))
- Fixed name of failed tests tag in xml (thanks to [@KronicDeth](https://github.com/KronicDeth))
- Fixed name of failed tests tag in XML (thanks to [@KronicDeth](https://github.com/KronicDeth))
- Fixed compatibility with Elixir 1.2 (thanks to [@adrienmo](https://github.com/adrienmo))
16 changes: 8 additions & 8 deletions README.md
@@ -1,11 +1,11 @@
JUnitFormatter
=========

[![Build Status](https://travis-ci.org/victorolinasc/junit-formatter.svg)](https://travis-ci.org/victorolinasc/junit-formatter) [![Documentation](https://img.shields.io/badge/docs-hexpm-blue.svg)](http://hexdocs.pm/junit_formatter/) [![Downloads](https://img.shields.io/hexpm/dt/junit_formatter.svg)](https://hex.pm/packages/junit_formatter) [![Coverage Status](https://coveralls.io/repos/github/victorolinasc/junit-formatter/badge.svg?branch=master)](https://coveralls.io/github/victorolinasc/junit-formatter?branch=master)
[![Build Status](https://travis-ci.org/victorolinasc/junit-formatter.svg)](https://travis-ci.org/victorolinasc/junit-formatter) [![Hex Version](https://img.shields.io/hexpm/v/junit_formatter.svg)](http://hex.pm/packages/junit_formatter/) [![Documentation](https://img.shields.io/badge/docs-hexpm-blue.svg)](http://hexdocs.pm/junit_formatter/) [![Downloads](https://img.shields.io/hexpm/dt/junit_formatter.svg)](https://hex.pm/packages/junit_formatter) [![Coverage Status](https://coveralls.io/repos/github/victorolinasc/junit-formatter/badge.svg?branch=master)](https://coveralls.io/github/victorolinasc/junit-formatter?branch=master) [![Last Updated](https://img.shields.io/github/last-commit/victorolinasc/junit-formatter.svg)](https://github.com/victorolinasc/junit-formatter/commits/master)

A simple ExUnit Formatter that collects test results and generates an xml report in JUnit format. This is intended to be used by tools that can produce a graphical report, mainly targeted at Jenkins and its support for JUnit.
A simple ExUnit Formatter that collects test results and generates an XML report in JUnit format. This is intended to be used by tools that can produce a graphical report, mainly targeted at Jenkins and its support for JUnit.

The report is generated in `Mix.Project.app_path` folder with a default filename of test-junit-report.xml. It can be configured through application configuration on the key report_file (application junit_formatter).
The report is generated in `Mix.Project.app_path` folder with a default filename of `test-junit-report.xml`. It can be configured through application configuration on the key `report_file` (application `:junit_formatter`).

> Versions 3+ require minimum Elixir version to be 1.5+. For older releases, please use version 2.2 of this library.
Expand Down Expand Up @@ -62,17 +62,17 @@ The JUnit style XML report for this project looks like this:
</testsuites>
```

*note: this example has been reformatted for readability.*
*Note: This example has been reformatted for readability.*

## Options

`JUnitFormatter` accepts 4 options that can be passed in config.exs (or equivalent environment configuration for tests):

- `print_report_file` (boolean - default `false`): tells formatter if you want to see the path where the file is being written to in the console. This might help you debug where the file is. By default it writes the report to the `Mix.Project.app_path` folder. This ensures compatibility with umbrella apps.
- `report_file` (binary - default `"test-junit-report.xml"`): the name of the file to write to. It must contain the extension. 99% of the time you will want the extension to be `.xml`, but if you don't you can pass any extension (though the contents of the file will be an xml document).
- `report_file` (binary - default `"test-junit-report.xml"`): the name of the file to write to. It must contain the extension. 99% of the time you will want the extension to be `.xml`, but if you don't you can pass any extension (though the contents of the file will be an XML document).
- `report_dir` (binary - default `Mix.Project.app_path()`): the directory to which the formatter will write the report. Do not end it with a slash. **IMPORTANT!!** `JUnitFormatter` will **NOT** create the directory. If you are pointing to a directory that is outside _build then it is your duty to clean it and to be sure it exists.
- `prepend_project_name?` (boolean - default `false`): tells if the report file should have the name of the project as a prefix. See the "Umbrella" part of the documentation.
- `include_filename?` (boolean - default `false`): dictates whether `<testcase>`s in the XML report should include a "file" attribute of the relative path to the file of the test. Note that this defaults to false because not all JUnit ingesters will accept a file attribute.
- `include_filename?` (boolean - default `false`): dictates whether `<testcase>`s in the XML report should include a "file" attribute of the relative path to the file of the test. Note that this defaults to false because not all JUnit ingesters will accept a file attribute.

Example configuration:

Expand All @@ -89,7 +89,7 @@ This would generate the report at: `/tmp/myapp-report_file_test.xml`.

## Umbrella projects

`JUnitFormatter` works with umbrella projects too. By default, it will generate the xml report on each sub-project build folder. So, as an example, if you have two apps (`my-app` and `another`) it will generate the following reports:
`JUnitFormatter` works with umbrella projects too. By default, it will generate the XML report on each sub-project build folder. So, as an example, if you have two apps (`my-app` and `another`) it will generate the following reports:

- `_build/test/lib/my_app/report_file.xml`
- `_build/test/lib/another/report_file.xml`
Expand All @@ -101,7 +101,7 @@ config :junit_formatter,
report_dir: "/tmp"
```

Then, while running in an umbrela project, the first sub-project will run and generate a report file the following path:
Then, while running in an umbrella project, the first sub-project will run and generate a report file the following path:

- `/tmp/report_file.xml`

Expand Down
18 changes: 9 additions & 9 deletions lib/formatter.ex
@@ -1,28 +1,28 @@
defmodule JUnitFormatter do
@moduledoc """
* A ExUnit.Formatter implementation that generates a xml in the format understood by JUnit.
An `ExUnit.Formatter` implementation that generates a XML in the format understood by JUnit.
To acomplish this, there are some mappings that are not straight one to one.
To accomplish this, there are some mappings that are not straight one to one.
Therefore, here goes the mapping:
- JUnit - ExUnit
- JUnit - `ExUnit`
- Testsuites - :testsuite
- Testsuite - %ExUnit.TestCase{}
- Testsuite - `ExUnit.Case`
- failures = failures
- skipped = skip
- errors = invalid
- time = (sum of all times in seconds rounded down)
- Testcase - %ExUnit.Test
- Testcase - `ExUnit.Test`
- name = :case
- test = :test
- content (only if not successful)
- skipped = {:state, {:skip, _}}
- failed = {:state, {:failed, {_, reason, stacktrace}}}
- reason = reason.message
- contet = Exception.format_stacktrace(stacktrace)
- content = `Exception.format_stacktrace/1`
- error = {:invalid, module}
The report is written to a file in the _build directory.
The report is written to a file in the `_build` directory.
"""
require Record

Expand All @@ -32,7 +32,7 @@ defmodule JUnitFormatter do
@moduledoc """
A struct to keep track of test values and tests themselves.
It is used to build the testsuite junit node.
It is used to build the testsuite JUnit node.
"""
defstruct errors: 0,
failures: 0,
Expand Down Expand Up @@ -71,7 +71,7 @@ defmodule JUnitFormatter do
# wrap result in a root node (not adding any attribute to root)
result = :xmerl.export_simple([{:testsuites, [], suites}], :xmerl_xml)

# save the report in an xml file
# save the report in an XML file
file_name = get_report_file_path()

:ok = File.write!(file_name, result, [:write])
Expand Down
31 changes: 18 additions & 13 deletions mix.exs
@@ -1,6 +1,7 @@
defmodule Formatter.Mixfile do
use Mix.Project

@source_url "https://github.com/victorolinasc/junit-formatter"
@version "3.1.0"

def project do
Expand All @@ -10,19 +11,11 @@ defmodule Formatter.Mixfile do
elixir: "~> 1.5",
deps: deps(),
package: package(),
docs: docs(),
consolidate_protocols: Mix.env() != :test,
description: description(),
name: "JUnit Formatter",
test_coverage: [tool: ExCoveralls],
docs: [
extras: [
"README.md": [title: "Overview"],
"CHANGELOG.md": [title: "Changelog"]
],
main: "readme",
source_ref: "v#{@version}",
source_url: "https://github.com/victorolinasc/junit-formatter"
]
test_coverage: [tool: ExCoveralls]
]
end

Expand All @@ -45,14 +38,26 @@ defmodule Formatter.Mixfile do
[
files: ["lib", "mix.exs", "README*", "LICENSE*", "CHANGELOG*"],
maintainers: ["Victor Nascimento"],
licenses: ["Apache 2.0"],
licenses: ["Apache-2.0"],
links: %{
"Github" => "https://github.com/victorolinasc/junit-formatter",
"docs" => "http://hexdocs.pm/junit_formatter/"
"Changelog" => @source_url <> "/blob/master/CHANGELOG.md",
"GitHub" => @source_url
}
]
end

defp docs do
[
extras: [
"README.md": [title: "Overview"],
"CHANGELOG.md": [title: "Changelog"]
],
main: "readme",
source_ref: "v#{@version}",
source_url: @source_url
]
end

defp description do
"""
An ExUnit.Formatter that produces an XML report of the tests run in the project _build dir.
Expand Down

0 comments on commit a704697

Please sign in to comment.