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

@ -25,23 +25,8 @@ module Spectator
# Actually, prefixing methods and macros with `Spectator`
# most likely won't work and can cause compiler errors.
macro describe(description, &block)
# This macro creates the foundation for all specs.
# Every group of examples is defined a separate module - `SpectatorExamples`.
# There's multiple reasons for this.
#
# The first reason is to provide namespace isolation.
# We don't want the spec code to accidentally pickup types and values from the `Spectator` module.
# Another reason is that we need a root module to put all examples and groups in.
# And lastly, the spec DSL needs to be given to the block of code somehow.
# The DSL is included in the `SpectatorTest` class.
#
# For more information on how the DSL works, see the `DSL` module.
# Root-level class that contains all examples and example groups.
class ::SpectatorTestContext
# Pass off the description argument and block to `DSL::StructureDSL.describe`.
# That method will handle creating a new group for this spec.
describe({{description}}) {{block}}
example_group({{description}}) {{block}}
end
end

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)