diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f80c10c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: Tests + +on: + push + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: [ + '2.6', # minimum supported + '2.7', # latest passing tests + ] + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 279ff7f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -sudo: false -language: ruby -cache: bundler -rvm: - - 2.4.9 # minimum supported - - 2.7.0 # latest released -before_install: gem install bundler -v 1.17.3 diff --git a/stack_frames.gemspec b/stack_frames.gemspec index 742a294..fa864dd 100644 --- a/stack_frames.gemspec +++ b/stack_frames.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_development_dependency "bundler" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency 'rake-compiler', '~> 1.0' spec.add_development_dependency "minitest", "~> 5.0" spec.add_development_dependency "stackprof", "~> 0.2.13" diff --git a/test/stack_frames/buffer_test.rb b/test/stack_frames/buffer_test.rb index 2b4c967..1b65b37 100644 --- a/test/stack_frames/buffer_test.rb +++ b/test/stack_frames/buffer_test.rb @@ -17,11 +17,11 @@ def test_new_with_invalid_capacity end def test_capture - buffer = StackFrames::Buffer.new(1) + buffer = StackFrames::Buffer.new(2) expected_line = __LINE__ + 1 frames_length = buffer.capture - assert_equal(1, frames_length) - frame = buffer[0] + assert_equal(2, frames_length) + frame = buffer[skipping_c_frames? ? 0 : 1] assert_equal('test_capture', frame.method_name) assert_equal(true, frame.method_name.frozen?) assert_equal(__FILE__, frame.path) @@ -36,13 +36,16 @@ def test_no_object_allocations got_path = nil got_lineno = nil got_method_name = nil - num_allocations = count_allocations do + frame_index = skipping_c_frames? ? 1 : 3 + instrumented_code = lambda do buffer.capture - frame = buffer[1] + frame = buffer[frame_index] got_path = frame.path got_lineno = frame.lineno got_method_name = frame.method_name end + count_allocations(&instrumented_code) # allow lazy memoized allocations + num_allocations = count_allocations(&instrumented_code) assert_equal(0, num_allocations) assert_equal('count_allocations', got_method_name) assert_equal(method(:count_allocations).source_location[1] + 1, got_lineno) @@ -55,12 +58,19 @@ def test_index_lookup frame1 do buffer.capture end + skipped = 0 [ - ["test_index_lookup", capture_lineno], - ["frame1", method(:frame1).source_location[1] + 1], - ["test_index_lookup", capture_lineno - 1], - ].each_with_index do |(method_name, lineno), i| - frame = buffer[i] + [:c, "capture", 0], + [:ruby, "test_index_lookup", capture_lineno], + [:ruby, "frame1", method(:frame1).source_location[1] + 1], + [:ruby, "test_index_lookup", capture_lineno - 1], + ].each_with_index do |(lang, method_name, lineno), i| + if skipping_c_frames? && lang == :c + skipped += 1 + next + end + buffer_idx = i - skipped + frame = buffer[buffer_idx] assert_equal(method_name, frame.method_name, "frame #{i}") assert_equal(lineno, frame.lineno, "frame #{i}") end @@ -107,6 +117,10 @@ def test_gc_stress private + def skipping_c_frames? + Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3") + end + def frame1 yield end