[ruby/prism] Pop lex mode for heredocs in the lexer, not the parser
[ruby.git] / spec / ruby / command_line / backtrace_limit_spec.rb
blob4d57bc268b5f14235b9d54d202dfd5801214b79c
1 require_relative '../spec_helper'
3 describe "The --backtrace-limit command line option" do
4   ruby_version_is ""..."3.4" do
5     it "limits top-level backtraces to a given number of entries" do
6       file = fixture(__FILE__ , "backtrace.rb")
7       out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
8       out = out.gsub(__dir__, '')
10       out.should == <<-MSG
11 top
12 /fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
13 \tfrom /fixtures/backtrace.rb:6:in `b'
14 \tfrom /fixtures/backtrace.rb:10:in `c'
15 \t ... 2 levels...
16       MSG
17     end
19     it "affects Exception#full_message" do
20       file = fixture(__FILE__ , "backtrace.rb")
21       out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
22       out = out.gsub(__dir__, '')
24       out.should == <<-MSG
25 full_message
26 /fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
27 \tfrom /fixtures/backtrace.rb:6:in `b'
28 \tfrom /fixtures/backtrace.rb:10:in `c'
29 \t ... 2 levels...
30       MSG
31     end
33     it "does not affect Exception#backtrace" do
34       file = fixture(__FILE__ , "backtrace.rb")
35       out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
36       out = out.gsub(__dir__, '')
38       out.should == <<-MSG
39 backtrace
40 /fixtures/backtrace.rb:2:in `a'
41 /fixtures/backtrace.rb:6:in `b'
42 /fixtures/backtrace.rb:10:in `c'
43 /fixtures/backtrace.rb:14:in `d'
44 /fixtures/backtrace.rb:29:in `<main>'
45       MSG
46     end
47   end
49   ruby_version_is "3.4" do
50     it "limits top-level backtraces to a given number of entries" do
51       file = fixture(__FILE__ , "backtrace.rb")
52       out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
53       out = out.gsub(__dir__, '')
55       out.should == <<-MSG
56 top
57 /fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
58 \tfrom /fixtures/backtrace.rb:6:in 'Object#b'
59 \tfrom /fixtures/backtrace.rb:10:in 'Object#c'
60 \t ... 2 levels...
61       MSG
62     end
64     it "affects Exception#full_message" do
65       file = fixture(__FILE__ , "backtrace.rb")
66       out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
67       out = out.gsub(__dir__, '')
69       out.should == <<-MSG
70 full_message
71 /fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
72 \tfrom /fixtures/backtrace.rb:6:in 'Object#b'
73 \tfrom /fixtures/backtrace.rb:10:in 'Object#c'
74 \t ... 2 levels...
75       MSG
76     end
78     it "does not affect Exception#backtrace" do
79       file = fixture(__FILE__ , "backtrace.rb")
80       out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
81       out = out.gsub(__dir__, '')
83       out.should == <<-MSG
84 backtrace
85 /fixtures/backtrace.rb:2:in 'Object#a'
86 /fixtures/backtrace.rb:6:in 'Object#b'
87 /fixtures/backtrace.rb:10:in 'Object#c'
88 /fixtures/backtrace.rb:14:in 'Object#d'
89 /fixtures/backtrace.rb:29:in '<main>'
90       MSG
91     end
92   end
93 end