Skip to content

Commit da9107d

Browse files
authored
Merge pull request #125 from rwstauner/stdlib-4
Fix tests for ruby 4+ by replacing set.rb with erb.rb in tests after Set moved to C
2 parents d1c0395 + 592f194 commit da9107d

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Ruby ${{ matrix.ruby }}
1111
strategy:
1212
matrix:
13-
ruby: ["3.1", "3.2", "3.3"]
13+
ruby: ["3.1", "3.2", "3.3", "3.4", "4.0"]
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: ruby/setup-ruby@v1

test/fixtures/gems/longhorn-0.1.0/lib/longhorn.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3-
require 'set'
3+
require 'erb'
44

55
module Longhorn
66
def self.run
7-
result = Set.new
7+
result = []
88
["allocated", "retained"]
99
.product(["memory", "objects"])
1010
.product(["gem", "file", "location", "class"])
1111
.each do |(type, metric), name|
12-
result << "#{type} #{metric} by #{name}"
12+
result << ERB.new("<%= type %> <%= metric %> by <%= name %>").result(binding)
1313
end
1414
result
1515
end

test/test_cli.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ def test_ignore_specific_files
2121
out, _err = capture_io do
2222
@cli.run([@script_file])
2323
end
24-
assert_includes out, "set.rb"
24+
assert_includes out, STDLIB_FILE
2525

2626
out, _err = capture_io do
27-
@cli.run(["--ignore-files=set.rb", @script_file])
27+
@cli.run(["--ignore-files=#{STDLIB_FILE}", @script_file])
2828
end
29-
refute_includes out, "set.rb"
29+
refute_includes out, STDLIB_FILE
3030
end
3131

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

3535
out, _err = capture_io do
3636
@cli.run(["--allow-files=longhorn", @script_file])
3737
end
38-
refute_includes out, "set.rb"
38+
refute_includes out, STDLIB_FILE
3939
end
4040

4141
def test_redirects_output_to_specific_file
@@ -81,7 +81,7 @@ def test_normalize_paths
8181
end
8282

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

8787
def test_pretty
@@ -91,7 +91,7 @@ def test_pretty
9191

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

9797
def test_prints_help_when_script_not_specified

test/test_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

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

10+
# The stdlib .rb file required by the longhorn test fixture gem.
11+
# Used in assertions that check profiler output references a stdlib file.
12+
# If Ruby moves this to C (like it did with set.rb), change the fixture's
13+
# require and update this constant to another pure-Ruby stdlib file.
14+
STDLIB_FILE = "erb.rb".freeze
15+
1016
def require_fixture_gem(name)
1117
lib_path = File.join(FIXTURE_DIR, 'gems', "#{name}-0.1.0", 'lib')
1218
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)

test/test_results.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ def test_normalize_paths_true
8080
io = StringIO.new
8181
report.pretty_print(io, normalize_paths: true)
8282
assert_match(%r!\d+\s{2}longhorn-0.1.0/lib/longhorn.rb:\d+!, io.string)
83-
assert_match(%r!ruby/lib/\S*set.rb!, io.string)
83+
assert_match(%r!ruby/lib/\S*#{Regexp.escape(STDLIB_FILE)}!, io.string)
8484
end
8585
end

0 commit comments

Comments
 (0)