Navigation Menu

Skip to content

Commit

Permalink
Normalize path in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 21, 2014
1 parent 7845708 commit a87cebf
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions lib/grntest/test-runner.rb
Expand Up @@ -411,7 +411,7 @@ def normalize_actual_result(result)
when :output
normalized_result << normalize_output(content, options)
when :error
normalized_result << normalize_raw_content(content)
normalized_result << normalize_error(content)
when :n_leaked_objects
result.n_leaked_objects = content
end
Expand All @@ -435,7 +435,8 @@ def normalize_output(content, options)
return $!.message
end
normalized_status = normalize_status(status)
normalized_output_content = [normalized_status, *values]
normalized_values = normalize_values(values)
normalized_output_content = [normalized_status, *normalized_values]
normalized_output = JSON.generate(normalized_output_content)
if normalized_output.bytesize > @max_n_columns
normalized_output = JSON.pretty_generate(normalized_output_content)
Expand Down Expand Up @@ -463,10 +464,43 @@ def normalize_status(status)
else
message, backtrace = rest
_ = backtrace # for suppress warnings
message = normalize_path_in_error_message(message)
[[return_code, 0.0, 0.0], message]
end
end

def normalize_values(values)
values.collect do |value|
if value.is_a?(Hash) and value["exception"]
exception = Marshal.load(Marshal.dump(value["exception"]))
message = exception["message"]
exception["message"] = normalize_path_in_error_message(message)
value.merge("exception" => exception)
else
value
end
end
end

def normalize_error(content)
content = normalize_path_in_error_message(content)
normalize_raw_content(content)
end

def normalize_path_in_error_message(content)
case content
when /\A(.*'fopen: failed to open mruby script file: )<(.+?)>'(.*)\z/
pre = $1
path = $2
post = $3
normalized_path = File.basename(path)
post = "" unless post.end_with?(")")
"#{pre}<#{normalized_path}>'#{post}"
else
content
end
end

def test_script_path
@worker.test_script_path
end
Expand Down

0 comments on commit a87cebf

Please sign in to comment.