Skip to content

Commit

Permalink
Don't spawn subprocess if codegen spec uses flags but not the prelude (
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Aug 16, 2024
1 parent 3bf3410 commit 7ee895f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1885,4 +1885,9 @@ describe "Code gen: macro" do
{% end %}
)).to_i.should eq(10)
end

it "accepts compile-time flags" do
run("{{ flag?(:foo) ? 1 : 0 }}", flags: %w(foo)).to_i.should eq(1)
run("{{ flag?(:foo) ? 1 : 0 }}", Int32, flags: %w(foo)).should eq(1)
end
end
12 changes: 8 additions & 4 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def run(code, filename : String? = nil, inject_primitives = true, debug = Crysta
# in the current executable!), so instead we compile
# the program and run it, printing the last
# expression and using that to compare the result.
if code.includes?(%(require "prelude")) || flags
if code.includes?(%(require "prelude"))
ast = Parser.parse(code).as(Expressions)
last = ast.expressions.last
assign = Assign.new(Var.new("__tempvar"), last)
Expand All @@ -315,7 +315,9 @@ def run(code, filename : String? = nil, inject_primitives = true, debug = Crysta
return SpecRunOutput.new(output)
end
else
new_program.run(code, filename: filename, debug: debug)
program = new_program
program.flags.concat(flags) if flags
program.run(code, filename: filename, debug: debug)
end
end

Expand All @@ -324,10 +326,12 @@ def run(code, return_type : T.class, filename : String? = nil, inject_primitives
code = %(require "primitives"\n#{code})
end

if code.includes?(%(require "prelude")) || flags
if code.includes?(%(require "prelude"))
fail "TODO: support the prelude in typed codegen specs", file: file
else
new_program.run(code, return_type: T, filename: filename, debug: debug)
program = new_program
program.flags.concat(flags) if flags
program.run(code, return_type: T, filename: filename, debug: debug)
end
end

Expand Down

0 comments on commit 7ee895f

Please sign in to comment.