summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-04-01 01:41:31 -0600
committerGitHub <noreply@github.com>2019-04-01 01:41:31 -0600
commitd7e2845bd4d7725dcbc74e36c42facbbb90db4e4 (patch)
tree84b4fc1238df718290fd936eb32f8b82776ab0fd
parent5c32e8826a326a3363acb91bdb72ed90d5c4fcbb (diff)
resolves #3226 CLI should use $stdin instead of STDIN (PR #3227)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/cli/invoker.rb2
-rw-r--r--test/invoker_test.rb18
3 files changed, 13 insertions, 8 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 0df52279..840e44c8 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -20,6 +20,7 @@ Bug Fixes::
* fix crash when source highlighter is Rouge and source language is not set on block (#3223)
* make Asciidoctor::SyntaxHighlighter::Config.register_for method public as documented
* update CLI and SyntaxHighlighter to allow Asciidoctor to load cleanly on Ruby 2.0 - 2.2
+ * CLI should use $stdin instead of STDIN to be consistent with the use of $stdout
== 2.0.4 (2019-03-31) - @mojavelinux
diff --git a/lib/asciidoctor/cli/invoker.rb b/lib/asciidoctor/cli/invoker.rb
index 7bbc080b..0bbe1f94 100644
--- a/lib/asciidoctor/cli/invoker.rb
+++ b/lib/asciidoctor/cli/invoker.rb
@@ -97,7 +97,7 @@ module Asciidoctor
if stdin
# allows use of block to supply stdin, particularly useful for tests
- input = block_given? ? yield : STDIN
+ input = block_given? ? yield : $stdin
input_opts = opts.merge to_file: tofile
if show_timings
@documents << (::Asciidoctor.convert input, (input_opts.merge timings: (timings = Timings.new)))
diff --git a/test/invoker_test.rb b/test/invoker_test.rb
index 09320711..9a862108 100644
--- a/test/invoker_test.rb
+++ b/test/invoker_test.rb
@@ -70,15 +70,19 @@ context 'Invoker' do
end
test 'should not fail to rewind input if reading document from stdin' do
- io = STDIN.dup
- class << io
- def read
- 'paragraph'
+ begin
+ $stdin = STDIN.dup
+ class << $stdin
+ def read
+ 'paragraph'
+ end
end
+ invoker = invoke_cli_to_buffer(%w(-s), '-')
+ assert_equal 0, invoker.code
+ assert_equal 1, invoker.document.blocks.size
+ ensure
+ $stdin = STDIN
end
- invoker = invoke_cli_to_buffer(%w(-s), '-') { io }
- assert_equal 0, invoker.code
- assert_equal 1, invoker.document.blocks.size
end
test 'should accept document from stdin and write to output file' do