|
8 | 8 | Warning[:deprecated] = true
|
9 | 9 | Warning[:experimental] = false
|
10 | 10 | end
|
11 |
| - |
12 |
| -if Object.const_defined?(:Warning) and Warning.respond_to?(:warn) |
13 |
| - def Warning.warn(message, category: nil) |
14 |
| - # Suppress any warning inside the method to prevent recursion |
15 |
| - verbose = $VERBOSE |
16 |
| - $VERBOSE = nil |
17 |
| - |
18 |
| - if Thread.current[:in_mspec_complain_matcher] |
19 |
| - return $stderr.write(message) |
20 |
| - end |
21 |
| - |
22 |
| - case message |
23 |
| - # $VERBOSE = true warnings |
24 |
| - when /(.+\.rb):(\d+):.+possibly useless use of (<|<=|==|>=|>) in void context/ |
25 |
| - # Make sure there is a .should otherwise it is missing |
26 |
| - line_nb = Integer($2) |
27 |
| - unless File.exist?($1) and /\.should(_not)? (<|<=|==|>=|>)/ === File.readlines($1)[line_nb-1] |
28 |
| - $stderr.write message |
29 |
| - end |
30 |
| - when /possibly useless use of (\+|-) in void context/ |
31 |
| - when /assigned but unused variable/ |
32 |
| - when /method redefined/ |
33 |
| - when /previous definition of/ |
34 |
| - when /instance variable @.+ not initialized/ |
35 |
| - when /statement not reached/ |
36 |
| - when /shadowing outer local variable/ |
37 |
| - when /setting Encoding.default_(in|ex)ternal/ |
38 |
| - when /unknown (un)?pack directive/ |
39 |
| - when /(un)?trust(ed\?)? is deprecated/ |
40 |
| - when /\.exists\? is a deprecated name/ |
41 |
| - when /Float .+ out of range/ |
42 |
| - when /passing a block to String#(bytes|chars|codepoints|lines) is deprecated/ |
43 |
| - when /core\/string\/modulo_spec\.rb:\d+: warning: too many arguments for format string/ |
44 |
| - when /regexp\/shared\/new_ascii(_8bit)?\.rb:\d+: warning: Unknown escape .+ is ignored/ |
45 |
| - else |
46 |
| - $stderr.write message |
47 |
| - end |
48 |
| - ensure |
49 |
| - $VERBOSE = verbose |
50 |
| - end |
51 |
| -else |
52 |
| - $VERBOSE = nil unless ENV['OUTPUT_WARNINGS'] |
53 |
| -end |
0 commit comments