Skip to content

Commit e02c651

Browse files
committed
Remove code intended for non-MRI implementations
The code was written expecting JRuby to support TracePoint, but it still hasn't been implemented. To keep the codebase simple, removing it until truly needed.
1 parent f567011 commit e02c651

File tree

7 files changed

+53
-63
lines changed

7 files changed

+53
-63
lines changed

Rakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Rake::TestTask.new(:test) do |t|
88
t.ruby_opts = ["-w", "-r#{helper_path}"]
99
t.test_files = FileList["test/**/*_test.rb"].exclude do |i|
1010
begin
11-
next false unless defined?(RubyVM)
1211
RubyVM::InstructionSequence.compile(File.read(i))
1312
false
1413
rescue SyntaxError

lib/power_assert.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ module PowerAssert
2828

2929
class << self
3030
def start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING)
31-
if respond_to?(:clear_global_method_cache, true)
32-
clear_global_method_cache
33-
end
31+
clear_global_method_cache
3432
yield Context.new(assertion_proc_or_source, assertion_method, source_binding)
3533
end
3634

@@ -51,13 +49,11 @@ def internal_file?(file)
5149
end
5250
end
5351

54-
if defined?(RubyVM)
55-
CLEAR_CACHE_ISEQ = RubyVM::InstructionSequence.compile('using PowerAssert.const_get(:Empty)')
56-
private_constant :CLEAR_CACHE_ISEQ
52+
CLEAR_CACHE_ISEQ = RubyVM::InstructionSequence.compile('using PowerAssert.const_get(:Empty)')
53+
private_constant :CLEAR_CACHE_ISEQ
5754

58-
def clear_global_method_cache
59-
CLEAR_CACHE_ISEQ.eval
60-
end
55+
def clear_global_method_cache
56+
CLEAR_CACHE_ISEQ.eval
6157
end
6258
end
6359

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,53 @@
11
require 'power_assert/configuration'
22

3-
if defined?(RubyVM)
4-
if PowerAssert.configuration._redefinition
5-
module PowerAssert
6-
# set redefined flag
7-
basic_classes = [
8-
Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass
9-
]
10-
11-
basic_operators = [
12-
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
13-
:empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
14-
# :call (it is just used for block call optimization)
15-
:&, :|,
16-
# :default (no specialized instruction for this)
17-
:pack, :include?,
18-
]
19-
20-
basic_classes.each do |klass|
21-
basic_operators.each do |bop|
22-
if klass.public_method_defined?(bop)
23-
refine(klass) do
24-
define_method(bop) {}
25-
end
3+
if PowerAssert.configuration._redefinition
4+
module PowerAssert
5+
# set redefined flag
6+
basic_classes = [
7+
Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass
8+
]
9+
10+
basic_operators = [
11+
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
12+
:empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
13+
# :call (it is just used for block call optimization)
14+
:&, :|,
15+
# :default (no specialized instruction for this)
16+
:pack, :include?,
17+
]
18+
19+
basic_classes.each do |klass|
20+
basic_operators.each do |bop|
21+
if klass.public_method_defined?(bop)
22+
refine(klass) do
23+
define_method(bop) {}
2624
end
2725
end
2826
end
27+
end
2928

30-
# bypass check_cfunc
31-
refine BasicObject do
32-
def !
33-
end
29+
# bypass check_cfunc
30+
refine BasicObject do
31+
def !
32+
end
3433

35-
def ==
36-
end
34+
def ==
3735
end
36+
end
3837

39-
refine Module do
40-
def ==
41-
end
38+
refine Module do
39+
def ==
4240
end
41+
end
4342

44-
refine Class do
45-
def new
46-
end
43+
refine Class do
44+
def new
4745
end
4846
end
4947
end
50-
51-
# disable optimization
52-
RubyVM::InstructionSequence.compile_option = {
53-
specialized_instruction: false
54-
}
5548
end
49+
50+
# disable optimization
51+
RubyVM::InstructionSequence.compile_option = {
52+
specialized_instruction: false
53+
}

lib/power_assert/parser.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ def method_id_set
3333
private
3434

3535
def valid_syntax?(str)
36-
return true unless defined?(RubyVM)
37-
begin
38-
verbose, $VERBOSE = $VERBOSE, nil
39-
RubyVM::InstructionSequence.compile(str)
40-
true
41-
rescue SyntaxError
42-
false
43-
ensure
44-
$VERBOSE = verbose
45-
end
36+
verbose, $VERBOSE = $VERBOSE, nil
37+
RubyVM::InstructionSequence.compile(str)
38+
true
39+
rescue SyntaxError
40+
false
41+
ensure
42+
$VERBOSE = verbose
4643
end
4744

4845
def slice_expression(str)

test/block_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined?(RubyVM) and ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
1+
if ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
22
warn "#{__FILE__}: specialized_instruction is set to false"
33
end
44

test/dyna_symbol_key_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined?(RubyVM) and ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
1+
if ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
22
warn "#{__FILE__}: specialized_instruction is set to false"
33
end
44

test/safe_op_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if defined?(RubyVM) and ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
1+
if ! RubyVM::InstructionSequence.compile_option[:specialized_instruction]
22
warn "#{__FILE__}: specialized_instruction is set to false"
33
end
44

0 commit comments

Comments
 (0)