Skip to content

Commit

Permalink
[ruby/yarp] Name test methods from relative paths
Browse files Browse the repository at this point in the history
Full path name of the source directory is a useless noise as tests.

ruby/prism@44a7ae2e64
  • Loading branch information
nobu committed Jun 24, 2023
1 parent 261e366 commit 97152d4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/yarp/parse_test.rb
Expand Up @@ -61,15 +61,16 @@ def test_parse_takes_file_path
assert_equal filepath, find_source_file_node(parsed_result.value).filepath
end

Dir[File.expand_path("fixtures/**/*.txt", __dir__)].each do |filepath|
relative = filepath.delete_prefix("#{File.expand_path("fixtures", __dir__)}/")
base = File.join(__dir__, "fixtures")
Dir["**/*.txt", base: base].each do |relative|
next if known_failures.include?(relative)

filepath = File.join(base, relative)
snapshot = File.expand_path(File.join("snapshots", relative), __dir__)
directory = File.dirname(snapshot)
FileUtils.mkdir_p(directory) unless File.directory?(directory)

define_method "test_filepath_#{filepath}" do
define_method "test_filepath_#{relative}" do
# First, read the source from the filepath. Use binmode to avoid converting CRLF on Windows,
# and explicitly set the external encoding to UTF-8 to override the binmode default.
source = File.read(filepath, binmode: true, external_encoding: Encoding::UTF_8)
Expand Down

0 comments on commit 97152d4

Please sign in to comment.