Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
with:
engine: cruby
min_version: 2.5
min_version: 3.1
test:
needs: ruby-versions
name: >-
Expand All @@ -21,9 +21,6 @@ jobs:
os: "ubuntu-latest"
TEST_SYMLINK: yes
rubyopt: "--enable-frozen-string-literal"
exclude:
- ruby-version: "2.5"
os: "macos-latest"
runs-on: ${{ matrix.os }}
env:
TEST_SYMLINK: ${{ matrix.TEST_SYMLINK }}
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ group :development do
gem 'test-unit'
gem 'rake'
gem 'simplecov'
gem 'bundler'
gem 'irb', '>= 1.3.1'
gem 'benchmark-ips'
end
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Use following test frameworks or extensions instead.
* [power_p](https://github.com/k-tsj/power_p)

## Requirement
* CRuby 2.5+
* CRuby 3.1+

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

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

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

```ruby
class Foo
attr_accessor :val
def method_missing(*)
:foo
end
end
foo = Foo.new
foo.val = false

assert do
# reported (only the value of "foo" and the literal "true")
foo.val == true
end

assert do
# won't be reported
foo.val
foo.foo
end
```

Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Rake::TestTask.new(:test) do |t|
t.ruby_opts = ["-w", "-r#{helper_path}"]
t.test_files = FileList["test/**/*_test.rb"].exclude do |i|
begin
next false unless defined?(RubyVM)
RubyVM::InstructionSequence.compile(File.read(i))
false
rescue SyntaxError
Expand Down
14 changes: 5 additions & 9 deletions lib/power_assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ module PowerAssert

class << self
def start(assertion_proc_or_source, assertion_method: nil, source_binding: TOPLEVEL_BINDING)
if respond_to?(:clear_global_method_cache, true)
clear_global_method_cache
end
clear_global_method_cache
yield Context.new(assertion_proc_or_source, assertion_method, source_binding)
end

Expand All @@ -51,13 +49,11 @@ def internal_file?(file)
end
end

if defined?(RubyVM)
CLEAR_CACHE_ISEQ = RubyVM::InstructionSequence.compile('using PowerAssert.const_get(:Empty)')
private_constant :CLEAR_CACHE_ISEQ
CLEAR_CACHE_ISEQ = RubyVM::InstructionSequence.compile('using PowerAssert.const_get(:Empty)')
private_constant :CLEAR_CACHE_ISEQ

def clear_global_method_cache
CLEAR_CACHE_ISEQ.eval
end
def clear_global_method_cache
CLEAR_CACHE_ISEQ.eval
end
end

Expand Down
88 changes: 37 additions & 51 deletions lib/power_assert/enable_tracepoint_events.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,53 @@
require 'power_assert/configuration'

if defined?(RubyVM)
if PowerAssert.configuration._redefinition
module PowerAssert
# set redefined flag
basic_classes = [
Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass
]

verbose = $VERBOSE
begin
$VERBOSE = nil
[:Fixnum, :Bignum].each do |c|
if Object.const_defined?(c) and (c = Object.const_get(c)) != Integer
basic_classes << c
if PowerAssert.configuration._redefinition
module PowerAssert
# set redefined flag
basic_classes = [
Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass
]

basic_operators = [
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
:empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
# :call (it is just used for block call optimization)
:&, :|,
# :default (no specialized instruction for this)
:pack, :include?,
]

basic_classes.each do |klass|
basic_operators.each do |bop|
if klass.public_method_defined?(bop)
refine(klass) do
define_method(bop) {}
end
end
ensure
$VERBOSE = verbose
end
end

basic_operators = [
:+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
:empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
# :call (it is just used for block call optimization)
:&, :|,
# :default (no specialized instruction for this)
:pack, :include?,
]

basic_classes.each do |klass|
basic_operators.each do |bop|
if klass.public_method_defined?(bop)
refine(klass) do
define_method(bop) {}
end
end
end
# bypass check_cfunc
refine BasicObject do
def !
end

# bypass check_cfunc
refine BasicObject do
def !
end

def ==
end
def ==
end
end

refine Module do
def ==
end
refine Module do
def ==
end
end

refine Class do
def new
end
refine Class do
def new
end
end
end

# disable optimization
RubyVM::InstructionSequence.compile_option = {
specialized_instruction: false
}
end

# disable optimization
RubyVM::InstructionSequence.compile_option = {
specialized_instruction: false
}
Loading
Loading