Skip to content

Commit

Permalink
resolves asciidoctor#3550 run tests on JRuby for Windows in CI
Browse files Browse the repository at this point in the history
* run tests on JRuby 9.1 and 9.2 for Windows in CI
* don't run Pygments tests on JRuby 9.1 for Windows
* exclude tests that use run_command on JRuby 9.1 for Windows
* ensure mtime of input file honors TZ environment variable on JRuby for Windows
  • Loading branch information
mojavelinux committed Apr 15, 2021
1 parent d7bf59f commit 073b853
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
ruby: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
ruby: ['jruby-9.2.17.0', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
asciimath-version: [~]
pygments-version: ['~> 2.0']
rouge-version: [~]
Expand All @@ -33,8 +33,9 @@ jobs:
- os: ubuntu-latest
ruby: jruby-9.1.17.0
pygments-version: ~
- os: ubuntu-latest
ruby: jruby-9.2.17.0
- os: windows-latest
ruby: jruby-9.1.17.0
pygments-version: ~
- os: macos-latest
ruby: '3.0'
- os: ubuntu-latest
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.adoc
Expand Up @@ -15,11 +15,19 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

== Unreleased

Improvments::
Bug Fixes::

* Ensure mtime of input file honors TZ environment variable on JRuby for Windows (affects value of docdatetime attribute) (#3550)

Improvements::

* Increment counter (but not the corresponding attribute) if attribute is locked (#4013)
* Use attribute as seed value for counter even if not already registered as a counter (#4014)

Build / Infrastructure::

* Run tests on JRuby for Windows (#3550)

// tag::compact[]
== 2.0.13 (2021-04-10) - @mojavelinux

Expand Down
3 changes: 2 additions & 1 deletion lib/asciidoctor/load.rb
Expand Up @@ -53,7 +53,8 @@ def load input, options = {}
end

if ::File === input
options[:input_mtime] = input.mtime
# JRuby for Windows does not honor TZ environment value when reading mtime on IO; run it through ::Time.at to fix
options[:input_mtime] = RUBY_ENGINE == 'jruby' ? (::Time.at input.mtime.to_i) : input.mtime
# NOTE defer setting infile and indir until we get a better sense of their purpose
# TODO cli checks if input path can be read and is file, but might want to add check to API too
attrs['docfile'] = input_path = ::File.absolute_path input.path
Expand Down
3 changes: 2 additions & 1 deletion test/api_test.rb
Expand Up @@ -84,7 +84,8 @@
assert_match(/reader\.rb.*prepare_lines/, exception.backtrace[0..4].join(?\n))
end

test 'should convert filename that contains non-ASCII characters independent of default encodings' do
# NOTE JRuby for Windows does not permit creating a file with non-Windows-1252 characters in the filename
test 'should convert filename that contains non-ASCII characters independent of default encodings', unless: (jruby? && windows?) do
old_external = Encoding.default_external
old_internal = Encoding.default_internal
old_verbose = $VERBOSE
Expand Down
10 changes: 5 additions & 5 deletions test/invoker_test.rb
Expand Up @@ -678,7 +678,7 @@
assert_equal 'erubi', doc.instance_variable_get('@options')[:eruby]
end

test 'should force default external encoding to UTF-8' do
test 'should force default external encoding to UTF-8', unless: jruby_9_1_windows? do
input_path = fixture_path 'encoding.adoc'
# using open3 to work around a bug in JRuby process_manager.rb,
# which tries to run a gsub on stdout prematurely breaking the test
Expand All @@ -691,7 +691,7 @@
assert_includes stdout_str, 'Codierungen sind verrückt auf älteren Versionen von Ruby'
end

test 'should force stdio encoding to UTF-8' do
test 'should force stdio encoding to UTF-8', unless: jruby_9_1_windows? do
cmd = asciidoctor_cmd ['-E', 'IBM866:IBM866']
# NOTE configure-stdin.rb populates stdin
result = run_command(cmd, '-r', (fixture_path 'configure-stdin.rb'), '-s', '-o', '-', '-') {|out| out.read }
Expand All @@ -702,7 +702,7 @@
assert_include '<p>IBM866:IBM866</p>', result
end

test 'should not fail to load if call to Dir.home fails' do
test 'should not fail to load if call to Dir.home fails', unless: jruby_9_1_windows? do
cmd = asciidoctor_cmd ['-r', (fixture_path 'undef-dir-home.rb')]
result = run_command(cmd, '-s', '-o', '-', (fixture_path 'basic.adoc')) {|out| out.read }
assert_include 'Body content', result
Expand All @@ -721,15 +721,15 @@
assert_match(/Total time/, error)
end

test 'should show timezone as UTC if system TZ is set to UTC' do
test 'should show timezone as UTC if system TZ is set to UTC', unless: jruby_9_1_windows? do
input_path = fixture_path 'doctime-localtime.adoc'
output = run_command(asciidoctor_cmd, '-d', 'inline', '-o', '-', '-s', input_path, env: { 'TZ' => 'UTC', 'SOURCE_DATE_EPOCH' => nil, 'IGNORE_SOURCE_DATE_EPOCH' => '1' }) {|out| out.read }
doctime, localtime = output.lines.map(&:chomp)
assert doctime.end_with?(' UTC')
assert localtime.end_with?(' UTC')
end

test 'should show timezone as offset if system TZ is not set to UTC' do
test 'should show timezone as offset if system TZ is not set to UTC', unless: jruby_9_1_windows? do
input_path = fixture_path 'doctime-localtime.adoc'
output = run_command(asciidoctor_cmd, '-d', 'inline', '-o', '-', '-s', input_path, env: { 'TZ' => 'EST+5', 'SOURCE_DATE_EPOCH' => nil, 'IGNORE_SOURCE_DATE_EPOCH' => '1' }) {|out| out.read }
doctime, localtime = output.lines.map(&:chomp)
Expand Down
2 changes: 1 addition & 1 deletion test/syntax_highlighter_test.rb
Expand Up @@ -1095,7 +1095,7 @@ def highlight?
assert_includes css, 'background-color: #49483e;'
end

test 'should not fail to load rouge if the Asciidoctor module is included into the global namespace' do
test 'should not fail to load rouge if the Asciidoctor module is included into the global namespace', unless: jruby_9_1_windows? do
result = run_command(asciidoctor_cmd, '-r', (fixture_path 'include-asciidoctor.rb'), '-s', '-o', '-', '-a', 'source-highlighter=rouge', (fixture_path 'source-block.adoc'), use_bundler: true) {|out| out.read }
assert_xpath '//pre[@class="rouge highlight"]', result, 1
end
Expand Down
27 changes: 23 additions & 4 deletions test/test_helper.rb
Expand Up @@ -34,6 +34,10 @@ def jruby?
RUBY_ENGINE == 'jruby'
end

def self.jruby_9_1_windows?
RUBY_ENGINE == 'jruby' && windows? && (JRUBY_VERSION.start_with? '9.1.')
end

def self.windows?
/mswin|msys|mingw/.match? RbConfig::CONFIG['host_os']
end
Expand Down Expand Up @@ -331,6 +335,8 @@ def asciidoctor_cmd ruby_args = nil
[Gem.ruby, *ruby_args, (File.join bindir, 'asciidoctor')]
end

# NOTE run_command fails on JRuby 9.1 for Windows with the following error:
# Java::JavaLang::ClassCastException at org.jruby.util.ShellLauncher.getModifiedEnv(ShellLauncher.java:271)
def run_command cmd, *args, &block
if Array === cmd
args.unshift(*cmd)
Expand All @@ -348,7 +354,7 @@ def run_command cmd, *args, &block
old_env, env = ENV.merge, (ENV.merge env)
env.each {|key, val| env.delete key if val.nil? } if env.value? nil
ENV.replace env
IO.popen [cmd, *args, opts], &block
popen [cmd, *args, opts], &block
ensure
ENV.replace old_env
end
Expand All @@ -357,12 +363,25 @@ def run_command cmd, *args, &block
val.nil? ? (accum.delete key) : (accum[key] = val)
accum
end
IO.popen [env, cmd, *args, (opts.merge unsetenv_others: true)], &block
popen [env, cmd, *args, (opts.merge unsetenv_others: true)], &block
else
IO.popen [env, cmd, *args, opts], &block
popen [env, cmd, *args, opts], &block
end
else
popen [cmd, *args, opts], &block
end
end

def popen args, &block
# When block is passed to IO.popen, JRuby for Windows does not return value of block as return value
if jruby? && windows?
result = nil
IO.popen args do |io|
result = yield io
end
result
else
IO.popen [cmd, *args, opts], &block
IO.popen args, &block
end
end

Expand Down

0 comments on commit 073b853

Please sign in to comment.