From 1575407fbf70e215a9e991dcedcd5847ef9768cb Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 14 Nov 2024 11:20:13 +0100 Subject: [PATCH] Improve encoding test --- src/engines/ruby/2.1/Dockerfile.musl | 2 ++ src/engines/ruby/2.2/Dockerfile.musl | 2 ++ src/engines/ruby/2.3/Dockerfile.musl | 2 ++ src/engines/ruby/2.4/Dockerfile.musl | 2 ++ src/engines/ruby/2.5/Dockerfile.musl | 2 ++ src/engines/ruby/2.6/Dockerfile.musl | 2 ++ src/engines/ruby/2.7/Dockerfile.musl | 2 ++ src/engines/ruby/3.0/Dockerfile.musl | 2 ++ src/engines/ruby/3.1/Dockerfile.musl | 2 ++ src/engines/ruby/3.2/Dockerfile.musl | 2 ++ src/engines/ruby/3.3/Dockerfile.musl | 2 ++ src/engines/ruby/3.4/Dockerfile.musl | 2 ++ tasks/docker.rake | 6 +++++- test/engines/test_encoding.rb | 26 ++++++++++++++++++++------ 14 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/engines/ruby/2.1/Dockerfile.musl b/src/engines/ruby/2.1/Dockerfile.musl index 72a8779..7212121 100644 --- a/src/engines/ruby/2.1/Dockerfile.musl +++ b/src/engines/ruby/2.1/Dockerfile.musl @@ -29,6 +29,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 2.7.11 RUN gem install bundler --version 1.17.3 diff --git a/src/engines/ruby/2.2/Dockerfile.musl b/src/engines/ruby/2.2/Dockerfile.musl index be263cd..1356c52 100644 --- a/src/engines/ruby/2.2/Dockerfile.musl +++ b/src/engines/ruby/2.2/Dockerfile.musl @@ -29,6 +29,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 2.7.11 RUN gem install bundler --version 1.17.3 diff --git a/src/engines/ruby/2.3/Dockerfile.musl b/src/engines/ruby/2.3/Dockerfile.musl index 0aadd04..dd8989c 100644 --- a/src/engines/ruby/2.3/Dockerfile.musl +++ b/src/engines/ruby/2.3/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.3.26 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/2.4/Dockerfile.musl b/src/engines/ruby/2.4/Dockerfile.musl index ee2da59..aac98b8 100644 --- a/src/engines/ruby/2.4/Dockerfile.musl +++ b/src/engines/ruby/2.4/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.3.26 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/2.5/Dockerfile.musl b/src/engines/ruby/2.5/Dockerfile.musl index 8edb08f..7021c7d 100644 --- a/src/engines/ruby/2.5/Dockerfile.musl +++ b/src/engines/ruby/2.5/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.3.26 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/2.6/Dockerfile.musl b/src/engines/ruby/2.6/Dockerfile.musl index f5856bd..98462c3 100644 --- a/src/engines/ruby/2.6/Dockerfile.musl +++ b/src/engines/ruby/2.6/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.3.26 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/2.7/Dockerfile.musl b/src/engines/ruby/2.7/Dockerfile.musl index 7521b59..1822987 100644 --- a/src/engines/ruby/2.7/Dockerfile.musl +++ b/src/engines/ruby/2.7/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.3.26 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/3.0/Dockerfile.musl b/src/engines/ruby/3.0/Dockerfile.musl index 3a87a09..847fcff 100644 --- a/src/engines/ruby/3.0/Dockerfile.musl +++ b/src/engines/ruby/3.0/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.5.21 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/3.1/Dockerfile.musl b/src/engines/ruby/3.1/Dockerfile.musl index 5f248f1..2ff39c7 100644 --- a/src/engines/ruby/3.1/Dockerfile.musl +++ b/src/engines/ruby/3.1/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.5.21 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/3.2/Dockerfile.musl b/src/engines/ruby/3.2/Dockerfile.musl index f370a7b..98f836b 100644 --- a/src/engines/ruby/3.2/Dockerfile.musl +++ b/src/engines/ruby/3.2/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.5.21 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/3.3/Dockerfile.musl b/src/engines/ruby/3.3/Dockerfile.musl index 9fe7520..fce5674 100644 --- a/src/engines/ruby/3.3/Dockerfile.musl +++ b/src/engines/ruby/3.3/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.5.21 RUN gem install bundler:2.3.26 diff --git a/src/engines/ruby/3.4/Dockerfile.musl b/src/engines/ruby/3.4/Dockerfile.musl index 81c4e08..592f869 100644 --- a/src/engines/ruby/3.4/Dockerfile.musl +++ b/src/engines/ruby/3.4/Dockerfile.musl @@ -28,6 +28,8 @@ ARG REPRO_RUN_KEY=0 # updated by changing the `REPRO_RUN_KEY`. RUN true "${REPRO_RUN_KEY}" && apk update +ENV LANG en_US.UTF-8 + ## Install a pinned RubyGems and Bundler RUN gem update --system 3.5.21 RUN gem install bundler:2.3.26 diff --git a/tasks/docker.rake b/tasks/docker.rake index f9fcd8a..9a25ee7 100644 --- a/tasks/docker.rake +++ b/tasks/docker.rake @@ -230,7 +230,11 @@ namespace :docker do tag = target[:tag] platform = docker_platform - exec "docker run --rm -it --platform #{platform} -v #{Dir.pwd}:#{Dir.pwd} -w #{Dir.pwd} #{image}:#{tag} /bin/sh" + version = tag =~ /^(\d+\.\d+)/ && $1 + engine = image =~ /([^\/]+)$/ && $1 + gemfile = "gemfiles/#{engine}-#{version}.gemfile" + + exec "docker run --rm -it --platform #{platform} -v #{Dir.pwd}:#{Dir.pwd} -w #{Dir.pwd} -e BUNDLE_GEMFILE=#{Dir.pwd}/#{gemfile} #{image}:#{tag} /bin/sh" end desc "Run container with irb." diff --git a/test/engines/test_encoding.rb b/test/engines/test_encoding.rb index bbc84e1..92ab0bf 100644 --- a/test/engines/test_encoding.rb +++ b/test/engines/test_encoding.rb @@ -1,13 +1,27 @@ -require 'minitest/autorun' +require "minitest/autorun" + +# polyfill for Ruby 2.2 and down, used by minitest +unless "".respond_to?(:match?) + String.instance_eval do + def match?(other) + (Regexp === other) ? other.match?(self) : (self == other) + end + end +end class TestEncoding < Minitest::Test - def test_utf8 - assert_equal("".encoding, Encoding::UTF_8) + def test_utf8_lang + assert_equal("en_US.UTF-8", ENV["LANG"]) + end + + def test_utf8_string + assert_equal(Encoding::UTF_8, "".encoding) end def test_read_utf8 - contents = File.read('test/fixtures/encoding/utf-8.txt') - assert_equal(contents.encoding, Encoding::UTF_8) - assert_equal(contents, "\u2705\n") + contents = File.read("test/fixtures/encoding/utf-8.txt") + + assert_equal(Encoding::UTF_8, contents.encoding) + assert_equal("\u2705\n", contents) end end