File: raise_spec.cr

package info (click to toggle)
crystal 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,384 kB
  • sloc: javascript: 6,400; sh: 695; makefile: 269; ansic: 121; python: 105; cpp: 77; xml: 32
file content (25 lines) | stat: -rw-r--r-- 742 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require "./spec_helper"

describe "raise" do
  callstack_on_rescue = nil

  it "should set exception's callstack" do
    exception = expect_raises Exception, "without callstack" do
      raise "without callstack"
    end
    exception.callstack.should_not be_nil
  end

  it "shouldn't overwrite the callstack on re-raise" do
    exception_after_reraise = expect_raises Exception, "exception to be rescued" do
      begin
        raise "exception to be rescued"
      rescue exception_on_rescue
        callstack_on_rescue = exception_on_rescue.callstack
        raise exception_on_rescue
      end
    end
    exception_after_reraise.callstack.should_not be_nil
    exception_after_reraise.callstack.should eq(callstack_on_rescue)
  end
end