Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruby 3 test suite #152

Merged
merged 2 commits into from Apr 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,43 @@
name: CI

on: [push, pull_request]

jobs:
rubies:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [ ruby-head, '3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2' ]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install
- name: Run test
run: rake
- name: Install gem
run: rake install
platforms:
strategy:
matrix:
os: [macos, windows]
ruby: ['3.0']
runs-on: ${{ matrix.os }}-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install
- name: Run test
run: rake
- name: Install gem
run: rake install
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

36 changes: 11 additions & 25 deletions Rakefile
@@ -1,31 +1,17 @@
task :default => :test
require "bundler/gem_tasks"
require "rake/testtask"

# ==========================================================
# Packaging
# ==========================================================

GEMSPEC = Gem::Specification::load('stackprof.gemspec')

require 'rubygems/package_task'
Gem::PackageTask.new(GEMSPEC) do |pkg|
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/test_*.rb"]
end

# ==========================================================
# Ruby Extension
# ==========================================================
require "rake/extensiontask"

require 'rake/extensiontask'
Rake::ExtensionTask.new('stackprof', GEMSPEC) do |ext|
ext.lib_dir = 'lib/stackprof'
Rake::ExtensionTask.new("stackprof") do |ext|
ext.ext_dir = "ext/stackprof"
ext.lib_dir = "lib/stackprof"
end
task :build => :compile

# ==========================================================
# Testing
# ==========================================================

require 'rake/testtask'
Rake::TestTask.new 'test' do |t|
t.test_files = FileList['test/test_*.rb']
end
task :test => :build
task default: %i(compile test)
45 changes: 36 additions & 9 deletions test/test_stackprof.rb
Expand Up @@ -39,16 +39,30 @@ def test_object_allocation
end
assert_equal :object, profile[:mode]
assert_equal 1, profile[:interval]
assert_equal 2, profile[:samples]
if RUBY_VERSION >= '3'
assert_equal 4, profile[:samples]
else
assert_equal 2, profile[:samples]
end

frame = profile[:frames].values.first
assert_includes frame[:name], "StackProfTest#test_object_allocation"
assert_equal 2, frame[:samples]
assert_includes [profile_base_line - 2, profile_base_line], frame[:line]
assert_equal [1, 1], frame[:lines][profile_base_line+1]
assert_equal [1, 1], frame[:lines][profile_base_line+2]
if RUBY_VERSION >= '3'
assert_equal [2, 1], frame[:lines][profile_base_line+1]
assert_equal [2, 1], frame[:lines][profile_base_line+2]
else
assert_equal [1, 1], frame[:lines][profile_base_line+1]
assert_equal [1, 1], frame[:lines][profile_base_line+2]
end
frame = profile[:frames].values[1] if RUBY_VERSION < '2.3'
assert_equal [2, 0], frame[:lines][profile_base_line]

if RUBY_VERSION >= '3'
assert_equal [4, 0], frame[:lines][profile_base_line]
else
assert_equal [2, 0], frame[:lines][profile_base_line]
end
end

def test_object_allocation_interval
Expand All @@ -64,7 +78,8 @@ def test_cputime
end

assert_operator profile[:samples], :>=, 1
frame = profile[:frames].values.first
offset = RUBY_VERSION >= '3' ? 1 : 0
frame = profile[:frames].values[offset]
assert_includes frame[:name], "StackProfTest#math"
end

Expand All @@ -74,7 +89,11 @@ def test_walltime
end

frame = profile[:frames].values.first
assert_equal "StackProfTest#idle", frame[:name]
if RUBY_VERSION >= '3'
assert_equal "IO.select", frame[:name]
else
assert_equal "StackProfTest#idle", frame[:name]
end
assert_in_delta 200, frame[:samples], 25
end

Expand All @@ -89,10 +108,16 @@ def test_custom
assert_equal :custom, profile[:mode]
assert_equal 10, profile[:samples]

frame = profile[:frames].values.first
offset = RUBY_VERSION >= '3' ? 1 : 0
frame = profile[:frames].values[offset]
assert_includes frame[:name], "StackProfTest#test_custom"
assert_includes [profile_base_line-2, profile_base_line+1], frame[:line]
assert_equal [10, 10], frame[:lines][profile_base_line+2]

if RUBY_VERSION >= '3'
assert_equal [10, 0], frame[:lines][profile_base_line+2]
else
assert_equal [10, 10], frame[:lines][profile_base_line+2]
end
end

def test_raw
Expand All @@ -105,7 +130,9 @@ def test_raw
raw = profile[:raw]
assert_equal 10, raw[-1]
assert_equal raw[0] + 2, raw.size
assert_includes profile[:frames][raw[-2]][:name], 'StackProfTest#test_raw'

offset = RUBY_VERSION >= '3' ? -3 : -2
assert_includes profile[:frames][raw[offset]][:name], 'StackProfTest#test_raw'
assert_equal 10, profile[:raw_timestamp_deltas].size
end

Expand Down