Skip to content

Commit 8a46052

Browse files
committed
Allow to test a custom fixtures path during testing
Of course, these won't really be fixtures, but it allows to test against whole codebases without copying them, doing symlinks or something like that. For example, I can tell that over the whole RuboCop codebase, there are only 8 files that produce mismatched ast. Telling what the problem is is a different problem. The ast for real files can and will be huge so I haven't checked yet (maybe parser bug) but it's nice for discoverability regardless
1 parent de7bb68 commit 8a46052

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

test/prism/ruby/parser_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compa
167167
ignore_warnings { Prism::Translation::Parser33.new.tokenize(buffer) }
168168

169169
if expected_ast == actual_ast
170-
if !compare_asts
170+
if !compare_asts && !Fixture.custom_base_path?
171171
puts "#{fixture.path} is now passing"
172172
end
173173

@@ -178,7 +178,7 @@ def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compa
178178
rescue Test::Unit::AssertionFailedError
179179
raise if compare_tokens
180180
else
181-
puts "#{fixture.path} is now passing" if !compare_tokens
181+
puts "#{fixture.path} is now passing" if !compare_tokens && !Fixture.custom_base_path?
182182
end
183183

184184
assert_equal_comments(expected_comments, actual_comments) if compare_comments

test/prism/snapshots_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def assert_snapshot(fixture)
6060
# If the snapshot file exists, then assert that the printed value
6161
# matches the snapshot.
6262
assert_equal(saved, printed)
63-
else
63+
elsif !Fixture.custom_base_path?
6464
# If the snapshot file does not yet exist, then write it out now.
6565
directory = File.dirname(snapshot)
6666
FileUtils.mkdir_p(directory) unless File.directory?(directory)

test/prism/test_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TestCase < ::Test::Unit::TestCase
3838
# are used to define test methods that assert against each fixture in some
3939
# way.
4040
class Fixture
41-
BASE = File.join(__dir__, "fixtures")
41+
BASE = ENV.fetch("FIXTURE_BASE", File.join(__dir__, "fixtures"))
4242

4343
attr_reader :path
4444

@@ -63,9 +63,14 @@ def test_name
6363
end
6464

6565
def self.each(except: [], &block)
66-
paths = Dir[ENV.fetch("FOCUS") { File.join("**", "*.txt") }, base: BASE] - except
66+
glob_pattern = ENV.fetch("FOCUS") { custom_base_path? ? File.join("**", "*.rb") : File.join("**", "*.txt") }
67+
paths = Dir[glob_pattern, base: BASE] - except
6768
paths.each { |path| yield Fixture.new(path) }
6869
end
70+
71+
def self.custom_base_path?
72+
ENV.key?("FIXTURE_BASE")
73+
end
6974
end
7075

7176
# Yield each encoding that we want to test, along with a range of the

0 commit comments

Comments
 (0)