Skip to content

Commit

Permalink
Showing 3 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/std/callstack_spec.cr
Original file line number Diff line number Diff line change
@@ -26,4 +26,36 @@ describe "Backtrace" do
output.should_not match(/src\/exception\.cr/)
output.should_not match(/src\/raise\.cr/)
end

it "prints exception backtrace to stderr" do
tempfile = Tempfile.new("compiler_spec_output")
tempfile.close
sample = "#{__DIR__}/data/exception_backtrace_sample"

`bin/crystal build --debug #{sample.inspect} -o #{tempfile.path.inspect}`
File.exists?(tempfile.path).should be_true

output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio|
Process.run tempfile.path, output: outio, error: errio
end

output.to_s.empty?.should be_true
error.to_s.should contain("IndexError")
end

it "prints crash backtrace to stderr" do
tempfile = Tempfile.new("compiler_spec_output")
tempfile.close
sample = "#{__DIR__}/data/crash_backtrace_sample"

`bin/crystal build --debug #{sample.inspect} -o #{tempfile.path.inspect}`
File.exists?(tempfile.path).should be_true

output, error = {IO::Memory.new, IO::Memory.new}.tap do |outio, errio|
Process.run tempfile.path, output: outio, error: errio
end

output.to_s.empty?.should be_true
error.to_s.should contain("Invalid memory access")
end
end
18 changes: 18 additions & 0 deletions spec/std/data/crash_backtrace_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Kls
def callee1
foo = "foo".to_unsafe
foo.realloc(100)
end
end

def callee2
yield
end

def callee3
callee2 do
Kls.new.callee1
end
end

callee3
17 changes: 17 additions & 0 deletions spec/std/data/exception_backtrace_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Kls
def callee1
(0..10).to_a[123]
end
end

def callee2
yield
end

def callee3
callee2 do
Kls.new.callee1
end
end

callee3

0 comments on commit e4d1f92

Please sign in to comment.