Skip to content

Commit e757fde

Browse files
committed
Set default external encoding for parse tests
1 parent c4e8357 commit e757fde

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

test/parse_test.rb

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
require "yarp_test_helper"
44

55
class ParseTest < Test::Unit::TestCase
6+
# Because we're reading the snapshots from disk, we need to make sure that
7+
# they're encoded as UTF-8. When certain settings are present this might not
8+
# always be the case (e.g., LANG=C or -Eascii-8bit). So here we force the
9+
# default external encoding for the duration of the test.
10+
def setup
11+
@previous_default_external = Encoding.default_external
12+
Encoding.default_external = Encoding::UTF_8
13+
end
14+
15+
def teardown
16+
Encoding.default_external = @previous_default_external
17+
end
18+
619
def test_Ruby_3_2_plus
720
assert_operator RUBY_VERSION, :>=, "3.2.0", "ParseTest requires Ruby 3.2+"
821
end
@@ -48,24 +61,6 @@ def test_parse_takes_file_path
4861
assert_equal filepath, find_source_file_node(parsed_result.value).filepath
4962
end
5063

51-
# We have some files that are failing on other systems because of default
52-
# encoding. We'll fix these ASAP.
53-
FAILING = %w[
54-
seattlerb/bug202.txt
55-
seattlerb/dsym_esc_to_sym.txt
56-
seattlerb/heredoc_bad_oct_escape.txt
57-
seattlerb/magic_encoding_comment.txt
58-
seattlerb/read_escape_unicode_curlies.txt
59-
seattlerb/read_escape_unicode_h4.txt
60-
seattlerb/regexp_escape_extended.txt
61-
seattlerb/regexp_unicode_curlies.txt
62-
seattlerb/str_evstr_escape.txt
63-
seattlerb/str_lit_concat_bad_encodings.txt
64-
symbols.txt
65-
whitequark/bug_ascii_8bit_in_literal.txt
66-
whitequark/dedenting_heredoc.txt
67-
]
68-
6964
Dir[File.expand_path("fixtures/**/*.txt", __dir__)].each do |filepath|
7065
relative = filepath.delete_prefix("#{File.expand_path("fixtures", __dir__)}/")
7166
next if known_failures.include?(relative)
@@ -75,12 +70,6 @@ def test_parse_takes_file_path
7570
FileUtils.mkdir_p(directory) unless File.directory?(directory)
7671

7772
define_method "test_filepath_#{filepath}" do
78-
if (ENV.key?("RUBYCI_NICKNAME") || ENV["RUBY_DEBUG"] =~ /ci/) && FAILING.include?(relative)
79-
# http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20230621T190004Z.fail.html.gz
80-
# http://ci.rvm.jp/results/trunk-yjit@ruby-sp2-docker/4612202
81-
omit "Not working on RubyCI and ci.rvm.jp"
82-
end
83-
8473
# First, read the source from the filepath. Use binmode to avoid converting CRLF on Windows,
8574
# and explicitly set the external encoding to UTF-8 to override the binmode default.
8675
source = File.read(filepath, binmode: true, external_encoding: Encoding::UTF_8)

0 commit comments

Comments
 (0)