summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-28 16:06:56 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-28 16:06:56 +0000
commit80001cc8c4602f15726a87e2423dd47cc0e18598 (patch)
tree008b816b265e60d4b5110bfdc42b9bde0d18fae6 /test
parentb361c8e3d5b2d91044700aa527503d1851ead0fe (diff)
downloadruby-80001cc8c4602f15726a87e2423dd47cc0e18598.tar.gz
Add test for cause on pty
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_backtrace.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb
index 0730b5d1c5..1a570c6d6e 100644
--- a/test/ruby/test_backtrace.rb
+++ b/test/ruby/test_backtrace.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'tempfile'
+require 'pty'
class TestBacktrace < Test::Unit::TestCase
def test_exception
@@ -329,4 +330,52 @@ class TestBacktrace < Test::Unit::TestCase
bar
end;
end
+
+ def assert_pty(args, test_stdin = "", dummy, expected)
+ actual = nil
+ PTY.spawn(EnvUtil.rubybin, *args) do |r, w, pid|
+ w.puts test_stdin
+ w.puts "__END__"
+ w.close
+ actual = r.read
+ end
+ expected = test_stdin.chomp + "\n__END__\n" + expected.to_s
+ expected.gsub!(/\n/, "\r\n")
+ assert_equal expected, actual
+ end
+
+ def test_tty_backtrace
+ err = "\e[1mTraceback\e[m (most recent call last):\n" +
+ "-:1:in `<main>': \e[1m\e[1;4munhandled exception\e[m\n"
+ assert_pty([], "raise", [], err)
+
+ err = "\e[1mTraceback\e[m (most recent call last):\n" +
+ "\t1: from -:4:in `<main>'\n" +
+ "-:2:in `foo': \e[1mfoo! (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
+ assert_pty([], <<-"end;", [], err)
+ def foo
+ raise "foo!"
+ end
+ foo
+ end;
+
+ err = "\e[1mTraceback\e[m (most recent call last):\n" +
+ "\t2: from -:9:in `<main>'\n" +
+ "\t1: from -:5:in `bar'\n" +
+ "-:2:in `foo': \e[1mfoo! (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" +
+ "\t2: from -:9:in `<main>'\n" +
+ "\t1: from -:4:in `bar'\n" +
+ "-:7:in `rescue in bar': \e[1mbar! (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
+ assert_pty([], <<-"end;", [], err)
+ def foo
+ raise "foo!"
+ end
+ def bar
+ foo
+ rescue
+ raise "bar!"
+ end
+ bar
+ end;
+ end
end