From 007c9aa2bf0ca503001e5ee2c2fc73566a09fbfc Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 4 Jul 2012 16:01:01 +0000 Subject: * ruby.c (proc_options): warn only if -K and -w option is specified. see also r36274 [Feature #5206] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ruby.c | 4 +++- test/ruby/test_rubyoptions.rb | 20 ++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d991ca791..b385ff9206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 4 21:55:35 2012 NARUSE, Yui + + * ruby.c (proc_options): warn only if -K and -w option is specified. + see also r36274 [Feature #5206] + Wed Jul 4 21:41:44 2012 Naohisa Goto * gc.c, atomic.h (ATOMIC_SIZE_*): moved from gc.c to atomic.h diff --git a/ruby.c b/ruby.c index c56efe4e08..5aa93504b0 100644 --- a/ruby.c +++ b/ruby.c @@ -920,7 +920,6 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt) opt->src.enc.name = rb_str_new2(enc_name); if (!opt->ext.enc.name) opt->ext.enc.name = opt->src.enc.name; - rb_warn("-K%c is specified; it is for 1.8 compatibility and may cause odd behavior", rb_tolower(*s)); } s++; } @@ -1277,6 +1276,9 @@ process_options(int argc, char **argv, struct cmdline_options *opt) opt->intern.enc.name = int_enc_name; } + if (opt->src.enc.name) + rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); + if (opt->dump & DUMP_BIT(version)) { ruby_show_version(); return Qtrue; diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 4ef974a677..029eff07d4 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -121,9 +121,17 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%w(-KU), "p '\u3042'") do |r, e| assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) end - assert_in_out_err(%w(-KE -e) + [""], "", [], /-Ke/) - assert_in_out_err(%w(-KS -e) + [""], "", [], /-Ks/) - assert_in_out_err(%w(-KN -e) + [""], "", [], /-Kn/) + line = '-eputs"\xc2\xa1".encoding' + env = {'RUBYOPT' => nil} + assert_in_out_err([env, '-Ke', line], "", ["EUC-JP"], []) + assert_in_out_err([env, '-KE', line], "", ["EUC-JP"], []) + assert_in_out_err([env, '-Ks', line], "", ["Windows-31J"], []) + assert_in_out_err([env, '-KS', line], "", ["Windows-31J"], []) + assert_in_out_err([env, '-Ku', line], "", ["UTF-8"], []) + assert_in_out_err([env, '-KU', line], "", ["UTF-8"], []) + assert_in_out_err([env, '-Kn', line], "", ["ASCII-8BIT"], []) + assert_in_out_err([env, '-KN', line], "", ["ASCII-8BIT"], []) + assert_in_out_err([env, '-wKe', line], "", ["EUC-JP"], /-K/) end def test_version @@ -235,7 +243,7 @@ class TestRubyOptions < Test::Unit::TestCase ENV['RUBYOPT'] = '-Eus-ascii -KN' assert_in_out_err(%w(-Eutf-8 -KU), "p '\u3042'") do |r, e| assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) - assert_match(/-Ku/, e.join) + assert_equal([], e) end ensure @@ -287,9 +295,9 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err([], "#! /test_r_u_b_y_test_r_u_b_y_options_foobarbazqux -foo -bar\r\np 1\r\n", [], /: no Ruby script found in input/) - assert_in_out_err([], "#!ruby -KU -Eutf-8\r\np \"\u3042\"\r\n") do |r, e| + assert_in_out_err([{'RUBYOPT' => nil}], "#!ruby -KU -Eutf-8\r\np \"\u3042\"\r\n") do |r, e| assert_equal("\"\u3042\"", r.join.force_encoding(Encoding::UTF_8)) - assert_match(/-Ku/, e.join) + assert_equal([], e) end bug4118 = '[ruby-dev:42680]' -- cgit v1.2.3