Playing around with line numbers

Trying to find some pattern in the line descripancies reported to the 
macros compared to the source file.
This commit is contained in:
Michael Miller 2020-09-14 20:00:17 -06:00
parent bc602d9b62
commit 9103bfde0f
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 38 additions and 36 deletions

View file

@ -3,12 +3,30 @@ require "./builder"
module Spectator::DSL
module Examples
macro example(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
macro define_example(name)
macro {{name.id}}(what = nil)
def %test
\{{yield}}
end
%source = ::Spectator::Source.new(__FILE__, __LINE__)
::Spectator::DSL::Builder.add_example(
\{{what.is_a?(StringLiteral) || what.is_a?(NilLiteral) ? what : what.stringify}},
%source,
\{{@type.name}}.new
) { |example, context| context.as(\{{@type.name}}).%test }
end
end
define_example(:example)
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
{% puts "#{_source_file}:#{_source_line}" %}
def %test
{{block.body}}
{{yield}}
end
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
%source = ::Spectator::Source.new(__FILE__, __LINE__)
::Spectator::DSL::Builder.add_example(
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
%source,
@ -16,12 +34,18 @@ module Spectator::DSL
) { |example, context| context.as({{@type.name}}).%test }
end
macro it(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
end
macro specify(what = nil, *, _source_file = __FILE__, _source_line = __LINE__, &block)
example({{what}}, _source_file: {{_source_file}}, _source_line: {{_source_line}}) {{block}}
{% puts "#{_source_file}:#{_source_line}" %}
def %test
{{yield}}
end
%source = ::Spectator::Source.new(__FILE__, __LINE__)
::Spectator::DSL::Builder.add_example(
{{what.is_a?(StringLiteral | NilLiteral) ? what : what.stringify}},
%source,
{{@type.name}}.new
) { |example, context| context.as({{@type.name}}).%test }
end
end
macro it(description = nil, _source_file = __FILE__, _source_line = __LINE__, &block)

View file

@ -8,19 +8,13 @@ module Spectator::DSL
# Defines a new example group.
# The *what* argument is a name or description of the group.
# If it isn't a string literal, then it is symbolized for `ExampleNode#name`.
macro example_group(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
# Example group: {{what.stringify}}
# Source: {{_source_file}}:{{_source_line}}
class Group%group < {{@type.id}}
_spectator_group_subject({{what}})
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::DSL::Builder.start_group({{what.is_a?(StringLiteral) ? what : what.stringify}}, %source)
{{block.body}}
::Spectator::DSL::Builder.end_group
end
macro example_group(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)
class Group%group < {{@type.id}}; _spectator_group_subject({{what}}); ::Spectator::DSL::Builder.start_group({{what.is_a?(StringLiteral) ? what : what.stringify}}, ::Spectator::Source.new(__FILE__, __LINE__)); {{block.body}}; ::Spectator::DSL::Builder.end_group; end
{% debug(false) %}
end
macro describe(what, *, _source_file = __FILE__, _source_line = __LINE__, &block)

View file

@ -42,7 +42,6 @@ module Spectator
def add_example(name, source, context, &block : Example, Context ->)
{% if flag?(:spectator_debug) %}
puts "Add example: #{name} @ #{source}"
puts "Context: #{context}"
{% end %}
delegate = ExampleContextDelegate.new(context, block)
Example.new(delegate, name, source, current_group)