diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2014-02-28 19:54:08 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2014-02-28 19:54:08 -0700 |
| commit | fd788825995c2d984ff22dc28b6876f8d9c0b8f1 (patch) | |
| tree | 71dabb9704828852422c424fa7942d7075f9d34b /test | |
| parent | f87bc738c4bd03c5049194449cacd854ed729430 (diff) | |
use implicit method rescue block in cli; cleanup interrupt handling
- use implicit rescue block for method in cli classes
- exit cleanly when process receives interrupt
- minor cleanups
Diffstat (limited to 'test')
| -rw-r--r-- | test/invoker_test.rb | 36 | ||||
| -rw-r--r-- | test/sections_test.rb | 17 |
2 files changed, 27 insertions, 26 deletions
diff --git a/test/invoker_test.rb b/test/invoker_test.rb index 78e354f7..efbb943c 100644 --- a/test/invoker_test.rb +++ b/test/invoker_test.rb @@ -10,9 +10,9 @@ context 'Invoker' do test 'should parse source and render as html5 article by default' do invoker = nil output = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoker = invoke_cli %w(-o -) - output = stdout.string + output = out.string end assert !invoker.nil? doc = invoker.document @@ -103,9 +103,9 @@ context 'Invoker' do test 'should display version and exit' do expected = %(Asciidoctor #{Asciidoctor::VERSION} [http://asciidoctor.org]\nRuntime Environment (#{RUBY_DESCRIPTION})) actual = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoke_cli %w(--version) - actual = stdout.string.rstrip + actual = out.string.rstrip end assert_equal expected, actual end @@ -116,9 +116,9 @@ context 'Invoker' do 3. third EOS warnings = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoke_cli_to_buffer(%w(-o /dev/null), '-') { input } - warnings = stderr.string + warnings = err.string end assert_match(/WARNING/, warnings) end @@ -129,32 +129,32 @@ context 'Invoker' do 3. third EOS warnings = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoke_cli_to_buffer(%w(-q -o /dev/null), '-') { input } - warnings = stderr.string + warnings = err.string end assert_equal '', warnings end test 'should report usage if no input file given' do - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoke_cli [], nil - assert_match(/Usage:/, stderr.string) + assert_match(/Usage:/, err.string) end end test 'should report error if input file does not exist' do - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoker = invoke_cli [], 'missing_file.asciidoc' - assert_match(/input file .* missing/, stderr.string) + assert_match(/input file .* missing/, err.string) assert_equal 1, invoker.code end end test 'should treat extra arguments as files' do - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoker = invoke_cli %w(-o /dev/null extra arguments sample.asciidoc), nil - assert_match(/input file .* missing/, stderr.string) + assert_match(/input file .* missing/, err.string) assert_equal 1, invoker.code end end @@ -323,9 +323,9 @@ context 'Invoker' do test 'should output a trailing endline to stdout' do invoker = nil output = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| invoker = invoke_cli %w(-o -) - output = stdout.string + output = out.string end assert !invoker.nil? assert !output.nil? @@ -478,11 +478,11 @@ context 'Invoker' do require 'open3' #cmd = "#{executable} -o - --trace #{input_path}" cmd = "#{File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']} #{executable} -o - --trace #{input_path}" - _, stdout, _ = Open3.popen3 cmd + _, out, _ = Open3.popen3 cmd #stderr_lines = stderr.readlines # warnings may be issued, so don't assert on stderr #assert stderr_lines.empty?, 'Command failed. Expected to receive a rendered document.' - stdout_lines = stdout.readlines + stdout_lines = out.readlines assert !stdout_lines.empty? stdout_lines.each {|l| l.force_encoding Encoding::UTF_8 } if Asciidoctor::FORCE_ENCODING stdout_str = stdout_lines.join diff --git a/test/sections_test.rb b/test/sections_test.rb index 2975c20f..e8704556 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -546,9 +546,9 @@ text in standalone EOS output, errors = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| output = render_string input - errors = stderr.string + errors = err.string end assert !errors.empty? @@ -584,9 +584,9 @@ Master section text. output = nil errors = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| output = render_string input - errors = stdout.string + errors = out.string end assert errors.empty? @@ -2238,12 +2238,13 @@ intro doc = nil warnings = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| doc = document_from_string input - warnings = stderr.string + warnings = err.string end assert_not_nil warnings + assert !warnings.empty? assert_match(/ERROR:.*section/, warnings) end @@ -2323,9 +2324,9 @@ Appendix subsection content output = nil errors = nil - redirect_streams do |stdout, stderr| + redirect_streams do |out, err| output = render_string input, :backend => 'docbook' - errors = stdout.string + errors = out.string end assert errors.empty? assert_xpath '/book/preface', output, 1 |
