diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-05 01:04:08 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-05 01:04:08 +0900 |
| commit | 29a12297c3594ed24102d62e16dfd6d4e5e328f3 (patch) | |
| tree | 17c7cc90f47da821600e0d066e1c259baf144893 | |
| parent | cf12aff0593a0aa70d957b96f03df8288c025938 (diff) | |
Refine non-nil warnings for the deprecated variables
| -rw-r--r-- | string.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_io.rb | 8 | ||||
| -rw-r--r-- | test/ruby/test_string.rb | 18 |
3 files changed, 19 insertions, 9 deletions
@@ -11378,7 +11378,7 @@ rb_str_setter(VALUE val, ID id, VALUE *var) static void nil_setter_warning(ID id) { - rb_warn_deprecated("'%"PRIsVALUE"'", NULL, rb_id2str(id)); + rb_warn_deprecated("non-nil '%"PRIsVALUE"'", NULL, rb_id2str(id)); } void diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index dd8ccbc96a..1adf47ac51 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2907,10 +2907,10 @@ class TestIO < Test::Unit::TestCase end def test_print_separators - EnvUtil.suppress_warning { - $, = ':' - $\ = "\n" - } + assert_deprecated_warning(/non-nil '\$,'/) {$, = ":"} + assert_raise(TypeError) {$, = 1} + assert_deprecated_warning(/non-nil '\$\\'/) {$\ = "\n"} + assert_raise(TypeError) {$/ = 1} pipe(proc do |w| w.print('a') EnvUtil.suppress_warning {w.print('a','b','c')} diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 6fdc2bdaa8..1fe0629331 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1883,9 +1883,13 @@ CODE def test_fs return unless @cls == String - assert_raise_with_message(TypeError, /\$;/) { - $; = [] - } + begin + fs = $; + assert_deprecated_warning(/non-nil '\$;'/) {$; = "x"} + assert_raise_with_message(TypeError, /\$;/) {$; = []} + ensure + EnvUtil.suppress_warning {$; = fs} + end name = "\u{5206 5217}" assert_separately([], "#{<<~"do;"}\n#{<<~"end;"}") do; @@ -2775,7 +2779,13 @@ CODE def test_rs return unless @cls == String - assert_raise(TypeError) { $/ = 1 } + begin + rs = $/ + assert_deprecated_warning(/non-nil '\$\/'/) { $/ = "" } + assert_raise(TypeError) { $/ = 1 } + ensure + EnvUtil.suppress_warning { $/ = rs } + end name = "\u{5206 884c}" assert_separately([], "#{<<~"do;"}\n#{<<~"end;"}") do; |
