Skip to content

Commit 28dc4ff

Browse files
authored
Merge pull request #3417 from Earlopain/tests-custom-fixtures
Allow to test a custom fixtures path during testing
2 parents a122353 + 2184d82 commit 28dc4ff

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

test/prism/ruby/parser_test.rb

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

166166
if expected_ast == actual_ast
167-
if !compare_asts
167+
if !compare_asts && !Fixture.custom_base_path?
168168
puts "#{fixture.path} is now passing"
169169
end
170170

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

181181
assert_equal_comments(expected_comments, actual_comments) if compare_comments

test/prism/snapshots_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
require_relative "test_helper"
44

5+
# We don't want to generate snapshots when running
6+
# against files outside of the project folder.
7+
return if Prism::TestCase::Fixture.custom_base_path?
8+
59
module Prism
610
class SnapshotsTest < TestCase
711
# When we pretty-print the trees to compare against the snapshots, we want

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)