Skip to content

Commit

Permalink
Spec: try to call 'crystal i' when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Jun 29, 2024
1 parent e83e787 commit 7b2c96c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion spec/std/exception/call_stack_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe "Backtrace" do
error.to_s.should contain("IndexError")
end

it "prints crash backtrace to stderr", tags: %w[slow] do
pending_interpreted "prints crash backtrace to stderr", tags: %w[slow] do
sample = datapath("crash_backtrace_sample")

_, output, error = compile_and_run_file(sample)
Expand Down
2 changes: 1 addition & 1 deletion spec/std/kernel_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe "at_exit" do
end
end

describe "hardware exception" do
pending_interpreted describe: "hardware exception" do
it "reports invalid memory access", tags: %w[slow] do
status, _, error = compile_and_run_source <<-'CRYSTAL'
puts Pointer(Int64).null.value
Expand Down
20 changes: 11 additions & 9 deletions spec/std/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ def spawn_and_check(before : Proc(_), file = __FILE__, line = __LINE__, &block :
end

def compile_file(source_file, *, bin_name = "executable_file", flags = %w(), file = __FILE__, &)
# can't use backtick in interpreted code (#12241)
pending_interpreted! "Unable to compile Crystal code in interpreted code"

with_temp_executable(bin_name, file: file) do |executable_file|
compiler = ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal"
args = ["build"] + flags + ["-o", executable_file, source_file]
Expand Down Expand Up @@ -111,12 +108,17 @@ def compile_source(source, flags = %w(), file = __FILE__, &)
end

def compile_and_run_file(source_file, flags = %w(), runtime_args = %w(), file = __FILE__)
compile_file(source_file, flags: flags, file: file) do |executable_file|
output, error = IO::Memory.new, IO::Memory.new
status = Process.run executable_file, args: runtime_args, output: output, error: error

{status, output.to_s, error.to_s}
end
status, output, error = Process::Status.new(0), IO::Memory.new, IO::Memory.new
{% if flag?(:interpreted) %}
compiler = ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal"
args = ["i", source_file, "--", *runtime_args]
status = Process.run compiler, args: args, output: output, error: error
{% else %}
compile_file(source_file, flags: flags, file: file) do |executable_file|
status = Process.run executable_file, args: runtime_args, output: output, error: error
end
{% end %}
{status, output.to_s, error.to_s}
end

def compile_and_run_source(source, flags = %w(), runtime_args = %w(), file = __FILE__)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/interpreted.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec"

{% if flag?(:interpreted) %}
def pending_interpreted(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
pending("#{description} [interpreted]", file, line, end_line)
def pending_interpreted(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, tags = nil, &block)
pending("#{description} [interpreted]", file, line, end_line, false, tags)
end

def pending_interpreted(*, describe, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
Expand Down

0 comments on commit 7b2c96c

Please sign in to comment.