mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle nil location
This commit is contained in:
parent
39e917ce57
commit
835fa40773
11 changed files with 47 additions and 19 deletions
|
@ -169,8 +169,10 @@ module Spectator
|
|||
json.object do
|
||||
json.field("description", name? || "<anonymous>")
|
||||
json.field("full_description", to_s)
|
||||
json.field("file_path", location.path)
|
||||
json.field("line_number", location.line)
|
||||
if location = location?
|
||||
json.field("file_path", location.path)
|
||||
json.field("line_number", location.line)
|
||||
end
|
||||
@result.to_json(json) if @finished
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,8 +56,10 @@ module Spectator
|
|||
# Creates the JSON representation of the expectation.
|
||||
def to_json(json : JSON::Builder)
|
||||
json.object do
|
||||
json.field("file_path", @location.path)
|
||||
json.field("line_number", @location.line)
|
||||
if location = @location
|
||||
json.field("file_path", location.path)
|
||||
json.field("line_number", location.line)
|
||||
end
|
||||
json.field("satisfied", satisfied?)
|
||||
if (failed = @match_data.as?(Matchers::FailedMatchData))
|
||||
failed_to_json(failed, json)
|
||||
|
|
|
@ -11,9 +11,16 @@ module Spectator::Formatting::Components
|
|||
# Produces output for running the previously specified example.
|
||||
def to_s(io)
|
||||
io << "crystal spec "
|
||||
io << @example.location
|
||||
io << ' '
|
||||
io << Comment.colorize(@example.to_s)
|
||||
|
||||
# Use location for argument if it's available, since it's simpler.
|
||||
# Otherwise, use the example name filter argument.
|
||||
if location = @example.location?
|
||||
io << location
|
||||
else
|
||||
io << "-e " << @example
|
||||
end
|
||||
|
||||
io << ' ' << Comment.colorize(@example.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Spectator::Formatting::Components::JUnit
|
|||
def self.from_report(report)
|
||||
hostname = System.hostname
|
||||
counts = report.counts
|
||||
suites = report.examples.group_by(&.location.file)
|
||||
suites = report.examples.group_by { |example| example.location?.try(&.path) || "anonymous" }
|
||||
suites = suites.map do |file, examples|
|
||||
TestSuite.from_examples(file, examples, hostname)
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module Spectator::Formatting::Components::JUnit
|
|||
private def self.package_name_from_file(file)
|
||||
path = Path.new(file.to_s)
|
||||
name = path.stem
|
||||
directory = path.relative_to(Dir.current).dirname
|
||||
directory = path.dirname
|
||||
package = directory.gsub(File::SEPARATOR, '.')
|
||||
{package, name}
|
||||
end
|
||||
|
|
|
@ -29,8 +29,13 @@ module Spectator::Formatting::Components
|
|||
io.puts example
|
||||
io << " "
|
||||
io << Runtime.new(example.result.elapsed).colorize.bold
|
||||
io << ' '
|
||||
io.puts example.location
|
||||
|
||||
if location = example.location
|
||||
io << ' '
|
||||
io.puts location
|
||||
else
|
||||
io.puts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -71,8 +71,10 @@ module Spectator::Formatting::Components
|
|||
source = if (result = @example.result).responds_to?(:source)
|
||||
result.source
|
||||
else
|
||||
@example.location
|
||||
@example.location?
|
||||
end
|
||||
return unless source
|
||||
|
||||
line(io) { io << Comment.colorize(source) }
|
||||
end
|
||||
|
||||
|
|
|
@ -30,8 +30,13 @@ module Spectator::Formatting::Components
|
|||
io.puts example
|
||||
io << "# "
|
||||
io << Runtime.new(example.result.elapsed)
|
||||
io << ' '
|
||||
io.puts example.location
|
||||
|
||||
if location = example.location?
|
||||
io << ' '
|
||||
io.puts location
|
||||
else
|
||||
io.puts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,8 +28,11 @@ module Spectator::Formatting
|
|||
@json.start_object
|
||||
@json.field("description", example.name? || "<anonymous>")
|
||||
@json.field("full_description", example)
|
||||
@json.field("file_path", example.location.path)
|
||||
@json.field("line_number", example.location.line)
|
||||
|
||||
if location = example.location?
|
||||
@json.field("file_path", location.path)
|
||||
@json.field("line_number", location.line)
|
||||
end
|
||||
end
|
||||
|
||||
# Adds fields to the example object for all result types known after the example completes.
|
||||
|
|
|
@ -7,8 +7,10 @@ module Spectator
|
|||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example) : Bool
|
||||
start_line = example.location.line
|
||||
end_line = example.location.end_line
|
||||
return false unless location = example.location?
|
||||
|
||||
start_line = location.line
|
||||
end_line = location.end_line
|
||||
(start_line..end_line).covers?(@line)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Spectator
|
|||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example) : Bool
|
||||
@location === example.location
|
||||
@location === example.location?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue