mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use failure location in output if available
Fixes https://gitlab.com/arctic-fox/spectator/-/issues/57
This commit is contained in:
parent
9c7f39ba45
commit
7e2b267e93
3 changed files with 22 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
||||||
require "json"
|
require "json"
|
||||||
|
require "./example_failed"
|
||||||
|
require "./location"
|
||||||
require "./result"
|
require "./result"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
|
@ -36,6 +38,15 @@ module Spectator
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Attempts to retrieve the location where the example failed.
|
||||||
|
# This only works if the location of the failed expectation was reported.
|
||||||
|
# If available, returns a `Location`, otherwise `nil`.
|
||||||
|
def source : Location?
|
||||||
|
return unless error = @error.as?(ExampleFailed)
|
||||||
|
|
||||||
|
error.location?
|
||||||
|
end
|
||||||
|
|
||||||
# One-word description of the result.
|
# One-word description of the result.
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "fail"
|
io << "fail"
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
require "../../example"
|
require "../../example"
|
||||||
|
require "../../location"
|
||||||
require "./comment"
|
require "./comment"
|
||||||
|
|
||||||
module Spectator::Formatting::Components
|
module Spectator::Formatting::Components
|
||||||
# Provides syntax for running a specific example from the command-line.
|
# Provides syntax for running a specific example from the command-line.
|
||||||
struct ExampleCommand
|
struct ExampleCommand
|
||||||
# Creates the component with the specified example.
|
# Creates the component with the specified example.
|
||||||
def initialize(@example : Example)
|
# The location can be overridden, for instance, pointing to a problematic line in the example.
|
||||||
|
# Otherwise the example's location is used.
|
||||||
|
def initialize(@example : Example, @location : Location? = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Produces output for running the previously specified example.
|
# Produces output for running the previously specified example.
|
||||||
|
@ -14,7 +17,7 @@ module Spectator::Formatting::Components
|
||||||
|
|
||||||
# Use location for argument if it's available, since it's simpler.
|
# Use location for argument if it's available, since it's simpler.
|
||||||
# Otherwise, use the example name filter argument.
|
# Otherwise, use the example name filter argument.
|
||||||
if location = @example.location?
|
if location = (@location || @example.location?)
|
||||||
io << location
|
io << location
|
||||||
else
|
else
|
||||||
io << "-e " << @example
|
io << "-e " << @example
|
||||||
|
|
|
@ -14,7 +14,12 @@ module Spectator::Formatting::Components
|
||||||
io.puts "Failed examples:"
|
io.puts "Failed examples:"
|
||||||
io.puts
|
io.puts
|
||||||
@failures.each do |failure|
|
@failures.each do |failure|
|
||||||
io.puts ExampleCommand.new(failure).colorize(:red)
|
# Use failed location if it's available.
|
||||||
|
if (result = failure.result).responds_to?(:source)
|
||||||
|
location = result.source
|
||||||
|
end
|
||||||
|
|
||||||
|
io.puts ExampleCommand.new(failure, location).colorize(:red)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue