diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index ef82ce8c6d..8e87e496ac 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -167,7 +167,7 @@ def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compa ignore_warnings { Prism::Translation::Parser33.new.tokenize(buffer) } if expected_ast == actual_ast - if !compare_asts + if !compare_asts && !Fixture.custom_base_path? puts "#{fixture.path} is now passing" end @@ -178,7 +178,7 @@ def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compa rescue Test::Unit::AssertionFailedError raise if compare_tokens else - puts "#{fixture.path} is now passing" if !compare_tokens + puts "#{fixture.path} is now passing" if !compare_tokens && !Fixture.custom_base_path? end assert_equal_comments(expected_comments, actual_comments) if compare_comments diff --git a/test/prism/snapshots_test.rb b/test/prism/snapshots_test.rb index 0744eafad3..3fbda1f86e 100644 --- a/test/prism/snapshots_test.rb +++ b/test/prism/snapshots_test.rb @@ -2,6 +2,10 @@ require_relative "test_helper" +# We don't want to generate snapshots when running +# against files outside of the project folder. +return if Prism::TestCase::Fixture.custom_base_path? + module Prism class SnapshotsTest < TestCase # When we pretty-print the trees to compare against the snapshots, we want diff --git a/test/prism/test_helper.rb b/test/prism/test_helper.rb index b848500283..c5afdc0ea5 100644 --- a/test/prism/test_helper.rb +++ b/test/prism/test_helper.rb @@ -38,7 +38,7 @@ class TestCase < ::Test::Unit::TestCase # are used to define test methods that assert against each fixture in some # way. class Fixture - BASE = File.join(__dir__, "fixtures") + BASE = ENV.fetch("FIXTURE_BASE", File.join(__dir__, "fixtures")) attr_reader :path @@ -63,9 +63,14 @@ def test_name end def self.each(except: [], &block) - paths = Dir[ENV.fetch("FOCUS") { File.join("**", "*.txt") }, base: BASE] - except + glob_pattern = ENV.fetch("FOCUS") { custom_base_path? ? File.join("**", "*.rb") : File.join("**", "*.txt") } + paths = Dir[glob_pattern, base: BASE] - except paths.each { |path| yield Fixture.new(path) } end + + def self.custom_base_path? + ENV.key?("FIXTURE_BASE") + end end # Yield each encoding that we want to test, along with a range of the