summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2020-02-19 23:50:45 -0700
committerGitHub <noreply@github.com>2020-02-19 23:50:45 -0700
commitc480686aa6fb5ccfa42772cd1690d77fdf48756a (patch)
tree5a0e1a18cee103d27bf442133ebdf6dbd1ff6270
parent6cdd1f167a1b24e784377b1ac91865610d15cd0e (diff)
disable bundler in the pure CLI tests (PR #3577)
- switch to array-based arguments to prevent the command from being modified - disable the RUBYOPT environment variable unless the use_bundler option is enabled
-rw-r--r--test/invoker_test.rb14
-rw-r--r--test/test_helper.rb45
2 files changed, 27 insertions, 32 deletions
diff --git a/test/invoker_test.rb b/test/invoker_test.rb
index 3ea36d44..079781e7 100644
--- a/test/invoker_test.rb
+++ b/test/invoker_test.rb
@@ -683,7 +683,7 @@ context 'Invoker' do
# using open3 to work around a bug in JRuby process_manager.rb,
# which tries to run a gsub on stdout prematurely breaking the test
# warnings may be issued, so don't assert on stderr
- stdout_lines = run_command({ 'LANG' => 'US-ASCII' }, %(#{asciidoctor_cmd} -o - --trace #{input_path})) {|out| out.readlines }
+ stdout_lines = run_command(asciidoctor_cmd, '-o', '-', '--trace', input_path, env: { 'LANG' => 'US-ASCII' }) {|out| out.readlines }
refute_empty stdout_lines
# NOTE Ruby on Windows runs with a IBM437 encoding by default
stdout_lines.each {|l| l.force_encoding Encoding::UTF_8 } unless Encoding.default_external == Encoding::UTF_8
@@ -692,7 +692,9 @@ context 'Invoker' do
end
test 'should force stdio encoding to UTF-8' do
- result = run_command(%(#{asciidoctor_cmd true, '-E IBM866:IBM866'} -r #{fixture_path 'configure-stdin.rb'} -s -o - -)) {|out| out.read }
+ 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 }
# NOTE Ruby on Windows runs with a IBM437 encoding by default
result.force_encoding Encoding::UTF_8 unless Encoding.default_external == Encoding::UTF_8
assert_equal Encoding::UTF_8, result.encoding
@@ -701,8 +703,8 @@ context 'Invoker' do
end
test 'should not fail to load if call to Dir.home fails' do
- rubyopt = %(-r #{fixture_path 'undef-dir-home.rb'})
- result = run_command(%(#{asciidoctor_cmd true, rubyopt} -s -o - #{fixture_path 'basic.adoc'})) {|out| out.read }
+ 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
end
@@ -721,7 +723,7 @@ context 'Invoker' do
test 'should show timezone as UTC if system TZ is set to UTC' do
input_path = fixture_path 'doctime-localtime.adoc'
- output = run_command({ 'TZ' => 'UTC', 'SOURCE_DATE_EPOCH' => nil, 'IGNORE_SOURCE_DATE_EPOCH' => '1' }, %(#{asciidoctor_cmd} -d inline -o - -s #{input_path})) {|out| out.read }
+ 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')
@@ -729,7 +731,7 @@ context 'Invoker' do
test 'should show timezone as offset if system TZ is not set to UTC' do
input_path = fixture_path 'doctime-localtime.adoc'
- output = run_command({ 'TZ' => 'EST+5', 'SOURCE_DATE_EPOCH' => nil, 'IGNORE_SOURCE_DATE_EPOCH' => '1' }, %(#{asciidoctor_cmd} -d inline -o - -s #{input_path})) {|out| out.read }
+ 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)
assert doctime.end_with?(' -0500')
assert localtime.end_with?(' -0500')
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 6be252c1..7211c1e6 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -19,7 +19,6 @@ require 'tempfile'
require 'tmpdir'
autoload :FileUtils, 'fileutils'
-autoload :Open3, 'open3'
autoload :Pathname, 'pathname'
RE_XMLNS_ATTRIBUTE = / xmlns="[^"]+"/
@@ -67,17 +66,6 @@ class Minitest::Test
File.join Asciidoctor::ROOT_DIR, 'bin'
end
- def asciidoctor_cmd use_ruby = true, ruby_opts = nil
- executable = File.join bindir, 'asciidoctor'
- if use_ruby
- ruby = File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
- ruby = %(#{ruby} #{ruby_opts}) if ruby_opts
- %(#{ruby} #{executable})
- else
- executable
- end
- end
-
def testdir
ASCIIDOCTOR_TEST_DIR
end
@@ -335,35 +323,40 @@ class Minitest::Test
end
end
- def run_command *args, &block
- if Hash === (env = args[0])
- cmd = args[1]
- else
- cmd, env = env, nil
+ def asciidoctor_cmd ruby_args = nil
+ [Gem.ruby, *ruby_args, (File.join bindir, 'asciidoctor')]
+ end
+
+ def run_command cmd, *args, &block
+ if Array === cmd
+ args.unshift(*cmd)
+ cmd = args.shift
end
+ kw_args = Hash === args[-1] ? args.pop : {}
+ env = kw_args[:env]
+ (env ||= {})['RUBYOPT'] = nil unless kw_args[:use_bundler]
opts = { err: [:child, :out] }
if env
- # NOTE remove workaround once https://github.com/jruby/jruby/issues/3428 is resolved
- if jruby?
+ if jruby? && (Gem::Version.new JRUBY_VERSION) < (Gem::Version.new '9.2.10.0')
begin
old_env, env = ENV, (ENV.merge env)
env.each {|key, val| env.delete key if val.nil? } if env.value? nil
ENV.replace env
- IO.popen cmd, opts, &block
+ IO.popen [cmd, *args, opts], &block
ensure
ENV.replace old_env
end
elsif env.value? nil
- env = env.inject(ENV.to_h) do |acc, (key, val)|
- val.nil? ? (acc.delete key) : (acc[key] = val)
- acc
+ env = env.reduce ENV.to_h do |accum, (key, val)|
+ val.nil? ? (accum.delete key) : (accum[key] = val)
+ accum
end
- IO.popen env, cmd, (opts.merge unsetenv_others: true), &block
+ IO.popen [env, cmd, *args, (opts.merge unsetenv_others: true)], &block
else
- IO.popen env, cmd, opts, &block
+ IO.popen [env, cmd, *args, opts], &block
end
else
- IO.popen cmd, opts, &block
+ IO.popen [cmd, *args, opts], &block
end
end