mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement TAP formatter
This commit is contained in:
parent
886dfa56c6
commit
edbcff03a5
4 changed files with 69 additions and 2 deletions
|
@ -133,7 +133,7 @@ In no particular order, features that have been implemented and are planned:
|
||||||
- [X] RSpec/Crystal Spec default
|
- [X] RSpec/Crystal Spec default
|
||||||
- [X] JSON
|
- [X] JSON
|
||||||
- [ ] JUnit
|
- [ ] JUnit
|
||||||
- [ ] TAP
|
- [X] TAP
|
||||||
|
|
||||||
### How it Works
|
### How it Works
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ module Spectator
|
||||||
parser.on("--location FILE:LINE", "Run the example at line 'LINE' in the file 'FILE', multiple allowed") { |location| raise NotImplementedError.new("--location") }
|
parser.on("--location FILE:LINE", "Run the example at line 'LINE' in the file 'FILE', multiple allowed") { |location| raise NotImplementedError.new("--location") }
|
||||||
parser.on("--json", "Generate JSON output") { builder.formatter = Formatting::JsonFormatter.new }
|
parser.on("--json", "Generate JSON output") { builder.formatter = Formatting::JsonFormatter.new }
|
||||||
parser.on("--junit_output OUTPUT_DIR", "Generate JUnit XML output") { |output_dir| raise NotImplementedError.new("--juni_output") }
|
parser.on("--junit_output OUTPUT_DIR", "Generate JUnit XML output") { |output_dir| raise NotImplementedError.new("--juni_output") }
|
||||||
parser.on("--tap", "Generate TAP output (Test Anything Protocol)") { raise NotImplementedError.new("--tap") }
|
parser.on("--tap", "Generate TAP output (Test Anything Protocol)") { builder.formatter = Formatting::TAPFormatter.new }
|
||||||
parser.on("--no-color", "Disable colored output") { raise NotImplementedError.new("--no-color") }
|
parser.on("--no-color", "Disable colored output") { raise NotImplementedError.new("--no-color") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
34
src/spectator/formatting/tap_formatter.cr
Normal file
34
src/spectator/formatting/tap_formatter.cr
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
module Spectator::Formatting
|
||||||
|
# Formatter for the "Test Anything Protocol".
|
||||||
|
# For details, see: https://testanything.org/
|
||||||
|
class TAPFormatter < Formatter
|
||||||
|
# Creates the formatter.
|
||||||
|
# By default, output is sent to STDOUT.
|
||||||
|
def initialize(@io : IO = STDOUT)
|
||||||
|
@index = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called when a test suite is starting to execute.
|
||||||
|
def start_suite(suite : TestSuite)
|
||||||
|
@io << "1.."
|
||||||
|
@io.puts suite.size
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called when a test suite finishes.
|
||||||
|
# The results from the entire suite are provided.
|
||||||
|
def end_suite(report : Report)
|
||||||
|
@io.puts "Bail out!" if report.remaining?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called before a test starts.
|
||||||
|
def start_example(example : Example)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called when a test finishes.
|
||||||
|
# The result of the test is provided.
|
||||||
|
def end_example(result : Result)
|
||||||
|
@io.puts TAPTestLine.new(@index, result)
|
||||||
|
@index += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
33
src/spectator/formatting/tap_test_line.cr
Normal file
33
src/spectator/formatting/tap_test_line.cr
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
module Spectator::Formatting
|
||||||
|
# Produces a formatted TAP test line.
|
||||||
|
private struct TAPTestLine
|
||||||
|
# Creates the test line.
|
||||||
|
def initialize(@index : Int32, @result : Result)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Appends the line to the output.
|
||||||
|
def to_s(io)
|
||||||
|
io << status
|
||||||
|
io << ' '
|
||||||
|
io << @index
|
||||||
|
io << " - "
|
||||||
|
io << example
|
||||||
|
io << " # skip" if pending?
|
||||||
|
end
|
||||||
|
|
||||||
|
# The text "ok" or "not ok" depending on the result.
|
||||||
|
private def status
|
||||||
|
@result.is_a?(FailedResult) ? "not ok" : "ok"
|
||||||
|
end
|
||||||
|
|
||||||
|
# The example that was tested.
|
||||||
|
private def example
|
||||||
|
@result.example
|
||||||
|
end
|
||||||
|
|
||||||
|
# Indicates whether this test was skipped.
|
||||||
|
private def pending?
|
||||||
|
@result.is_a?(PendingResult)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue