Skip to content

Commit 5c5eb7f

Browse files
authored
Merge pull request #57 from k-tsj/drop-below-3_1
Drop support for ruby < 3.1
2 parents a7dab94 + e02c651 commit 5c5eb7f

File tree

10 files changed

+127
-196
lines changed

10 files changed

+127
-196
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
66
with:
77
engine: cruby
8-
min_version: 2.5
8+
min_version: 3.1
99
test:
1010
needs: ruby-versions
1111
name: >-
@@ -21,9 +21,6 @@ jobs:
2121
os: "ubuntu-latest"
2222
TEST_SYMLINK: yes
2323
rubyopt: "--enable-frozen-string-literal"
24-
exclude:
25-
- ruby-version: "2.5"
26-
os: "macos-latest"
2724
runs-on: ${{ matrix.os }}
2825
env:
2926
TEST_SYMLINK: ${{ matrix.TEST_SYMLINK }}

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ group :development do
1212
gem 'test-unit'
1313
gem 'rake'
1414
gem 'simplecov'
15-
gem 'bundler'
1615
gem 'irb', '>= 1.3.1'
1716
gem 'benchmark-ips'
1817
end

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ Use following test frameworks or extensions instead.
2424
* [power_p](https://github.com/k-tsj/power_p)
2525

2626
## Requirement
27-
* CRuby 2.5+
27+
* CRuby 3.1+
2828

2929
## Configuration
3030
To colorize output messages, add <code>require "power_assert/colorize"</code> to your code.
31-
(It requires CRuby 3.0.1+ or irb 1.3.1+)
31+
(It requires irb 1.3.1+)
3232

3333
## Known Limitations
3434
* Expressions must be put in one line. Expressions with folded long lines produce nothing report, e.g.:
@@ -61,23 +61,19 @@ assert do
6161
end
6262
```
6363

64-
* Returned values from accessor methods, method missing, or "super" produce nothing report, e.g:
64+
* Returned values from method missing, or "super" produce nothing report, e.g:
6565

6666
```ruby
6767
class Foo
68-
attr_accessor :val
68+
def method_missing(*)
69+
:foo
70+
end
6971
end
7072
foo = Foo.new
71-
foo.val = false
72-
73-
assert do
74-
# reported (only the value of "foo" and the literal "true")
75-
foo.val == true
76-
end
7773

7874
assert do
7975
# won't be reported
80-
foo.val
76+
foo.foo
8177
end
8278
```
8379

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: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +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-
verbose = $VERBOSE
12-
begin
13-
$VERBOSE = nil
14-
[:Fixnum, :Bignum].each do |c|
15-
if Object.const_defined?(c) and (c = Object.const_get(c)) != Integer
16-
basic_classes << c
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) {}
1724
end
1825
end
19-
ensure
20-
$VERBOSE = verbose
2126
end
27+
end
2228

23-
basic_operators = [
24-
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
25-
:empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
26-
# :call (it is just used for block call optimization)
27-
:&, :|,
28-
# :default (no specialized instruction for this)
29-
:pack, :include?,
30-
]
31-
32-
basic_classes.each do |klass|
33-
basic_operators.each do |bop|
34-
if klass.public_method_defined?(bop)
35-
refine(klass) do
36-
define_method(bop) {}
37-
end
38-
end
39-
end
29+
# bypass check_cfunc
30+
refine BasicObject do
31+
def !
4032
end
4133

42-
# bypass check_cfunc
43-
refine BasicObject do
44-
def !
45-
end
46-
47-
def ==
48-
end
34+
def ==
4935
end
36+
end
5037

51-
refine Module do
52-
def ==
53-
end
38+
refine Module do
39+
def ==
5440
end
41+
end
5542

56-
refine Class do
57-
def new
58-
end
43+
refine Class do
44+
def new
5945
end
6046
end
6147
end
62-
63-
# disable optimization
64-
RubyVM::InstructionSequence.compile_option = {
65-
specialized_instruction: false
66-
}
6748
end
49+
50+
# disable optimization
51+
RubyVM::InstructionSequence.compile_option = {
52+
specialized_instruction: false
53+
}

0 commit comments

Comments
 (0)