mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add basics for tracking source code location
This commit is contained in:
parent
b8dcf35165
commit
de55e31407
4 changed files with 29 additions and 6 deletions
|
@ -9,7 +9,7 @@ module Spectator
|
||||||
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
||||||
module Spectator
|
module Spectator
|
||||||
module Examples
|
module Examples
|
||||||
DSL.describe({{what}}) {{block}}
|
DSL.describe({{what}}, {{source_file}}, {{source_line}}) {{block}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@ require "./example_group"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
module DSL
|
module DSL
|
||||||
macro describe(what, type = "Describe", &block)
|
macro describe(what, source_file = __FILE__, source_line = __LINE__, type = "Describe", &block)
|
||||||
context({{what}}, {{type}}) {{block}}
|
context({{what}}, {{source_file}}, {{source_line}}, {{type}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro context(what, type = "Context", &block)
|
macro context(what, source_file = __FILE__, source_line = __LINE__, type = "Context", &block)
|
||||||
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %}
|
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %}
|
||||||
{% module_name = (type.id + safe_name.camelcase).id %}
|
{% module_name = (type.id + safe_name.camelcase).id %}
|
||||||
{% parent_context_name = PARENT_CONTEXT_NAME %}
|
{% parent_context_name = PARENT_CONTEXT_NAME %}
|
||||||
|
@ -23,12 +23,16 @@ module Spectator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
macro it(description, &block)
|
macro it(description, source_file = __FILE__, source_line = __LINE__, &block)
|
||||||
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
|
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
|
||||||
{% class_name = (safe_name.camelcase + "Example").id %}
|
{% class_name = (safe_name.camelcase + "Example").id %}
|
||||||
class {{class_name.id}} < ::Spectator::Example
|
class {{class_name.id}} < ::Spectator::Example
|
||||||
include Context
|
include Context
|
||||||
|
|
||||||
|
def source
|
||||||
|
Source.new({{source_file}}, {{source_line}})
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
require "./source"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
abstract class Example
|
abstract class Example
|
||||||
macro is_expected
|
macro is_expected
|
||||||
expect(subject)
|
expect(subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
abstract def source : Source
|
||||||
|
|
||||||
abstract def run
|
abstract def run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
src/spectator/source.cr
Normal file
15
src/spectator/source.cr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module Spectator
|
||||||
|
class Source
|
||||||
|
getter file : String
|
||||||
|
getter line : Int32
|
||||||
|
|
||||||
|
def initialize(@file, @line)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s(io)
|
||||||
|
io << file
|
||||||
|
io << ':'
|
||||||
|
io << line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue