Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove duplicated logic by defining the method to read log files
Browse files Browse the repository at this point in the history
otegami committed Jan 14, 2025
1 parent b999779 commit e3157b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/command_line/helper/command_runner.rb
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ def run_command_interactive(*command_line,
rescue SystemCallError
end
end
error_output = @error_output_log_path.read.encode("UTF-8", "locale")
error_output = read_log(@error_output_log_path)
Result.new("", error_output)
end
end
@@ -201,8 +201,8 @@ def run_command_sync(*command_line)
:err => @error_output_log_path.to_s,
}
succeeded = system(*command_line, options)
output = @output_log_path.read.encode("UTF-8", "locale")
error_output = @error_output_log_path.read.encode("UTF-8", "locale")
output = read_log(@output_log_path)
error_output = read_log(@error_output_log_path)
unless succeeded
message = <<-MESSAGE.chomp
failed to run: #{command_line.join(" ").encode("UTF-8")}
@@ -217,4 +217,9 @@ def run_command_sync(*command_line)
end
Result.new(output, error_output)
end

def read_log(log_path)
return "" unless File.exist?(log_path)
File.read(@log_path).encode("UTF-8", "locale")
end
end

0 comments on commit e3157b1

Please sign in to comment.