mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add source file and line number
The issue with nested macros losing their source location has been fixed!
This commit is contained in:
parent
f19b33d7a2
commit
5913a4c18f
3 changed files with 39 additions and 3 deletions
|
@ -1338,7 +1338,7 @@ module Spectator::DSL
|
||||||
# subject { 1 + 2 }
|
# subject { 1 + 2 }
|
||||||
# it is_expected.to eq(3)
|
# it is_expected.to eq(3)
|
||||||
# ```
|
# ```
|
||||||
macro it(what, &block)
|
macro it(what, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
# Create the wrapper class for the test code.
|
# Create the wrapper class for the test code.
|
||||||
{% if block.is_a?(Nop) %}
|
{% if block.is_a?(Nop) %}
|
||||||
{% if what.is_a?(Call) %}
|
{% if what.is_a?(Call) %}
|
||||||
|
@ -1354,6 +1354,16 @@ module Spectator::DSL
|
||||||
|
|
||||||
# Create a class derived from `RunnableExample` to run the test code.
|
# Create a class derived from `RunnableExample` to run the test code.
|
||||||
_spectator_example(Example%example, Test%example, ::Spectator::RunnableExample, {{what}}) do
|
_spectator_example(Example%example, Test%example, ::Spectator::RunnableExample, {{what}}) do
|
||||||
|
# Source file the example originated from.
|
||||||
|
def source_file
|
||||||
|
{{_source_file}}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Line number in the source file the example originated from.
|
||||||
|
def source_line
|
||||||
|
{{_source_line}}
|
||||||
|
end
|
||||||
|
|
||||||
# Implement abstract method to run the wrapped example block.
|
# Implement abstract method to run the wrapped example block.
|
||||||
protected def run_instance
|
protected def run_instance
|
||||||
@instance.%run
|
@instance.%run
|
||||||
|
@ -1392,12 +1402,22 @@ module Spectator::DSL
|
||||||
# can occur in unreferenced code and won't be caught by the compiler.
|
# can occur in unreferenced code and won't be caught by the compiler.
|
||||||
# By creating a `#pending` test, the code will be referenced.
|
# By creating a `#pending` test, the code will be referenced.
|
||||||
# Thus, forcing the compiler to at least process the code, even if it isn't run.
|
# Thus, forcing the compiler to at least process the code, even if it isn't run.
|
||||||
macro pending(what, &block)
|
macro pending(what, _source_file = __FILE__, _source_line = __LINE__, &block)
|
||||||
# Create the wrapper class for the test code.
|
# Create the wrapper class for the test code.
|
||||||
_spectator_test(Test%example, %run) {{block}}
|
_spectator_test(Test%example, %run) {{block}}
|
||||||
|
|
||||||
# Create a class derived from `PendingExample` to skip the test code.
|
# Create a class derived from `PendingExample` to skip the test code.
|
||||||
_spectator_example(Example%example, Test%example, ::Spectator::PendingExample, {{what}})
|
_spectator_example(Example%example, Test%example, ::Spectator::PendingExample, {{what}}) do
|
||||||
|
# Source file the example originated from.
|
||||||
|
def source_file
|
||||||
|
{{_source_file}}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Line number in the source file the example originated from.
|
||||||
|
def source_line
|
||||||
|
{{_source_line}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Add the example to the current group.
|
# Add the example to the current group.
|
||||||
::Spectator::DSL::Builder.add_example(Example%example)
|
::Spectator::DSL::Builder.add_example(Example%example)
|
||||||
|
|
|
@ -14,6 +14,16 @@ module Spectator
|
||||||
"DUMMY"
|
"DUMMY"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Dummy source file.
|
||||||
|
def source_file
|
||||||
|
__FILE__
|
||||||
|
end
|
||||||
|
|
||||||
|
# Dummy source line number.
|
||||||
|
def source_line
|
||||||
|
__LINE__
|
||||||
|
end
|
||||||
|
|
||||||
# Dummy instance.
|
# Dummy instance.
|
||||||
def instance
|
def instance
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -13,6 +13,12 @@ module Spectator
|
||||||
# Retrieves the internal wrapped instance.
|
# Retrieves the internal wrapped instance.
|
||||||
abstract def instance
|
abstract def instance
|
||||||
|
|
||||||
|
# Source file the example originated from.
|
||||||
|
abstract def source_file : String
|
||||||
|
|
||||||
|
# Line number in the source file the example originated from.
|
||||||
|
abstract def source_line : Int64
|
||||||
|
|
||||||
# Runs the example code.
|
# Runs the example code.
|
||||||
# A result is returned, which represents the outcome of the test.
|
# A result is returned, which represents the outcome of the test.
|
||||||
# An example can be run only once.
|
# An example can be run only once.
|
||||||
|
|
Loading…
Reference in a new issue