warning 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +20 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -0
- data/lib/warning.rb +96 -48
- metadata +3 -7
- data/Rakefile +0 -47
- data/test/fixtures/mismatched_indentations.rb +0 -4
- data/test/test_freeze_warning.rb +0 -70
- data/test/test_warning.rb +0 -515
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea693f6c3250c25b7ba2859e7c8ea5d945e8c0560aa3c564fda63da2d52e567
|
4
|
+
data.tar.gz: 3417d55cd4807d454d37afc6360864d9d87b29874b8e87d8082b413d209a4b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 379377da9ef4d3ac871eb4bdbf08dcc245ccb94d7f987ef04f3f60944f4e1d0784aeee60bb560cbd4d744b92e675803fcd6955c354553649bd72e8d0e3dda1a2
|
7
|
+
data.tar.gz: 691e2c43099ddad0631752b66d7c401025a59a1b81de0fc1eca92627e5efd9b6d561b571b434526a325cab2f30bc9f4c7d2f625d62ec303905b19115ecf85148
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
=== 1.3.0 (2022-07-14)
|
2
|
+
|
3
|
+
* Allow Warning.clear to take a block, and restore current state after block (splattael) (#18, #20)
|
4
|
+
|
5
|
+
* Raise ArgumentError if Warning.process is passed non-String as first argument (splattael) (#17, #19)
|
6
|
+
|
7
|
+
=== 1.2.1 (2021-10-04)
|
8
|
+
|
9
|
+
* Recognize additional void context warnings (kachick) (#13)
|
10
|
+
|
11
|
+
=== 1.2.0 (2021-02-16)
|
12
|
+
|
13
|
+
* Add support for :void_context as regexp argument to Warning.ignore (jeremyevans)
|
14
|
+
|
15
|
+
* Support :category keyword to Warning.warn on Ruby 3.0 (jeremyevans)
|
16
|
+
|
17
|
+
* Fix :taint warning handling on Ruby 3.0 (jeremyevans)
|
18
|
+
|
19
|
+
* Fix :ambiguous_slash warning handling on Ruby 3.0 (jeremyevans)
|
20
|
+
|
1
21
|
=== 1.1.0 (2020-06-12)
|
2
22
|
|
3
23
|
* Allow Warning.process to be called with a hash of actions instead of a block (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -42,6 +42,7 @@ appropriate regexp. The supported symbols are:
|
|
42
42
|
* :taint
|
43
43
|
* :unused_var
|
44
44
|
* :useless_operator
|
45
|
+
* :void_context
|
45
46
|
|
46
47
|
<tt>Warning.process</tt> takes an optional path prefix and a block, and if the
|
47
48
|
warning string starts with the path prefix, it calls the block with the warning
|
data/lib/warning.rb
CHANGED
@@ -4,7 +4,7 @@ module Warning
|
|
4
4
|
module Processor
|
5
5
|
# Map of symbols to regexps for warning messages to ignore.
|
6
6
|
IGNORE_MAP = {
|
7
|
-
ambiguous_slash: /: warning: ambiguous first argument; put parentheses or a space even after `\/' operator\n\z/,
|
7
|
+
ambiguous_slash: /: warning: ambiguous first argument; put parentheses or a space even after `\/' operator\n\z|: warning: ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after `\/' operator\n\z/,
|
8
8
|
arg_prefix: /: warning: `[&\*]' interpreted as argument prefix\n\z/,
|
9
9
|
bignum: /: warning: constant ::Bignum is deprecated\n\z/,
|
10
10
|
fixnum: /: warning: constant ::Fixnum is deprecated\n\z/,
|
@@ -17,29 +17,63 @@ module Warning
|
|
17
17
|
useless_operator: /: warning: possibly useless use of [><!=]+ in void context\n\z/,
|
18
18
|
keyword_separation: /: warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z/,
|
19
19
|
safe: /: warning: (?:rb_safe_level_2_warning|rb_safe_level|rb_set_safe_level_force|rb_set_safe_level|rb_secure|rb_insecure_operation|rb_check_safe_obj|\$SAFE) will (?:be removed|become a normal global variable) in Ruby 3\.0\n\z/,
|
20
|
-
taint: /: warning: (?:rb_error_untrusted|rb_check_trusted|Pathname#taint|Pathname#untaint|rb_env_path_tainted|Object#tainted\?|Object#taint|Object#untaint|Object#untrusted\?|Object#untrust|Object#trust|rb_obj_infect|rb_tainted_str_new|rb_tainted_str_new_cstr) is deprecated and will be removed in Ruby 3\.2
|
20
|
+
taint: /: warning: (?:rb_error_untrusted|rb_check_trusted|Pathname#taint|Pathname#untaint|rb_env_path_tainted|Object#tainted\?|Object#taint|Object#untaint|Object#untrusted\?|Object#untrust|Object#trust|rb_obj_infect|rb_tainted_str_new|rb_tainted_str_new_cstr) is deprecated and will be removed in Ruby 3\.2\.?\n\z/,
|
21
21
|
mismatched_indentations: /: warning: mismatched indentations at '.+' with '.+' at \d+\n\z/,
|
22
|
+
void_context: /possibly useless use of (?:a )?\S+ in void context/,
|
22
23
|
}
|
23
24
|
|
24
25
|
# Map of action symbols to procs that return the symbol
|
25
26
|
ACTION_PROC_MAP = {
|
27
|
+
raise: proc{|_| :raise},
|
26
28
|
default: proc{|_| :default},
|
27
29
|
backtrace: proc{|_| :backtrace},
|
28
|
-
raise: proc{|_| :raise},
|
29
30
|
}
|
30
31
|
private_constant :ACTION_PROC_MAP
|
31
32
|
|
32
33
|
# Clear all current ignored warnings, warning processors, and duplicate check cache.
|
33
34
|
# Also disables deduplicating warnings if that is currently enabled.
|
35
|
+
#
|
36
|
+
# If a block is passed, the previous values are restored after the block exits.
|
37
|
+
#
|
38
|
+
# Examples:
|
39
|
+
#
|
40
|
+
# # Clear warning state
|
41
|
+
# Warning.clear
|
42
|
+
#
|
43
|
+
# Warning.clear do
|
44
|
+
# # Clear warning state inside the block
|
45
|
+
# ...
|
46
|
+
# end
|
47
|
+
# # Previous warning state restored when block exists
|
34
48
|
def clear
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
49
|
+
if block_given?
|
50
|
+
ignore = process = dedup = nil
|
51
|
+
synchronize do
|
52
|
+
ignore = @ignore.dup
|
53
|
+
process = @process.dup
|
54
|
+
dedup = @dedup.dup
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
clear
|
59
|
+
yield
|
60
|
+
ensure
|
61
|
+
synchronize do
|
62
|
+
@ignore = ignore
|
63
|
+
@process = process
|
64
|
+
@dedup = dedup
|
65
|
+
end
|
66
|
+
end
|
67
|
+
else
|
68
|
+
synchronize do
|
69
|
+
@ignore.clear
|
70
|
+
@process.clear
|
71
|
+
@dedup = false
|
72
|
+
end
|
39
73
|
end
|
40
74
|
end
|
41
75
|
|
42
|
-
# Deduplicate warnings,
|
76
|
+
# Deduplicate warnings, suppress warning messages if the same warning message
|
43
77
|
# has already occurred. Note that this can lead to unbounded memory use
|
44
78
|
# if unique warnings are generated.
|
45
79
|
def dedup
|
@@ -75,6 +109,8 @@ module Warning
|
|
75
109
|
# :unused_var :: Ignore warnings for unused variables.
|
76
110
|
# :useless_operator :: Ignore warnings when using operators such as == and > when the
|
77
111
|
# result is not used.
|
112
|
+
# :void_context :: Ignore warnings for :: to reference constants when the result is not
|
113
|
+
# used (often used to trigger autoload).
|
78
114
|
#
|
79
115
|
# Examples:
|
80
116
|
#
|
@@ -126,7 +162,7 @@ module Warning
|
|
126
162
|
# Instead of passing a block, you can pass a hash of actions to take for specific
|
127
163
|
# warnings, using regexp as keys and a callable objects as values:
|
128
164
|
#
|
129
|
-
# Warning.
|
165
|
+
# Warning.process(__FILE__,
|
130
166
|
# /instance variable @\w+ not initialized/ => proc do |warning|
|
131
167
|
# LOGGER.warning(warning)
|
132
168
|
# end,
|
@@ -141,6 +177,10 @@ module Warning
|
|
141
177
|
#
|
142
178
|
# Warning.process(__FILE__, :missing_ivar=>:backtrace, :keyword_separation=>:raise)
|
143
179
|
def process(path='', actions=nil, &block)
|
180
|
+
unless path.is_a?(String)
|
181
|
+
raise ArgumentError, "path must be a String (given an instance of #{path.class})"
|
182
|
+
end
|
183
|
+
|
144
184
|
if block
|
145
185
|
if actions
|
146
186
|
raise ArgumentError, "cannot pass both actions and block to Warning.process"
|
@@ -166,57 +206,65 @@ module Warning
|
|
166
206
|
nil
|
167
207
|
end
|
168
208
|
|
169
|
-
# Handle ignored warnings and warning processors. If the warning is
|
170
|
-
# not ignored, is not a duplicate warning (if checking for duplicates)
|
171
|
-
# and there is no warning processor setup for the warning
|
172
|
-
# string, then use the default behavior of writing to $stderr.
|
173
|
-
def warn(str)
|
174
|
-
synchronize{@ignore.dup}.each do |path, regexp|
|
175
|
-
if str.start_with?(path) && str =~ regexp
|
176
|
-
return
|
177
|
-
end
|
178
|
-
end
|
179
209
|
|
180
|
-
|
181
|
-
|
182
|
-
|
210
|
+
if RUBY_VERSION >= '3.0'
|
211
|
+
method_args = ', category: nil'
|
212
|
+
super_ = "category ? super : super(str)"
|
213
|
+
# :nocov:
|
214
|
+
else
|
215
|
+
super_ = "super"
|
216
|
+
# :nocov:
|
217
|
+
end
|
218
|
+
|
219
|
+
class_eval(<<-END, __FILE__, __LINE__+1)
|
220
|
+
def warn(str#{method_args})
|
221
|
+
synchronize{@ignore.dup}.each do |path, regexp|
|
222
|
+
if str.start_with?(path) && regexp.match?(str)
|
223
|
+
return
|
224
|
+
end
|
183
225
|
end
|
184
226
|
|
185
|
-
|
186
|
-
|
227
|
+
if @dedup
|
228
|
+
if synchronize{@dedup[str]}
|
229
|
+
return
|
230
|
+
end
|
231
|
+
|
232
|
+
synchronize{@dedup[str] = true}
|
233
|
+
end
|
187
234
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
235
|
+
action = catch(:action) do
|
236
|
+
synchronize{@process.dup}.each do |path, block|
|
237
|
+
if str.start_with?(path)
|
238
|
+
if block.is_a?(Hash)
|
239
|
+
block.each do |regexp, blk|
|
240
|
+
if regexp.match?(str)
|
241
|
+
throw :action, blk.call(str)
|
242
|
+
end
|
195
243
|
end
|
244
|
+
else
|
245
|
+
throw :action, block.call(str)
|
196
246
|
end
|
197
|
-
else
|
198
|
-
throw :action, block.call(str)
|
199
247
|
end
|
200
248
|
end
|
249
|
+
|
250
|
+
:default
|
201
251
|
end
|
202
252
|
|
203
|
-
|
204
|
-
|
253
|
+
case action
|
254
|
+
when :default
|
255
|
+
#{super_}
|
256
|
+
when :backtrace
|
257
|
+
#{super_}
|
258
|
+
$stderr.puts caller
|
259
|
+
when :raise
|
260
|
+
raise str
|
261
|
+
else
|
262
|
+
# nothing
|
263
|
+
end
|
205
264
|
|
206
|
-
|
207
|
-
when :default
|
208
|
-
super
|
209
|
-
when :backtrace
|
210
|
-
super
|
211
|
-
$stderr.puts caller
|
212
|
-
when :raise
|
213
|
-
raise str
|
214
|
-
else
|
215
|
-
# nothing
|
265
|
+
nil
|
216
266
|
end
|
217
|
-
|
218
|
-
nil
|
219
|
-
end
|
267
|
+
END
|
220
268
|
|
221
269
|
private
|
222
270
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest-global_expectations
|
@@ -41,11 +41,7 @@ files:
|
|
41
41
|
- CHANGELOG
|
42
42
|
- MIT-LICENSE
|
43
43
|
- README.rdoc
|
44
|
-
- Rakefile
|
45
44
|
- lib/warning.rb
|
46
|
-
- test/fixtures/mismatched_indentations.rb
|
47
|
-
- test/test_freeze_warning.rb
|
48
|
-
- test/test_warning.rb
|
49
45
|
homepage: https://github.com/jeremyevans/ruby-warning
|
50
46
|
licenses:
|
51
47
|
- MIT
|
@@ -76,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
72
|
- !ruby/object:Gem::Version
|
77
73
|
version: '0'
|
78
74
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.3.7
|
80
76
|
signing_key:
|
81
77
|
specification_version: 4
|
82
78
|
summary: Add custom processing for warnings
|
data/Rakefile
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
require "rake/clean"
|
3
|
-
require 'rake/testtask'
|
4
|
-
require "rdoc/task"
|
5
|
-
|
6
|
-
CLEAN.include ["warning-*.gem", "rdoc"]
|
7
|
-
|
8
|
-
desc "Build warning gem"
|
9
|
-
task :package=>[:clean] do |p|
|
10
|
-
sh %{#{FileUtils::RUBY} -S gem build warning.gemspec}
|
11
|
-
end
|
12
|
-
|
13
|
-
### Specs
|
14
|
-
|
15
|
-
desc "Run test"
|
16
|
-
Rake::TestTask.new do |t|
|
17
|
-
t.libs.push "lib"
|
18
|
-
t.test_files = FileList['test/test_warning.rb']
|
19
|
-
t.verbose = true
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Run test"
|
23
|
-
Rake::TestTask.new(:test_freeze) do |t|
|
24
|
-
t.libs.push "lib"
|
25
|
-
t.test_files = FileList['test/test_freeze_warning.rb']
|
26
|
-
t.verbose = true
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "Run all tests"
|
30
|
-
task :default=>[:test, :test_freeze]
|
31
|
-
|
32
|
-
### RDoc
|
33
|
-
|
34
|
-
RDOC_OPTS = ['--main', 'README.rdoc', "--quiet", "--line-numbers", "--inline-source", '--title', 'ruby-warning: Add custom processing for warnings']
|
35
|
-
|
36
|
-
begin
|
37
|
-
gem 'hanna-nouveau'
|
38
|
-
RDOC_OPTS.concat(['-f', 'hanna'])
|
39
|
-
rescue Gem::LoadError
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
RDoc::Task.new do |rdoc|
|
44
|
-
rdoc.rdoc_dir = "rdoc"
|
45
|
-
rdoc.options += RDOC_OPTS
|
46
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
47
|
-
end
|
data/test/test_freeze_warning.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
2
|
-
require 'minitest/global_expectations/autorun'
|
3
|
-
require 'warning'
|
4
|
-
|
5
|
-
class WarningFreezeTest < Minitest::Test
|
6
|
-
module EnvUtil
|
7
|
-
def verbose_warning
|
8
|
-
class << (stderr = "")
|
9
|
-
alias write <<
|
10
|
-
end
|
11
|
-
stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true
|
12
|
-
yield stderr
|
13
|
-
return $stderr
|
14
|
-
ensure
|
15
|
-
stderr, $stderr, $VERBOSE = $stderr, stderr, verbose
|
16
|
-
end
|
17
|
-
module_function :verbose_warning
|
18
|
-
|
19
|
-
def with_default_internal(enc)
|
20
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
21
|
-
origenc, Encoding.default_internal = Encoding.default_internal, enc
|
22
|
-
$VERBOSE = verbose
|
23
|
-
yield
|
24
|
-
ensure
|
25
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
26
|
-
Encoding.default_internal = origenc
|
27
|
-
$VERBOSE = verbose
|
28
|
-
end
|
29
|
-
module_function :with_default_internal
|
30
|
-
end
|
31
|
-
|
32
|
-
def assert_warning(pat, msg = nil)
|
33
|
-
stderr = EnvUtil.verbose_warning {
|
34
|
-
EnvUtil.with_default_internal(pat.encoding) {
|
35
|
-
yield
|
36
|
-
}
|
37
|
-
}
|
38
|
-
msg = message(msg) {diff pat, stderr}
|
39
|
-
assert(pat === stderr, msg)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_warning_ignore
|
43
|
-
obj = Object.new
|
44
|
-
w = nil
|
45
|
-
|
46
|
-
Warning.ignore(/instance variable @ivar not initialized/)
|
47
|
-
Warning.process do |warning|
|
48
|
-
w = [4, warning]
|
49
|
-
end
|
50
|
-
Warning.freeze
|
51
|
-
|
52
|
-
assert_raises RuntimeError do
|
53
|
-
Warning.ignore(/instance variable @ivar not initialized/)
|
54
|
-
end
|
55
|
-
assert_raises RuntimeError do
|
56
|
-
Warning.process{|warning| w = [4, warning]}
|
57
|
-
end
|
58
|
-
|
59
|
-
assert_warning '' do
|
60
|
-
assert_nil(obj.instance_variable_get(:@ivar))
|
61
|
-
end
|
62
|
-
assert_nil w
|
63
|
-
|
64
|
-
assert_warning '' do
|
65
|
-
assert_nil(obj.instance_variable_get(:@ivar6))
|
66
|
-
end
|
67
|
-
assert_equal(4, w.first)
|
68
|
-
assert_match(/instance variable @ivar6 not initialized/, w.last)
|
69
|
-
end
|
70
|
-
end
|
data/test/test_warning.rb
DELETED
@@ -1,515 +0,0 @@
|
|
1
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
2
|
-
require 'minitest/global_expectations/autorun'
|
3
|
-
require 'warning'
|
4
|
-
require 'pathname'
|
5
|
-
|
6
|
-
class WarningTest < Minitest::Test
|
7
|
-
module EnvUtil
|
8
|
-
def verbose_warning
|
9
|
-
stderr = ""
|
10
|
-
class << (stderr = "")
|
11
|
-
alias write <<
|
12
|
-
def puts(*a)
|
13
|
-
self << a.join("\n")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true
|
17
|
-
yield stderr
|
18
|
-
return $stderr
|
19
|
-
ensure
|
20
|
-
stderr, $stderr, $VERBOSE = $stderr, stderr, verbose
|
21
|
-
end
|
22
|
-
module_function :verbose_warning
|
23
|
-
|
24
|
-
def with_default_internal(enc)
|
25
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
26
|
-
origenc, Encoding.default_internal = Encoding.default_internal, enc
|
27
|
-
$VERBOSE = verbose
|
28
|
-
yield
|
29
|
-
ensure
|
30
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
31
|
-
Encoding.default_internal = origenc
|
32
|
-
$VERBOSE = verbose
|
33
|
-
end
|
34
|
-
module_function :with_default_internal
|
35
|
-
end
|
36
|
-
|
37
|
-
def assert_warning(pat, msg = nil)
|
38
|
-
stderr = EnvUtil.verbose_warning {
|
39
|
-
EnvUtil.with_default_internal(pat.encoding) {
|
40
|
-
yield
|
41
|
-
}
|
42
|
-
}
|
43
|
-
msg = message(msg) {diff pat, stderr}
|
44
|
-
assert(pat === stderr, msg)
|
45
|
-
end
|
46
|
-
|
47
|
-
def teardown
|
48
|
-
Warning.clear
|
49
|
-
end
|
50
|
-
|
51
|
-
def ivar
|
52
|
-
Object.new.instance_variable_get(:@ivar)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_warning_dedup
|
56
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
57
|
-
ivar
|
58
|
-
end
|
59
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
60
|
-
ivar
|
61
|
-
end
|
62
|
-
|
63
|
-
Warning.dedup
|
64
|
-
|
65
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
66
|
-
ivar
|
67
|
-
end
|
68
|
-
assert_warning('') do
|
69
|
-
ivar
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_warning_ignore
|
74
|
-
obj = Object.new
|
75
|
-
|
76
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
77
|
-
assert_nil(obj.instance_variable_get(:@ivar))
|
78
|
-
end
|
79
|
-
|
80
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
81
|
-
assert_nil(obj.instance_variable_get(:@ivar))
|
82
|
-
end
|
83
|
-
|
84
|
-
Warning.ignore(/instance variable @ivar not initialized/)
|
85
|
-
|
86
|
-
assert_warning '' do
|
87
|
-
assert_nil(obj.instance_variable_get(:@ivar))
|
88
|
-
end
|
89
|
-
|
90
|
-
assert_warning(/instance variable @ivar2 not initialized/) do
|
91
|
-
assert_nil(obj.instance_variable_get(:@ivar2))
|
92
|
-
end
|
93
|
-
|
94
|
-
Warning.ignore(/instance variable @ivar2 not initialized/, __FILE__)
|
95
|
-
|
96
|
-
assert_warning '' do
|
97
|
-
assert_nil(obj.instance_variable_get(:@ivar2))
|
98
|
-
end
|
99
|
-
|
100
|
-
assert_warning(/instance variable @ivar3 not initialized/) do
|
101
|
-
assert_nil(obj.instance_variable_get(:@ivar3))
|
102
|
-
end
|
103
|
-
|
104
|
-
Warning.ignore(/instance variable @ivar3 not initialized/, __FILE__+'a')
|
105
|
-
|
106
|
-
assert_warning(/instance variable @ivar3 not initialized/) do
|
107
|
-
assert_nil(obj.instance_variable_get(:@ivar3))
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_warning_ignore_missing_ivar
|
112
|
-
Warning.clear
|
113
|
-
|
114
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
115
|
-
assert_nil(instance_variable_get(:@ivar))
|
116
|
-
end
|
117
|
-
|
118
|
-
Warning.ignore(:missing_ivar, __FILE__)
|
119
|
-
|
120
|
-
assert_warning '' do
|
121
|
-
assert_nil(instance_variable_get(:@ivar))
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_warning_ignore_missing_gvar
|
126
|
-
assert_warning(/global variable `\$gvar' not initialized/) do
|
127
|
-
$gvar
|
128
|
-
end
|
129
|
-
|
130
|
-
Warning.ignore(:missing_gvar, __FILE__)
|
131
|
-
|
132
|
-
assert_warning '' do
|
133
|
-
$gvar
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_warning_ignore_method_redefined
|
138
|
-
def self.a; end
|
139
|
-
|
140
|
-
assert_warning(/method redefined; discarding old a.+previous definition of a was here/m) do
|
141
|
-
def self.a; end
|
142
|
-
end
|
143
|
-
|
144
|
-
Warning.ignore(:method_redefined, __FILE__)
|
145
|
-
|
146
|
-
assert_warning '' do
|
147
|
-
def self.a; end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_warning_ignore_not_reached
|
152
|
-
assert_warning(/: warning: statement not reached/) do
|
153
|
-
instance_eval('def self.b; return; 1 end', __FILE__)
|
154
|
-
end
|
155
|
-
|
156
|
-
Warning.ignore(:not_reached, __FILE__)
|
157
|
-
|
158
|
-
assert_warning '' do
|
159
|
-
instance_eval('def self.c; return; 1 end', __FILE__)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_warning_ignore_fixnum
|
164
|
-
assert_warning(/warning: constant ::Fixnum is deprecated/) do
|
165
|
-
::Fixnum
|
166
|
-
end
|
167
|
-
|
168
|
-
Warning.ignore(:fixnum, __FILE__)
|
169
|
-
|
170
|
-
assert_warning '' do
|
171
|
-
::Fixnum
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_warning_ignore_bignum
|
176
|
-
assert_warning(/warning: constant ::Bignum is deprecated/) do
|
177
|
-
::Bignum
|
178
|
-
end
|
179
|
-
|
180
|
-
Warning.ignore(:bignum, __FILE__)
|
181
|
-
|
182
|
-
assert_warning '' do
|
183
|
-
::Bignum
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_warning_ignore_ambiguous_slash
|
188
|
-
def self.d(re); end
|
189
|
-
assert_warning(/warning: ambiguous first argument; put parentheses or a space even after `\/' operator/) do
|
190
|
-
instance_eval('d /a/', __FILE__)
|
191
|
-
end
|
192
|
-
|
193
|
-
Warning.ignore(:ambiguous_slash, __FILE__)
|
194
|
-
|
195
|
-
assert_warning '' do
|
196
|
-
instance_eval('d /a/', __FILE__)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_warning_ignore_unused_var
|
201
|
-
assert_warning(/warning: assigned but unused variable - \w+/) do
|
202
|
-
instance_eval('def self.e; b = 1; 2 end', __FILE__)
|
203
|
-
end
|
204
|
-
|
205
|
-
Warning.ignore(:unused_var, __FILE__)
|
206
|
-
|
207
|
-
assert_warning '' do
|
208
|
-
instance_eval('def self.f; b = 1; 2 end', __FILE__)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_warning_ignore_useless_operator
|
213
|
-
assert_warning(/warning: possibly useless use of == in void context/) do
|
214
|
-
instance_eval('1 == 2; true', __FILE__)
|
215
|
-
end
|
216
|
-
|
217
|
-
Warning.ignore(:useless_operator, __FILE__)
|
218
|
-
|
219
|
-
assert_warning '' do
|
220
|
-
instance_eval('1 == 2; true', __FILE__)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_warning_ignore_arg_prefix
|
225
|
-
assert_warning(/: warning: `\*' interpreted as argument prefix/) do
|
226
|
-
instance_eval('Array *[nil]', __FILE__)
|
227
|
-
end
|
228
|
-
|
229
|
-
assert_warning(/: warning: `&' interpreted as argument prefix/) do
|
230
|
-
instance_eval('tap &proc{}', __FILE__)
|
231
|
-
end
|
232
|
-
Warning.ignore(:arg_prefix, __FILE__)
|
233
|
-
|
234
|
-
assert_warning '' do
|
235
|
-
instance_eval('Array *[nil]', __FILE__)
|
236
|
-
instance_eval('tap &proc{}', __FILE__)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_warning_ignore_shadow
|
241
|
-
assert_warning(/warning: shadowing outer local variable - a/) do
|
242
|
-
instance_eval('lambda{|a| lambda{|a|}}', __FILE__)
|
243
|
-
end
|
244
|
-
|
245
|
-
Warning.ignore(:shadow, __FILE__)
|
246
|
-
|
247
|
-
assert_warning '' do
|
248
|
-
instance_eval('lambda{|a| lambda{|a|}}', __FILE__)
|
249
|
-
end
|
250
|
-
end if RUBY_VERSION < '2.6'
|
251
|
-
|
252
|
-
if RUBY_VERSION > '2.7' && RUBY_VERSION < '2.8'
|
253
|
-
def h2kw(**kw)
|
254
|
-
end
|
255
|
-
def kw2h(h, **kw)
|
256
|
-
end
|
257
|
-
def skw(h=1, a: 1)
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_warning_ignore_keyword
|
261
|
-
assert_warning(/warning: Using the last argument as keyword parameters is deprecated; maybe \*\* should be added to the call.*The called method `h2kw' is defined here/m) do
|
262
|
-
h2kw({})
|
263
|
-
end
|
264
|
-
assert_warning(/warning: Passing the keyword argument as the last hash parameter is deprecated.*The called method `kw2h' is defined here/m) do
|
265
|
-
kw2h(a: 1)
|
266
|
-
end
|
267
|
-
assert_warning(/warning: Splitting the last argument into positional and keyword parameters is deprecated.*The called method `skw' is defined here/m) do
|
268
|
-
skw("b" => 1, a: 2)
|
269
|
-
end
|
270
|
-
assert_warning(/warning: Splitting the last argument into positional and keyword parameters is deprecated.*The called method `skw' is defined here/m) do
|
271
|
-
skw({"b" => 1, a: 2})
|
272
|
-
end
|
273
|
-
|
274
|
-
Warning.ignore(:keyword_separation, __FILE__)
|
275
|
-
|
276
|
-
assert_warning '' do
|
277
|
-
h2kw({})
|
278
|
-
kw2h(a: 1)
|
279
|
-
skw("b" => 1, a: 2)
|
280
|
-
skw({"b" => 1, a: 2})
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_warning_ignore_safe
|
285
|
-
assert_warning(/\$SAFE will become a normal global variable in Ruby 3\.0/) do
|
286
|
-
$SAFE = 0
|
287
|
-
end
|
288
|
-
|
289
|
-
Warning.ignore(:safe, __FILE__)
|
290
|
-
|
291
|
-
assert_warning("") do
|
292
|
-
$SAFE = 0
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
if RUBY_VERSION > '2.7' && RUBY_VERSION < '3.2'
|
298
|
-
|
299
|
-
def test_warning_ignore_taint
|
300
|
-
o = Object.new
|
301
|
-
|
302
|
-
assert_warning(/Object#taint is deprecated and will be removed in Ruby 3\.2/) do
|
303
|
-
o.taint
|
304
|
-
end
|
305
|
-
assert_warning(/Object#untaint is deprecated and will be removed in Ruby 3\.2/) do
|
306
|
-
o.untaint
|
307
|
-
end
|
308
|
-
assert_warning(/Object#tainted\? is deprecated and will be removed in Ruby 3\.2/) do
|
309
|
-
o.tainted?
|
310
|
-
end
|
311
|
-
assert_warning(/Object#trust is deprecated and will be removed in Ruby 3\.2/) do
|
312
|
-
o.trust
|
313
|
-
end
|
314
|
-
assert_warning(/Object#untrust is deprecated and will be removed in Ruby 3\.2/) do
|
315
|
-
o.untrust
|
316
|
-
end
|
317
|
-
assert_warning(/Object#untrusted\? is deprecated and will be removed in Ruby 3\.2/) do
|
318
|
-
o.untrusted?
|
319
|
-
end
|
320
|
-
|
321
|
-
path = Pathname.new(__FILE__)
|
322
|
-
assert_warning(/Pathname#taint is deprecated and will be removed in Ruby 3\.2/) do
|
323
|
-
path.taint
|
324
|
-
end
|
325
|
-
assert_warning(/Pathname#untaint is deprecated and will be removed in Ruby 3\.2/) do
|
326
|
-
path.untaint
|
327
|
-
end
|
328
|
-
|
329
|
-
Warning.ignore(:taint, __FILE__)
|
330
|
-
|
331
|
-
assert_warning("") do
|
332
|
-
o.taint
|
333
|
-
o.untaint
|
334
|
-
o.tainted?
|
335
|
-
o.trust
|
336
|
-
o.untrust
|
337
|
-
o.untrusted?
|
338
|
-
p.taint
|
339
|
-
p.untaint
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
def test_warning_ignore_symbol_array
|
345
|
-
def self.c; end
|
346
|
-
|
347
|
-
assert_warning(/statement not reached.+method redefined; discarding old c.+previous definition of c was here/m) do
|
348
|
-
instance_eval('def self.c; return; 1 end', __FILE__)
|
349
|
-
end
|
350
|
-
|
351
|
-
Warning.ignore([:method_redefined, :not_reached], __FILE__)
|
352
|
-
|
353
|
-
assert_warning '' do
|
354
|
-
instance_eval('def self.c; return; 1 end', __FILE__)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_warning_ignore_mismatched_indentation
|
359
|
-
assert_warning(/warning: mismatched indentations/) do
|
360
|
-
load 'test/fixtures/mismatched_indentations.rb'
|
361
|
-
end
|
362
|
-
|
363
|
-
Warning.ignore(:mismatched_indentations, 'test/fixtures/mismatched_indentations.rb')
|
364
|
-
|
365
|
-
assert_warning '' do
|
366
|
-
load 'test/fixtures/mismatched_indentations.rb'
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
def test_warning_process
|
371
|
-
obj = Object.new
|
372
|
-
warn = nil
|
373
|
-
|
374
|
-
Warning.process(__FILE__+'a') do |warning|
|
375
|
-
warn = [0, warning]
|
376
|
-
end
|
377
|
-
|
378
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
379
|
-
assert_nil(obj.instance_variable_get(:@ivar))
|
380
|
-
end
|
381
|
-
assert_nil(warn)
|
382
|
-
|
383
|
-
Warning.process(__FILE__) do |warning|
|
384
|
-
warn = [1, warning]
|
385
|
-
end
|
386
|
-
|
387
|
-
assert_warning '' do
|
388
|
-
assert_nil(obj.instance_variable_get(:@ivar2))
|
389
|
-
end
|
390
|
-
assert_equal(1, warn.first)
|
391
|
-
assert_match(/instance variable @ivar2 not initialized/, warn.last)
|
392
|
-
warn = nil
|
393
|
-
|
394
|
-
Warning.process(File.dirname(__FILE__)) do |warning|
|
395
|
-
warn = [2, warning]
|
396
|
-
end
|
397
|
-
|
398
|
-
assert_warning '' do
|
399
|
-
assert_nil(obj.instance_variable_get(:@ivar3))
|
400
|
-
end
|
401
|
-
assert_equal(1, warn.first)
|
402
|
-
assert_match(/instance variable @ivar3 not initialized/, warn.last)
|
403
|
-
warn = nil
|
404
|
-
|
405
|
-
Warning.process(__FILE__+':') do |warning|
|
406
|
-
warn = [3, warning]
|
407
|
-
end
|
408
|
-
|
409
|
-
assert_warning '' do
|
410
|
-
assert_nil(obj.instance_variable_get(:@ivar4))
|
411
|
-
end
|
412
|
-
assert_equal(3, warn.first)
|
413
|
-
assert_match(/instance variable @ivar4 not initialized/, warn.last)
|
414
|
-
warn = nil
|
415
|
-
|
416
|
-
Warning.clear
|
417
|
-
|
418
|
-
assert_warning(/instance variable @ivar5 not initialized/) do
|
419
|
-
assert_nil(obj.instance_variable_get(:@ivar5))
|
420
|
-
end
|
421
|
-
assert_nil(warn)
|
422
|
-
|
423
|
-
Warning.process do |warning|
|
424
|
-
warn = [4, warning]
|
425
|
-
end
|
426
|
-
|
427
|
-
assert_warning '' do
|
428
|
-
assert_nil(obj.instance_variable_get(:@ivar6))
|
429
|
-
end
|
430
|
-
assert_equal(4, warn.first)
|
431
|
-
assert_match(/instance variable @ivar6 not initialized/, warn.last)
|
432
|
-
end
|
433
|
-
|
434
|
-
def test_warning_process_block_return_default
|
435
|
-
w = nil
|
436
|
-
Warning.process(__FILE__) do |warning|
|
437
|
-
w = warning
|
438
|
-
:default
|
439
|
-
end
|
440
|
-
|
441
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
442
|
-
ivar
|
443
|
-
end
|
444
|
-
assert_match(/instance variable @ivar not initialized/, w)
|
445
|
-
end
|
446
|
-
|
447
|
-
def test_warning_process_block_return_backtrace
|
448
|
-
w = nil
|
449
|
-
Warning.process(__FILE__) do |warning|
|
450
|
-
w = warning
|
451
|
-
:backtrace
|
452
|
-
end
|
453
|
-
|
454
|
-
assert_warning(/instance variable @ivar not initialized.*#{__FILE__}/m) do
|
455
|
-
ivar
|
456
|
-
end
|
457
|
-
assert_match(/instance variable @ivar not initialized/, w)
|
458
|
-
end
|
459
|
-
|
460
|
-
def test_warning_process_block_return_raise
|
461
|
-
w = nil
|
462
|
-
Warning.process(__FILE__) do |warning|
|
463
|
-
w = warning
|
464
|
-
:raise
|
465
|
-
end
|
466
|
-
|
467
|
-
assert_raises(RuntimeError, /instance variable @ivar not initialized/) do
|
468
|
-
EnvUtil.verbose_warning{ivar}
|
469
|
-
end
|
470
|
-
assert_match(/instance variable @ivar not initialized/, w)
|
471
|
-
end
|
472
|
-
|
473
|
-
def test_warning_process_action
|
474
|
-
w = nil
|
475
|
-
Warning.process(__FILE__, :missing_ivar=>:default, :missing_gvar=>:backtrace, :ambiguous_slash=>:raise)
|
476
|
-
Warning.process(__FILE__, :not_reached=>proc do |warning|
|
477
|
-
w = warning
|
478
|
-
:raise
|
479
|
-
end)
|
480
|
-
|
481
|
-
assert_warning(/instance variable @ivar not initialized/) do
|
482
|
-
ivar
|
483
|
-
end
|
484
|
-
|
485
|
-
assert_warning(/global variable `\$gvar' not initialized.*#{__FILE__}/m) do
|
486
|
-
$gvar
|
487
|
-
end
|
488
|
-
|
489
|
-
Warning.process(__FILE__) do |warning|
|
490
|
-
w = warning
|
491
|
-
:raise
|
492
|
-
end
|
493
|
-
|
494
|
-
assert_raises(RuntimeError, /warning: ambiguous first argument; put parentheses or a space even after `\/' operator/) do
|
495
|
-
EnvUtil.verbose_warning{instance_eval('d /a/', __FILE__)}
|
496
|
-
end
|
497
|
-
|
498
|
-
assert_raises(RuntimeError, /warning: statement not reached/) do
|
499
|
-
EnvUtil.verbose_warning{instance_eval('def self.b; return; 1 end', __FILE__)}
|
500
|
-
end
|
501
|
-
assert_match(/warning: statement not reached/, w)
|
502
|
-
end
|
503
|
-
|
504
|
-
def test_warning_process_action_and_block
|
505
|
-
assert_raises(ArgumentError) do
|
506
|
-
Warning.process(__FILE__)
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
def test_warning_process_no_action_and_no_block
|
511
|
-
assert_raises(ArgumentError) do
|
512
|
-
Warning.process(__FILE__, :missing_ivar=>:default){}
|
513
|
-
end
|
514
|
-
end
|
515
|
-
end
|