diff options
author | Nobuyoshi Nakada <[email protected]> | 2019-12-20 23:48:15 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2019-12-20 23:48:15 +0900 |
commit | 07e595fdbd75ed44473073cdf8cd758572d11709 (patch) | |
tree | 05adbd2b9d08690bed5be134acf2cb4111c4ea07 /test/ruby/test_pattern_matching.rb | |
parent | dd7f0c87c9da8e695c38a6529deb6e0f24f6d06c (diff) |
Added `experimental` warning category
[Feature #16420]
Diffstat (limited to 'test/ruby/test_pattern_matching.rb')
-rw-r--r-- | test/ruby/test_pattern_matching.rb | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 5308ec3281..dc72aa029c 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'test/unit' -verbose, $VERBOSE = $VERBOSE, nil # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" +experimental, Warning[:experimental] = Warning[:experimental], false # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" eval "\n#{<<~'END_of_GUARD'}", binding, __FILE__, __LINE__ class TestPatternMatching < Test::Unit::TestCase class C @@ -92,7 +92,8 @@ class TestPatternMatching < Test::Unit::TestCase end assert_block do - verbose, $VERBOSE = $VERBOSE, nil # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" + # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" + experimental, Warning[:experimental] = Warning[:experimental], false eval(%q{ case true in a @@ -100,7 +101,7 @@ class TestPatternMatching < Test::Unit::TestCase end }) ensure - $VERBOSE = verbose + Warning[:experimental] = experimental end assert_block do @@ -1274,6 +1275,23 @@ END 1 in a: }, /unexpected/, '[ruby-core:95098]') end + + def assert_experimental_warning(code) + w = Warning[:experimental] + + Warning[:experimental] = false + assert_warn('') {eval(code)} + + Warning[:experimental] = true + assert_warn(/Pattern matching is experimental/) {eval(code)} + ensure + Warning[:experimental] = w + end + + def test_experimental_warning + assert_experimental_warning("case 0; in 0; end") + assert_experimental_warning("0 in 0") + end end END_of_GUARD -$VERBOSE = verbose +Warning[:experimental] = experimental |