Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running compiler_specs with specific flags #7837

Merged
merged 2 commits into from
May 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def warnings_result(code, inject_primitives = true)
compiler.warnings = Warnings::All
compiler.error_on_warnings = false
compiler.prelude = "empty" # avoid issues in the current std lib
apply_program_flags(compiler.flags)
result = compiler.compile Compiler::Source.new("code.cr", code), output_filename

result.program.warning_failures
Expand Down Expand Up @@ -160,9 +161,24 @@ end
private def new_program
program = Program.new
program.color = false
apply_program_flags(program.flags)
program
end

# Use CRYSTAL_SPEC_COMPILER_FLAGS env var to run the compiler specs
# against a compiler with the specified options.
# Separate flags with a space.
# Using CRYSTAL_SPEC_COMPILER_FLAGS="foo bar" will mimic -Dfoo -Dbar options.
private def apply_program_flags(target)
ENV["CRYSTAL_SPEC_COMPILER_FLAGS"]?.try { |f| target.concat(f.split) }
end

private def encode_program_flags : String
f = [] of String
apply_program_flags(f)
f.map { |x| "-D#{x}" }.join(' ')
end

class Crystal::SpecRunOutput
@output : String

Expand Down Expand Up @@ -202,6 +218,7 @@ def run(code, filename = nil, inject_primitives = true, debug = Crystal::Debug::
compiler = Compiler.new
compiler.debug = debug
compiler.flags.concat flags if flags
apply_program_flags(compiler.flags)
compiler.compile Compiler::Source.new("spec", code), output_filename

output = `#{output_filename}`
Expand All @@ -221,7 +238,7 @@ def build_and_run(code)

binary_file = File.tempname("build_and_run_bin")

`bin/crystal build #{code_file.path.inspect} -o #{binary_file.path.inspect}`
`bin/crystal build #{encode_program_flags} #{code_file.path.inspect} -o #{binary_file.path.inspect}`
File.exists?(binary_file).should be_true

out_io, err_io = IO::Memory.new, IO::Memory.new
Expand Down