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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion stack_frames.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 24 additions & 10 deletions test/stack_frames/buffer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down