Navigation Menu

Skip to content

Commit

Permalink
Extract output normalization code
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2012
1 parent 9c68246 commit fec07b3
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/grntest/tester.rb
Expand Up @@ -936,28 +936,32 @@ def normalize_result(result)
when :input
normalized_result << content
when :output
type = options[:type]
case type
when "json", "msgpack"
status, *values = parse_result(content, type)
normalized_status = normalize_status(status)
normalized_output_content = [normalized_status, *values]
normalized_output = JSON.generate(normalized_output_content)
if normalized_output.bytesize > @max_n_columns
normalized_output = JSON.pretty_generate(normalized_output_content)
end
normalized_output.force_encoding("ASCII-8BIT")
normalized_result << "#{normalized_output}\n"
else
normalized_result << "#{content}\n".force_encoding("ASCII-8BIT")
end
normalized_result << normalize_output(content, options)
when :error
normalized_result << "#{content}\n".force_encoding("ASCII-8BIT")
end
end
normalized_result
end

def normalize_output(content, options)
type = options[:type]
case type
when "json", "msgpack"
status, *values = parse_result(content, type)
normalized_status = normalize_status(status)
normalized_output_content = [normalized_status, *values]
normalized_output = JSON.generate(normalized_output_content)
if normalized_output.bytesize > @max_n_columns
normalized_output = JSON.pretty_generate(normalized_output_content)
end
normalized_output.force_encoding("ASCII-8BIT")
"#{normalized_output}\n"
else
"#{content}\n".force_encoding("ASCII-8BIT")
end
end

def parse_result(result, type)
case type
when "json"
Expand Down

0 comments on commit fec07b3

Please sign in to comment.