Skip to content

Commit

Permalink
junit: Allow disabling the message or details if they aren't relevant (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessa Bradbury authored Dec 14, 2018
1 parent db4fedf commit 3d1b392
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ steps:
type: junit
encoding: UTF-8
strip_colors: true
message: false
summary:
format: '%{location}: %{testcase.name}'
details_regex: '(?<location>\S+:\d+)[^\n]*\z'
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ crop:
* `job_id_regex:` Ruby regular expression to extract the `job_id` from the artifact path. It must contain
a named capture with the name `job_id`. Defaults to
`(?<job_id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})`.
* `summary:` (`junit` type only) Customise how the summary is generated. Includes:

#### Junit specific options:

* `summary:` Customise how the summary is generated. Includes:
* `format:` A ruby format string for converting the junit xml attributes
into a summary. All attributes are available in `<element>.<attr-name>` format.
* `details_regex:` A ruby regular expression, run over the body text of each failure. Any named captures
Expand All @@ -119,6 +122,9 @@ summary:
details_regex: '(?<location>\S+:\d+)'
```

* `message:` Set this to false if the failure `message` attribute is not worth showing in the annotation. Defaults to `true`.
* `details:` Set this to false if the body of the failure is not worth showing in the annotation. Defaults to `true`.

### Formatter

There are two formatter types, `summary` and `details`.
Expand Down
12 changes: 9 additions & 3 deletions lib/test_summary_buildkite_plugin/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def file_contents_to_failures(str)
testcase.elements.each('failure | error') do |failure|
failures << Failure::Structured.new(
summary: summary(failure),
message: failure.attributes['message']&.to_s,
message: message(failure),
details: details(failure)
)
end
Expand Down Expand Up @@ -150,8 +150,14 @@ def detail_attributes(failure)
end

def details(failure)
# gets all text elements that are direct children (includes CDATA), and use the unescaped values
failure.texts.map(&:value).join('').strip
if options.fetch(:details, true)
# gets all text elements that are direct children (includes CDATA), and use the unescaped values
failure.texts.map(&:value).join('').strip
end
end

def message(failure)
failure.attributes['message']&.to_s if options.fetch(:message, true)
end

def summary_format
Expand Down
4 changes: 4 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ configuration:
type: string
strip_colors:
type: boolean
message:
type: boolean
details:
type: boolean
crop:
type: object
properties:
Expand Down
24 changes: 24 additions & 0 deletions spec/test_summary_buildkite_plugin/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
expect(input.failures.first.details).to start_with('Failure/Error: ')
end

it 'failures have message' do
expect(input.failures.first.message).to start_with('expected http://')
end

it 'failures have file' do
expect(input.failures.first.summary).to include('./spec/lib/url_whitelist_spec.rb')
end
Expand Down Expand Up @@ -153,6 +157,26 @@
end
end
end

context 'disabling message' do
let(:additional_options) do
{ message: false }
end

it 'ignores the message' do
expect(input.failures.first.message).to be_nil
end
end

context 'disabling details' do
let(:additional_options) do
{ details: false }
end

it 'ignores the details' do
expect(input.failures.first.details).to be_nil
end
end
end

describe 'with glob path' do
Expand Down

0 comments on commit 3d1b392

Please sign in to comment.