Skip to content

Commit 7bd007a

Browse files
authored
Merge pull request #13 from Shopify/ruby3
Fix tests for ruby 3, which no longer skips C stack frames
2 parents 1645bf0 + 872c117 commit 7bd007a

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
3+
on:
4+
push
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
ruby: [
13+
'2.6', # minimum supported
14+
'2.7', # latest passing tests
15+
]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: ${{ matrix.ruby }}
21+
bundler-cache: true
22+
- run: bundle exec rake

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

stack_frames.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
2525
spec.require_paths = ["lib"]
2626

2727
spec.add_development_dependency "bundler"
28-
spec.add_development_dependency "rake", "~> 10.0"
28+
spec.add_development_dependency "rake", "~> 13.0"
2929
spec.add_development_dependency 'rake-compiler', '~> 1.0'
3030
spec.add_development_dependency "minitest", "~> 5.0"
3131
spec.add_development_dependency "stackprof", "~> 0.2.13"

test/stack_frames/buffer_test.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def test_new_with_invalid_capacity
1717
end
1818

1919
def test_capture
20-
buffer = StackFrames::Buffer.new(1)
20+
buffer = StackFrames::Buffer.new(2)
2121
expected_line = __LINE__ + 1
2222
frames_length = buffer.capture
23-
assert_equal(1, frames_length)
24-
frame = buffer[0]
23+
assert_equal(2, frames_length)
24+
frame = buffer[skipping_c_frames? ? 0 : 1]
2525
assert_equal('test_capture', frame.method_name)
2626
assert_equal(true, frame.method_name.frozen?)
2727
assert_equal(__FILE__, frame.path)
@@ -36,13 +36,16 @@ def test_no_object_allocations
3636
got_path = nil
3737
got_lineno = nil
3838
got_method_name = nil
39-
num_allocations = count_allocations do
39+
frame_index = skipping_c_frames? ? 1 : 3
40+
instrumented_code = lambda do
4041
buffer.capture
41-
frame = buffer[1]
42+
frame = buffer[frame_index]
4243
got_path = frame.path
4344
got_lineno = frame.lineno
4445
got_method_name = frame.method_name
4546
end
47+
count_allocations(&instrumented_code) # allow lazy memoized allocations
48+
num_allocations = count_allocations(&instrumented_code)
4649
assert_equal(0, num_allocations)
4750
assert_equal('count_allocations', got_method_name)
4851
assert_equal(method(:count_allocations).source_location[1] + 1, got_lineno)
@@ -55,12 +58,19 @@ def test_index_lookup
5558
frame1 do
5659
buffer.capture
5760
end
61+
skipped = 0
5862
[
59-
["test_index_lookup", capture_lineno],
60-
["frame1", method(:frame1).source_location[1] + 1],
61-
["test_index_lookup", capture_lineno - 1],
62-
].each_with_index do |(method_name, lineno), i|
63-
frame = buffer[i]
63+
[:c, "capture", 0],
64+
[:ruby, "test_index_lookup", capture_lineno],
65+
[:ruby, "frame1", method(:frame1).source_location[1] + 1],
66+
[:ruby, "test_index_lookup", capture_lineno - 1],
67+
].each_with_index do |(lang, method_name, lineno), i|
68+
if skipping_c_frames? && lang == :c
69+
skipped += 1
70+
next
71+
end
72+
buffer_idx = i - skipped
73+
frame = buffer[buffer_idx]
6474
assert_equal(method_name, frame.method_name, "frame #{i}")
6575
assert_equal(lineno, frame.lineno, "frame #{i}")
6676
end
@@ -107,6 +117,10 @@ def test_gc_stress
107117

108118
private
109119

120+
def skipping_c_frames?
121+
Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3")
122+
end
123+
110124
def frame1
111125
yield
112126
end

0 commit comments

Comments
 (0)