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
Add TAP formatter to spec suite #6286
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require "spec" | ||
require "xml" | ||
|
||
private def build_report | ||
String.build do |io| | ||
formatter = Spec::TAPFormatter.new(io) | ||
yield formatter | ||
formatter.finish | ||
end | ||
end | ||
|
||
private def exception_with_backtrace(msg) | ||
begin | ||
raise Exception.new(msg) | ||
rescue e | ||
e | ||
end | ||
end | ||
|
||
describe Spec::TAPFormatter do | ||
it "reports successful results" do | ||
output = build_report do |f| | ||
f.report Spec::Result.new(:success, "should do something", "spec/some_spec.cr", 33, nil, nil) | ||
f.report Spec::Result.new(:success, "should do something else", "spec/some_spec.cr", 50, nil, nil) | ||
end | ||
|
||
output.chomp.should eq <<-TAP | ||
ok 1 - should do something | ||
ok 2 - should do something else | ||
1..2 | ||
TAP | ||
end | ||
|
||
it "reports failures" do | ||
output = build_report do |f| | ||
f.report Spec::Result.new(:fail, "should do something", "spec/some_spec.cr", 33, nil, nil) | ||
end | ||
|
||
output.chomp.should eq <<-TAP | ||
not ok 1 - should do something | ||
1..1 | ||
TAP | ||
end | ||
|
||
it "reports errors" do | ||
output = build_report do |f| | ||
f.report Spec::Result.new(:error, "should do something", "spec/some_spec.cr", 33, nil, nil) | ||
end | ||
|
||
output.chomp.should eq <<-TAP | ||
not ok 1 - should do something | ||
1..1 | ||
TAP | ||
end | ||
|
||
it "reports pending" do | ||
output = build_report do |f| | ||
f.report Spec::Result.new(:pending, "should do something", "spec/some_spec.cr", 33, nil, nil) | ||
end | ||
|
||
output.chomp.should eq <<-TAP | ||
ok 1 - # SKIP should do something | ||
1..1 | ||
TAP | ||
end | ||
|
||
it "reports mixed results" do | ||
output = build_report do |f| | ||
f.report Spec::Result.new(:success, "should do something1", "spec/some_spec.cr", 33, 2.seconds, nil) | ||
f.report Spec::Result.new(:fail, "should do something2", "spec/some_spec.cr", 50, 0.5.seconds, nil) | ||
f.report Spec::Result.new(:error, "should do something3", "spec/some_spec.cr", 65, nil, nil) | ||
f.report Spec::Result.new(:error, "should do something4", "spec/some_spec.cr", 80, nil, nil) | ||
f.report Spec::Result.new(:pending, "should do something5", "spec/some_spec.cr", 33, nil, nil) | ||
end | ||
|
||
output.chomp.should eq <<-TAP | ||
ok 1 - should do something1 | ||
not ok 2 - should do something2 | ||
not ok 3 - should do something3 | ||
not ok 4 - should do something4 | ||
ok 5 - # SKIP should do something5 | ||
1..5 | ||
TAP | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# :nodoc: | ||
class Spec::TAPFormatter < Spec::Formatter | ||
@counter = 0 | ||
|
||
def report(result) | ||
case result.kind | ||
when :success | ||
@io << "ok" | ||
when :fail, :error | ||
@io << "not ok" | ||
when :pending | ||
@io << "ok" | ||
end | ||
|
||
@counter += 1 | ||
|
||
@io << ' ' << @counter << " -" | ||
if result.kind == :pending | ||
@io << " # SKIP" | ||
end | ||
@io << ' ' << result.description | ||
|
||
@io.puts | ||
end | ||
|
||
def finish | ||
@io << "1.." << @counter | ||
@io.puts | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should be
when :success, :pending
. And thewhen :pending
should be removed.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.
Nope, that would reduce visibility. Separate entries makes it obvious what we're looking at.