summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-08-13 16:31:06 -0600
committerDan Allen <dan.j.allen@gmail.com>2013-08-13 16:31:06 -0600
commit892fb9ef345069554e676c173c404ee2edceffbf (patch)
treefe92473eccbac0e2ffd64284179455d0a92a8e4c
parent2d82b3f6d8d447f81e940d0fa627e5e516a75c11 (diff)
resolves #556 print warning/error messages using warn
-rw-r--r--lib/asciidoctor/abstract_node.rb4
-rw-r--r--lib/asciidoctor/backends/docbook45.rb4
-rw-r--r--lib/asciidoctor/backends/html5.rb4
-rw-r--r--lib/asciidoctor/cli/invoker.rb9
-rw-r--r--lib/asciidoctor/debug.rb2
-rw-r--r--lib/asciidoctor/document.rb2
-rw-r--r--lib/asciidoctor/helpers.rb6
-rw-r--r--lib/asciidoctor/lexer.rb32
-rw-r--r--lib/asciidoctor/path_resolver.rb2
-rw-r--r--lib/asciidoctor/reader.rb12
-rw-r--r--lib/asciidoctor/substituters.rb6
-rw-r--r--lib/asciidoctor/table.rb2
-rw-r--r--test/blocks_test.rb2
-rw-r--r--test/sections_test.rb2
14 files changed, 44 insertions, 45 deletions
diff --git a/lib/asciidoctor/abstract_node.rb b/lib/asciidoctor/abstract_node.rb
index 66e0ce23..a025b350 100644
--- a/lib/asciidoctor/abstract_node.rb
+++ b/lib/asciidoctor/abstract_node.rb
@@ -319,7 +319,7 @@ class AbstractNode
end
if !File.readable? image_path
- puts "asciidoctor: WARNING: image to embed not found or not readable: #{image_path}"
+ warn "asciidoctor: WARNING: image to embed not found or not readable: #{image_path}"
return "data:#{mimetype}:base64,"
#return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
end
@@ -347,7 +347,7 @@ class AbstractNode
if File.readable? path
File.read(path).chomp
else
- puts "asciidoctor: WARNING: file does not exist or cannot be read: #{path}" if warn_on_failure
+ warn "asciidoctor: WARNING: file does not exist or cannot be read: #{path}" if warn_on_failure
nil
end
end
diff --git a/lib/asciidoctor/backends/docbook45.rb b/lib/asciidoctor/backends/docbook45.rb
index 931aec8e..59c23489 100644
--- a/lib/asciidoctor/backends/docbook45.rb
+++ b/lib/asciidoctor/backends/docbook45.rb
@@ -383,7 +383,7 @@ class BlockOpenTemplate < BaseTemplate
case style
when 'abstract'
if node.parent == node.document && node.document.attr?('doctype', 'book')
- puts 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
+ warn 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
''
else
%(<abstract>#{title && "\n<title>#{title}</title>"}
@@ -392,7 +392,7 @@ class BlockOpenTemplate < BaseTemplate
end
when 'partintro'
unless node.document.attr?('doctype', 'book') && node.parent.is_a?(Asciidoctor::Section) && node.level == 0
- puts 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a part section. Excluding block content.'
+ warn 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a part section. Excluding block content.'
''
else
%(<partintro#{common_attrs id, role, reftext}>#{title && "\n<title>#{title}</title>"}
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index 2117b4d4..679a1192 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -572,7 +572,7 @@ class BlockOpenTemplate < BaseTemplate
def open_block(node, id, style, role, title, content)
if style == 'abstract'
if node.parent == node.document && node.document.attr?('doctype', 'book')
- puts 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
+ warn 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
''
else
%(<div#{id && " id=\"#{id}\""} class="quoteblock abstract#{role && " #{role}"}">#{title &&
@@ -583,7 +583,7 @@ class BlockOpenTemplate < BaseTemplate
</div>)
end
elsif style == 'partintro' && (node.level != 0 || node.parent.context != :section || !node.document.attr?('doctype', 'book'))
- puts 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a book part. Excluding block content.'
+ warn 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a book part. Excluding block content.'
''
else
%(<div#{id && " id=\"#{id}\""} class="openblock#{style != 'open' ? " #{style}" : ''}#{role && " #{role}"}">#{title &&
diff --git a/lib/asciidoctor/cli/invoker.rb b/lib/asciidoctor/cli/invoker.rb
index f49f5d96..4f874181 100644
--- a/lib/asciidoctor/cli/invoker.rb
+++ b/lib/asciidoctor/cli/invoker.rb
@@ -85,10 +85,11 @@ module Asciidoctor
if profile
monitor = opts[:monitor]
- puts "Input file: #{input.respond_to?(:path) ? input.path : '-'}"
- puts " Time to read and parse source: #{'%05.5f' % monitor[:parse]}"
- puts " Time to render document: #{'%05.5f' % monitor[:render]}"
- puts " Total time to read, parse and render: #{'%05.5f' % monitor[:load_render]}"
+ err = (@err || $stderr)
+ err.puts "Input file: #{input.respond_to?(:path) ? input.path : '-'}"
+ err.puts " Time to read and parse source: #{'%05.5f' % monitor[:parse]}"
+ err.puts " Time to render document: #{'%05.5f' % monitor[:render]}"
+ err.puts " Total time to read, parse and render: #{'%05.5f' % monitor[:load_render]}"
end
end
rescue Exception => e
diff --git a/lib/asciidoctor/debug.rb b/lib/asciidoctor/debug.rb
index 9c5fd774..8d82dd87 100644
--- a/lib/asciidoctor/debug.rb
+++ b/lib/asciidoctor/debug.rb
@@ -3,7 +3,7 @@ module Debug
@show_debug = nil
def self.debug
- puts yield if self.show_debug_output?
+ warn yield if self.show_debug_output?
end
def self.set_debug(value)
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index 2ed79b79..b99939dc 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -212,7 +212,7 @@ class Document < AbstractBlock
if @attribute_overrides['docdir']
@base_dir = @attribute_overrides['docdir'] = File.expand_path(@attribute_overrides['docdir'])
else
- #puts 'asciidoctor: WARNING: setting base_dir is recommended when working with string documents' unless nested?
+ #warn 'asciidoctor: WARNING: setting base_dir is recommended when working with string documents' unless nested?
@base_dir = @attribute_overrides['docdir'] = File.expand_path(Dir.pwd)
end
else
diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb
index b7f843bc..65d42403 100644
--- a/lib/asciidoctor/helpers.rb
+++ b/lib/asciidoctor/helpers.rb
@@ -22,12 +22,10 @@ module Helpers
require name
rescue LoadError => e
if gem_name
- puts "asciidoctor: FAILED: required gem '#{gem_name === true ? name : gem_name}' is not installed"
+ fail "asciidoctor: FAILED: required gem '#{gem_name === true ? name : gem_name}' is not installed. Processing aborted."
else
- puts "asciidoctor: FAILED: #{e}"
+ fail "asciidoctor: FAILED: #{e.chomp '.'}. Processing aborted."
end
- # QUESTION: raise abort error or use exit code return value?
- raise 'Processing aborted'
end
end
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index 2d1a5121..9505a37f 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -138,7 +138,7 @@ class Lexer
document.attributes['mantitle'] = document.sub_attributes(m[1].rstrip.downcase)
document.attributes['manvolnum'] = m[2].strip
else
- puts "asciidoctor: ERROR: line #{reader.lineno}: malformed manpage title"
+ warn "asciidoctor: ERROR: line #{reader.lineno}: malformed manpage title"
end
reader.skip_blank_lines
@@ -157,13 +157,13 @@ class Lexer
document.attributes['outfilesuffix'] = ".#{document.attributes['manvolnum']}"
end
else
- puts "asciidoctor: ERROR: line #{reader.lineno}: malformed name section body"
+ warn "asciidoctor: ERROR: line #{reader.lineno}: malformed name section body"
end
else
- puts "asciidoctor: ERROR: line #{reader.lineno}: name section title must be at level 1"
+ warn "asciidoctor: ERROR: line #{reader.lineno}: name section title must be at level 1"
end
else
- puts "asciidoctor: ERROR: line #{reader.lineno}: name section expected"
+ warn "asciidoctor: ERROR: line #{reader.lineno}: name section expected"
end
end
@@ -265,9 +265,9 @@ class Lexer
doctype = parent.document.doctype
if next_level > current_level || (section.is_a?(Document) && next_level == 0)
if next_level == 0 && doctype != 'book'
- puts "asciidoctor: ERROR: line #{reader.lineno + 1}: only book doctypes can contain level 0 sections"
+ warn "asciidoctor: ERROR: line #{reader.lineno + 1}: only book doctypes can contain level 0 sections"
elsif !expected_next_levels.nil? && !expected_next_levels.include?(next_level)
- puts "asciidoctor: WARNING: line #{reader.lineno + 1}: section title out of sequence: " +
+ warn "asciidoctor: WARNING: line #{reader.lineno + 1}: section title out of sequence: " +
"expected #{expected_next_levels.size > 1 ? 'levels' : 'level'} #{expected_next_levels * ' or '}, " +
"got level #{next_level}"
end
@@ -276,7 +276,7 @@ class Lexer
section << new_section
else
if next_level == 0 && doctype != 'book'
- puts "asciidoctor: ERROR: line #{reader.lineno + 1}: only book doctypes can contain level 0 sections"
+ warn "asciidoctor: ERROR: line #{reader.lineno + 1}: only book doctypes can contain level 0 sections"
end
# close this section (and break out of the nesting) to begin a new one
break
@@ -383,7 +383,7 @@ class Lexer
elsif delimited_blk_match.masq.include?('admonition') && ADMONITION_STYLES.include?(style)
block_context = :admonition
else
- puts "asciidoctor: WARNING: line #{reader.lineno}: invalid style for #{block_context} block: #{style}"
+ warn "asciidoctor: WARNING: line #{reader.lineno}: invalid style for #{block_context} block: #{style}"
style = block_context.to_s
end
end
@@ -469,7 +469,7 @@ class Lexer
begin
# might want to move this check to a validate method
if match[1].to_i != expected_index
- puts "asciidoctor: WARNING: line #{reader.lineno + 1}: callout list item index: expected #{expected_index} got #{match[1]}"
+ warn "asciidoctor: WARNING: line #{reader.lineno + 1}: callout list item index: expected #{expected_index} got #{match[1]}"
end
list_item = next_list_item(reader, block, match)
expected_index += 1
@@ -479,7 +479,7 @@ class Lexer
if !coids.empty?
list_item.attributes['coids'] = coids
else
- puts "asciidoctor: WARNING: line #{reader.lineno}: no callouts refer to list item #{block.items.size}"
+ warn "asciidoctor: WARNING: line #{reader.lineno}: no callouts refer to list item #{block.items.size}"
end
end
end while reader.has_more_lines? && match = reader.peek_line.match(REGEXP[:colist])
@@ -545,7 +545,7 @@ class Lexer
# advance to block parsing =>
break
else
- puts "asciidoctor: WARNING: line #{reader.lineno}: invalid style for paragraph: #{style}"
+ warn "asciidoctor: WARNING: line #{reader.lineno}: invalid style for paragraph: #{style}"
style = nil
# continue to process paragraph
end
@@ -1271,8 +1271,8 @@ class Lexer
buffer.pop
end
- #puts "BUFFER[#{list_type},#{sibling_trait}]>#{buffer.join}<BUFFER"
- #puts "BUFFER[#{list_type},#{sibling_trait}]>#{buffer.inspect}<BUFFER"
+ #warn "BUFFER[#{list_type},#{sibling_trait}]>#{buffer.join}<BUFFER"
+ #warn "BUFFER[#{list_type},#{sibling_trait}]>#{buffer.inspect}<BUFFER"
buffer
end
@@ -1911,7 +1911,7 @@ class Lexer
if validate && expected != actual
# FIXME I need a reader reference or line number to report line number
- puts "asciidoctor: WARNING: list item index: expected #{expected}, got #{actual}"
+ warn "asciidoctor: WARNING: list item index: expected #{expected}, got #{actual}"
end
marker
@@ -2203,7 +2203,7 @@ class Lexer
save_current = lambda {
if collector.empty?
if type != :style
- puts "asciidoctor: WARNING:#{reader.nil? ? nil : " line #{reader.lineno}:"} invalid empty #{type} detected in style attribute"
+ warn "asciidoctor: WARNING:#{reader.nil? ? nil : " line #{reader.lineno}:"} invalid empty #{type} detected in style attribute"
end
else
case type
@@ -2212,7 +2212,7 @@ class Lexer
parsed[type].push collector.join
when :id
if parsed.has_key? :id
- puts "asciidoctor: WARNING:#{reader.nil? ? nil : " line #{reader.lineno}:"} multiple ids detected in style attribute"
+ warn "asciidoctor: WARNING:#{reader.nil? ? nil : " line #{reader.lineno}:"} multiple ids detected in style attribute"
end
parsed[type] = collector.join
else
diff --git a/lib/asciidoctor/path_resolver.rb b/lib/asciidoctor/path_resolver.rb
index 7a4e14b8..763e2cc3 100644
--- a/lib/asciidoctor/path_resolver.rb
+++ b/lib/asciidoctor/path_resolver.rb
@@ -312,7 +312,7 @@ class PathResolver
elsif !recover
raise SecurityError, "#{opts[:target_name] || 'path'} #{target} refers to location outside jail: #{jail} (disallowed in safe mode)"
elsif !warned
- puts "asciidoctor: WARNING: #{opts[:target_name] || 'path'} has illegal reference to ancestor of jail, auto-recovering"
+ warn "asciidoctor: WARNING: #{opts[:target_name] || 'path'} has illegal reference to ancestor of jail, auto-recovering"
warned = true
end
else
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 612abaf7..9da76128 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -392,10 +392,10 @@ class Reader
@conditionals_stack.pop
@skipping = @conditionals_stack.empty? ? false : @conditionals_stack.last[:skipping]
else
- puts "asciidoctor: ERROR: line #{@lineno + 1}: mismatched macro: endif::#{target}[], expected endif::#{pair[:target]}[]"
+ warn "asciidoctor: ERROR: line #{@lineno + 1}: mismatched macro: endif::#{target}[], expected endif::#{pair[:target]}[]"
end
else
- puts "asciidoctor: ERROR: line #{@lineno + 1}: unmatched macro: endif::#{target}[]"
+ warn "asciidoctor: ERROR: line #{@lineno + 1}: unmatched macro: endif::#{target}[]"
end
advance
return preprocess_next_line.nil? ? nil : true
@@ -525,7 +525,7 @@ class Reader
target_type = :file
include_file = @document.normalize_system_path(target, nil, nil, :target_name => 'include file')
if !File.file?(include_file)
- puts "asciidoctor: WARNING: line #{@lineno}: include file not found: #{include_file}"
+ warn "asciidoctor: WARNING: line #{@lineno}: include file not found: #{include_file}"
return true
end
end
@@ -574,7 +574,7 @@ class Reader
end
end
rescue
- puts "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
+ warn "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
return true
end
@lines.unshift(*normalize_include_data(selected, attributes['indent'])) unless selected.empty?
@@ -604,7 +604,7 @@ class Reader
end
end
rescue
- puts "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
+ warn "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
return true
end
#@lines.unshift(*selected) unless selected.empty?
@@ -614,7 +614,7 @@ class Reader
begin
@lines.unshift(*normalize_include_data(open(include_file) {|f| f.readlines }, attributes['indent']))
rescue
- puts "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
+ warn "asciidoctor: WARNING: line #{@lineno}: include #{target_type} not readable: #{include_file}"
return true
end
end
diff --git a/lib/asciidoctor/substituters.rb b/lib/asciidoctor/substituters.rb
index a2b16377..295625af 100644
--- a/lib/asciidoctor/substituters.rb
+++ b/lib/asciidoctor/substituters.rb
@@ -61,7 +61,7 @@ module Substituters
when :post_replacements
text = sub_post_replacements(text)
else
- puts "asciidoctor: WARNING: unknown substitution type #{type}"
+ warn "asciidoctor: WARNING: unknown substitution type #{type}"
end
}
text = restore_passthroughs(text) if has_passthroughs
@@ -321,7 +321,7 @@ module Substituters
directive == 'counter2' ? '' : val
else
# if we get here, our attr_ref regex is too loose
- puts "asciidoctor: WARNING: illegal attribute directive: #{m[2]}"
+ warn "asciidoctor: WARNING: illegal attribute directive: #{m[2]}"
''
end
elsif (key = m[2].downcase) && @document.attributes.has_key?(key)
@@ -874,7 +874,7 @@ module Substituters
candidates = subs.split(',').map {|sub| sub.strip.to_sym}
resolved = candidates & SUB_OPTIONS
if (invalid = candidates - resolved).size > 0
- puts "asciidoctor: WARNING: invalid passthrough macro substitution operation#{invalid.size > 1 ? 's' : ''}: #{invalid * ', '}"
+ warn "asciidoctor: WARNING: invalid passthrough macro substitution operation#{invalid.size > 1 ? 's' : ''}: #{invalid * ', '}"
end
resolved
end
diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb
index 0ffb4bac..d194fe50 100644
--- a/lib/asciidoctor/table.rb
+++ b/lib/asciidoctor/table.rb
@@ -410,7 +410,7 @@ class Table::ParserContext
if format == 'psv'
cell_spec = take_cell_spec
if cell_spec.nil?
- puts 'asciidoctor: ERROR: table missing leading separator, recovering automatically'
+ warn 'asciidoctor: ERROR: table missing leading separator, recovering automatically'
cell_spec = {}
repeat = 1
else
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index b43e8b1d..50be6139 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -985,7 +985,7 @@ section paragraph
output, errors = nil
redirect_streams do |stdout, stderr|
output = render_string input
- errors = stdout.string
+ errors = stderr.string
end
assert_xpath '//*[@id="header"]/*', output, 0
assert_xpath '//*[@id="preamble"]/*', output, 0
diff --git a/test/sections_test.rb b/test/sections_test.rb
index d076c02f..5c0a159d 100644
--- a/test/sections_test.rb
+++ b/test/sections_test.rb
@@ -426,7 +426,7 @@ text in standalone
output, errors = nil
redirect_streams do |stdout, stderr|
output = render_string input
- errors = stdout.string
+ errors = stderr.string
end
assert !errors.empty?