From 2bc8289441f7d36f637cc1ea05def36e5813142d Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 19 Apr 2013 17:39:44 +0000 Subject: merge revision(s) 40117,40118,40333: [Backport #8222] * test/test_curses.rb: tests for getch. * ext/curses/curses.c (Init_curses): fix implementation function, crmode should be same as cbreak. [ruby-core:54013] [Bug #8222] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/curses/curses.c | 2 +- test/test_curses.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ version.h | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9ff762435..71538b4d8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Apr 20 02:37:33 2013 Nobuyoshi Nakada + + * ext/curses/curses.c (Init_curses): fix implementation function, + crmode should be same as cbreak. [ruby-core:54013] [Bug #8222] + Sat Apr 20 02:09:46 2013 Martin Bosslet * ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC. diff --git a/ext/curses/curses.c b/ext/curses/curses.c index 175e32cff9..88b1bdb3aa 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -2715,7 +2715,7 @@ Init_curses(void) rb_define_module_function(mCurses, "noraw", curses_noraw, 0); rb_define_module_function(mCurses, "cbreak", curses_cbreak, 0); rb_define_module_function(mCurses, "nocbreak", curses_nocbreak, 0); - rb_define_module_function(mCurses, "crmode", curses_nocbreak, 0); + rb_define_module_function(mCurses, "crmode", curses_cbreak, 0); rb_define_module_function(mCurses, "nocrmode", curses_nocbreak, 0); rb_define_module_function(mCurses, "nl", curses_nl, 0); rb_define_module_function(mCurses, "nonl", curses_nonl, 0); diff --git a/test/test_curses.rb b/test/test_curses.rb index 03462d6f7e..d03a94173d 100644 --- a/test/test_curses.rb +++ b/test/test_curses.rb @@ -1,7 +1,9 @@ require 'test/unit' +require_relative 'ruby/envutil' begin require 'curses' + require 'pty' rescue LoadError end @@ -10,3 +12,49 @@ class TestCurses < Test::Unit::TestCase assert_instance_of(String, Curses::VERSION) end end if defined? Curses + +class TestCurses + def run_curses(src, input = nil, timeout: 1) + PTY.spawn({"TERM"=>ENV["TERM"]||"dumb"}, EnvUtil.rubybin, "-e", <<-"src") {|r, w, pid| +require 'timeout' +require 'curses' +include Curses +init_screen +begin + result = Timeout.timeout(#{timeout}) do + #{src} + end +rescue Exception => e +ensure + close_screen + puts "", [Marshal.dump([result, e])].pack('m').delete("\n") +end +src + if input + w.print(input) + w.flush + end + res = r.read + return unless res + res, error = Marshal.load(res[/(.*)\Z/, 1].unpack('m')[0]) + raise error if error + return res + } + end + + def test_getch + assert_equal("a", run_curses("getch", "a")) + end + def test_getch_cbreak + assert_equal("a", run_curses("cbreak; getch", "a")) + end + def test_getch_nocbreak + assert_raise(Timeout::Error) {run_curses("nocbreak; getch", "a")} + end + def test_getch_crmode + assert_equal("a", run_curses("crmode; getch", "a")) + end + def test_getch_nocrmode + assert_raise(Timeout::Error) {run_curses("nocrmode; getch", "a")} + end +end if defined? TestCurses and defined? PTY diff --git a/version.h b/version.h index 30dbc428fe..5fca50c8c5 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-04-20" -#define RUBY_PATCHLEVEL 153 +#define RUBY_PATCHLEVEL 154 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 4 -- cgit v1.2.3