From 7cb1545e83dd37658898f6bcb70f980f26035279 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 17 Jul 2021 16:15:11 -0600 Subject: [PATCH] Don't use failure location in failed example block output This is problematic, since the failure could have ocurred outside the example block (in a method call). The comment line under the failure details will still point to the result location, if it's available. --- src/spectator/formatting/components/example_command.cr | 7 ++----- .../formatting/components/failure_command_list.cr | 7 +------ src/spectator/formatting/components/result_block.cr | 3 ++- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/spectator/formatting/components/example_command.cr b/src/spectator/formatting/components/example_command.cr index 92d7627..8b3c0b9 100644 --- a/src/spectator/formatting/components/example_command.cr +++ b/src/spectator/formatting/components/example_command.cr @@ -1,14 +1,11 @@ require "../../example" -require "../../location" require "./comment" module Spectator::Formatting::Components # Provides syntax for running a specific example from the command-line. struct ExampleCommand # Creates the component with the specified 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) + def initialize(@example : Example) end # Produces output for running the previously specified example. @@ -17,7 +14,7 @@ module Spectator::Formatting::Components # Use location for argument if it's available, since it's simpler. # Otherwise, use the example name filter argument. - if location = (@location || @example.location?) + if location = @example.location? io << location else io << "-e " << @example diff --git a/src/spectator/formatting/components/failure_command_list.cr b/src/spectator/formatting/components/failure_command_list.cr index ceb3242..7da5ed2 100644 --- a/src/spectator/formatting/components/failure_command_list.cr +++ b/src/spectator/formatting/components/failure_command_list.cr @@ -14,12 +14,7 @@ module Spectator::Formatting::Components io.puts "Failed examples:" io.puts @failures.each do |failure| - # Use failed location if it's available. - if (result = failure.result).responds_to?(:location) - location = result.location - end - - io.puts ExampleCommand.new(failure, location).colorize(:red) + io.puts ExampleCommand.new(failure).colorize(:red) end end end diff --git a/src/spectator/formatting/components/result_block.cr b/src/spectator/formatting/components/result_block.cr index 36eb1a6..6d89f3f 100644 --- a/src/spectator/formatting/components/result_block.cr +++ b/src/spectator/formatting/components/result_block.cr @@ -68,7 +68,8 @@ module Spectator::Formatting::Components end end - # Produces the (example) location line. + # Produces the location line. + # This is where the result was determined. private def location_line(io) location = if (result = @example.result).responds_to?(:location) result.location