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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby: ["3.1", "3.2", "3.3"]
ruby: ["3.1", "3.2", "3.3", "3.4", "4.0"]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/gems/longhorn-0.1.0/lib/longhorn.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'set'
require 'erb'

module Longhorn
def self.run
result = Set.new
result = []
["allocated", "retained"]
.product(["memory", "objects"])
.product(["gem", "file", "location", "class"])
.each do |(type, metric), name|
result << "#{type} #{metric} by #{name}"
result << ERB.new("<%= type %> <%= metric %> by <%= name %>").result(binding)
end
result
end
Expand Down
14 changes: 7 additions & 7 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ def test_ignore_specific_files
out, _err = capture_io do
@cli.run([@script_file])
end
assert_includes out, "set.rb"
assert_includes out, STDLIB_FILE

out, _err = capture_io do
@cli.run(["--ignore-files=set.rb", @script_file])
@cli.run(["--ignore-files=#{STDLIB_FILE}", @script_file])
end
refute_includes out, "set.rb"
refute_includes out, STDLIB_FILE
end

def test_allow_specific_files
assert_output(/set\.rb/) { @cli.run([@script_file]) }
assert_output(/#{Regexp.escape(STDLIB_FILE)}/) { @cli.run([@script_file]) }

out, _err = capture_io do
@cli.run(["--allow-files=longhorn", @script_file])
end
refute_includes out, "set.rb"
refute_includes out, STDLIB_FILE
end

def test_redirects_output_to_specific_file
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_normalize_paths
end

assert_match(%r!\d+\s{2}longhorn-0.1.0/lib/longhorn.rb:\d+!, out)
assert_match(%r!ruby/lib/\S*set.rb!, out)
assert_match(%r!ruby/lib/\S*#{Regexp.escape(STDLIB_FILE)}!, out)
end

def test_pretty
Expand All @@ -91,7 +91,7 @@ def test_pretty

assert_match(/\d kB/, out)
assert_match(%r!\d+\s{2}longhorn-0.1.0/lib/longhorn.rb:\d+!, out)
assert_match(%r!ruby/lib/\S*set.rb!, out)
assert_match(%r!ruby/lib/\S*#{Regexp.escape(STDLIB_FILE)}!, out)
end

def test_prints_help_when_script_not_specified
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

FIXTURE_DIR = File.expand_path('fixtures', __dir__).freeze

# The stdlib .rb file required by the longhorn test fixture gem.
# Used in assertions that check profiler output references a stdlib file.
# If Ruby moves this to C (like it did with set.rb), change the fixture's
# require and update this constant to another pure-Ruby stdlib file.
STDLIB_FILE = "erb.rb".freeze

def require_fixture_gem(name)
lib_path = File.join(FIXTURE_DIR, 'gems', "#{name}-0.1.0", 'lib')
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
Expand Down
2 changes: 1 addition & 1 deletion test/test_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ def test_normalize_paths_true
io = StringIO.new
report.pretty_print(io, normalize_paths: true)
assert_match(%r!\d+\s{2}longhorn-0.1.0/lib/longhorn.rb:\d+!, io.string)
assert_match(%r!ruby/lib/\S*set.rb!, io.string)
assert_match(%r!ruby/lib/\S*#{Regexp.escape(STDLIB_FILE)}!, io.string)
end
end
Loading