-
Notifications
You must be signed in to change notification settings - Fork 106
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
(SDK-147) Add 'test unit' runner and basic output formatting #98
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on using puppetlabs_spec_helper's rake task. While I still hope we can get rid of PSH in the future, now is not the time for it, alas.
I understand this is still in raw form, so some of the comments about commit structure are probably pre-mature.
lib/pdk/report/event.rb
Outdated
|
||
valid_types = [Array] | ||
|
||
unless valid_types.include?(value.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems a bit excessive for a single class test :->
lib/pdk/report.rb
Outdated
@@ -78,7 +78,7 @@ def to_junit(target = self.class.default_target) | |||
def to_text(target = self.class.default_target) | |||
events.each do |_tool, tool_events| | |||
tool_events.each do |event| | |||
target.puts("\n" << event.to_text) unless event.pass? | |||
target.puts(event.to_text) unless event.pass? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just undoes a change from the previous commit. If you rebase --interactive
, and remove the change from the first commit, you can get rid of it here too.
lib/pdk/cli/exec.rb
Outdated
@@ -55,6 +55,7 @@ class Command | |||
attr_reader :argv | |||
attr_reader :context | |||
attr_accessor :timeout | |||
attr_accessor :environment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the change itself, it does feel like it could be a separate commit though, as it adds a feature unrelated to the "puppetlabs_spec_helper invocation for unit tests" mentioned in the commit message.
282a78b
to
6cc293c
Compare
Yes I'll try to rebase this into a saner set of commits before merge. |
93b11a4
to
ead3e3b
Compare
@DavidS @rodjek @james-stocks This is ready to go now. Reviewing commit-by-commit should be pretty clear. Once merged, James should be able to rebase his |
lib/pdk/tests/unit.rb
Outdated
return unless json_data['summary'] | ||
|
||
# TODO: standardize summary output | ||
$stderr.puts ' ' << _('Evaluated %{total} tests in %{duration} seconds: %{errors} errors, %{failures} failures, %{pending} pending') % { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this summary line be added to the report to be printed out at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The report may go to a file or be in XML or all kinds of things. I consider the summary to be diagnostic information which is why I write it to $stderr
once the run is finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note also that a report generator could create it's own summary when appropriate based on the events we added when parsing the output.)
lib/pdk/tests/unit.rb
Outdated
json_data['messages'].each do |msg| | ||
report.add_event( | ||
source: 'rspec', | ||
state: :error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at the rspec json output yesterday, and I was unsure if a message from rspec is necessarily an error; a quick browse of the rspec-core code suggests they're pretty neutral on what a message is.
I think it's a fair assumption that a message from rspec is something we can consider an error.
EDIT: I notice in the code below that we won't include failures in the report if ['messages'] is populated - so we assume not just that a message is an error, but additionally that a message means that the example results are going to be pointless. Are there definitely not cases (e.g. deprecation warnings) where rspec will return a message AND meaningful spec results?
EDIT: I think when there are 0 examples to run; rspec provides 'No examples found.' as a message. But once we add skeleton spec code (e.g. it compiles ) we maybe could consider this to also be an an error
lib/pdk/tests/unit.rb
Outdated
elsif json_data['summary'] && json_data['summary']['failure_count'].zero? | ||
report.add_event(state: :passed, severity: :ok) | ||
elsif json_data['examples'] | ||
failures = json_data['examples'].reject { |e| e['status'] == 'passed' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should pending also be rejected here?
lib/pdk/tests/unit.rb
Outdated
) | ||
end | ||
elsif json_data['summary'] && json_data['summary']['failure_count'].zero? | ||
report.add_event(state: :passed, severity: :ok) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this all the report includes in the case of all examples passing? I guess the details of each example are not needed if everything is passing; but wouldn't it be desirable to record at least the number of examples that passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions on the rspec reporting, otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed a couple of examples to support or reject what @james-stocks has been talking about. Deprecations do not get taken as an error, so that's fine. They are also not displayed at all, that's not so good.
Additionally, when tests fail, important information about the failures is swallowed in the default output:
david@davids:~/git/pdk/test$ ~/git/pdk/bin/pdk test unit
[✔] Checking for missing Gemfile dependencies
[✔] Checking for required Bundler binstubs
[✖] Running unit tests
Evaluated 3 tests in 0.28056711 seconds: 0 errors, 3 failures, 0 pending
./spec/classes/mod_spec.rb:8: failed: expected that the catalogue would not compile but it does
./spec/classes/mod_spec.rb:8: failed: expected that the catalogue would not compile but it does
./spec/classes/mod_spec.rb:8: failed: expected that the catalogue would not compile but it does
david@davids:~/git/pdk/test$
Compare this to the plain rspec output:
david@davids:~/git/pdk/test$ bundle exec rspec spec/classes/mod_spec.rb
test::mod
on debian-8-x86_64
should not compile into a catalogue without dependency cycles (FAILED - 1)
on ubuntu-16.04-x86_64
should not compile into a catalogue without dependency cycles (FAILED - 2)
on redhat-7-x86_64
should not compile into a catalogue without dependency cycles (FAILED - 3)
Failures:
1) test::mod on debian-8-x86_64 should not compile into a catalogue without dependency cycles
Failure/Error: it { subject.should_not compile }
expected that the catalogue would not compile but it does
# ./spec/classes/mod_spec.rb:8:in `block (4 levels) in <top (required)>'
2) test::mod on ubuntu-16.04-x86_64 should not compile into a catalogue without dependency cycles
Failure/Error: it { subject.should_not compile }
expected that the catalogue would not compile but it does
# ./spec/classes/mod_spec.rb:8:in `block (4 levels) in <top (required)>'
3) test::mod on redhat-7-x86_64 should not compile into a catalogue without dependency cycles
Failure/Error: it { subject.should_not compile }
expected that the catalogue would not compile but it does
# ./spec/classes/mod_spec.rb:8:in `block (4 levels) in <top (required)>'
Deprecation Warnings:
Using `should_not` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/david/git/pdk/test/spec/classes/mod_spec.rb:8:in `block (4 levels) in <top (required)>'.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Finished in 0.28652 seconds (files took 1.37 seconds to load)
3 examples, 3 failures
Failed examples:
rspec ./spec/classes/mod_spec.rb[1:1:1] # test::mod on debian-8-x86_64 should not compile into a catalogue without dependency cycles
rspec ./spec/classes/mod_spec.rb[1:2:1] # test::mod on ubuntu-16.04-x86_64 should not compile into a catalogue without dependency cycles
rspec ./spec/classes/mod_spec.rb[1:3:1] # test::mod on redhat-7-x86_64 should not compile into a catalogue without dependency cycles
david@davids:~/git/pdk/test$
Everything else except the actual functional change looks good. @scotje if you can post a separate PR for the first 6 commits, we can get them merged independently and reduce the size and load of this one.
The JSON output from RSpec in general leaves a lot to be desired, we might want to consider writing a our own custom reporter eventually and shipping it as part of the template. I'll see what I can do to improve things with what we have though. |
This commit implements basic support for the `test unit` subcommand which invokes the puppetlabs_spec_helper provided `rake spec` command inside the context of the target module's bundled gem environment. Output from the underlying RSpec command is parsed and then returned to the user in the requested format and to the requested destination.
ead3e3b
to
dd03a74
Compare
Updated and simplified the report parsing. Currently some of the information (such as context) is being passed to the reporter but the |
lib/pdk/tests/unit.rb
Outdated
example_results.each do |result, examples| | ||
state = case result | ||
when 'passed' then :passed | ||
when 'failed' then :failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like at this point we immediately translate rspec result values to the result values our CI uses
I think our report code ( https://github.com/puppetlabs/pdk/blob/master/lib/pdk/report/event.rb#L83 ) should be clearly documented to explain that rspec pending gets mapped to a skipped result in XML reports; I'll update that outside of this PR
|
||
example_results.each do |result, examples| | ||
# Translate rspec example results to JUnit XML testcase results | ||
state = case result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI on seeing this, I was a little unsure about the translation of rspec result values to CI result values. I added a comment line here; and also created #115 (now merged) to support pending/skipped results better.
Now LGTM 👍
No description provided.