Skip to content

Commit

Permalink
Rubocop reported fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Aravinda VK <[email protected]>
  • Loading branch information
aravindavk committed Dec 28, 2023
1 parent 2902a9a commit a745687
Show file tree
Hide file tree
Showing 10 changed files with 760 additions and 744 deletions.
1 change: 0 additions & 1 deletion kadalu-binnacle.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# rubocop:disable Gemspec/RequiredRubyVersion
# frozen_string_literal: true

require_relative 'lib/kadalu/kadalu'
require_relative 'lib/kadalu/binnacle/version'

Gem::Specification.new do |spec|
Expand Down
151 changes: 77 additions & 74 deletions lib/kadalu/binnacle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,76 @@

require 'open3'

require 'kadalu/kadalu'
require 'kadalu/binnacle/store'
require 'kadalu/binnacle/plugins'
require 'kadalu/binnacle/plugins/commands'
require 'kadalu/binnacle/plugins/compare'
require 'kadalu/binnacle/plugins/http'
require 'kadalu/binnacle/messages'

module Kadalu::Binnacle
module_function

# Runs the given task file as a child process.
# This is to prevent exiting the main process if the
# child process exits. Collect the task file metrics and
# return to the caller in the end.
# rubocop: disable Metrics/AbcSize
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/PerceivedComplexity
def start(task_file, opts)
t1 = Time.now

# First line TAP output
Messages.file_started(task_file)

cmd_verbose_opts = ((0...opts.verbose).map { |_o| '-v' }).join(' ')
wide_opts = opts.wide ? '-w' : ''
cmd = "#{$PROGRAM_NAME} #{task_file} --runner #{cmd_verbose_opts} #{wide_opts}"

metrics = {
ok: true,
file: task_file,
passed: 0,
failed: 0,
tasks: [],
duration_seconds: 0,
completed: true
}

env = { 'RUBYLIB' => ENV.fetch('RUBYLIB', '') }
error_msgs = []
Utils.execute(env, cmd) do |stdout_line, stderr_line, ret|
unless stdout_line.nil?
# Only print the Test case Summary line
if stdout_line.start_with?('{')
data = JSON.parse(stdout_line, { symbolize_names: true })
metrics[:tasks] << data
Messages.task_summary(data)
if data[:ok]
metrics[:passed] += 1
else
metrics[:failed] += 1
module Kadalu
module Binnacle
module_function

# Runs the given task file as a child process.
# This is to prevent exiting the main process if the
# child process exits. Collect the task file metrics and
# return to the caller in the end.
# rubocop: disable Metrics/AbcSize
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/PerceivedComplexity
def start(task_file, opts)
t1 = Time.now

# First line TAP output
Messages.file_started(task_file)

cmd_verbose_opts = ((0...opts.verbose).map { |_o| '-v' }).join(' ')
wide_opts = opts.wide ? '-w' : ''
cmd = "#{$PROGRAM_NAME} #{task_file} --runner #{cmd_verbose_opts} #{wide_opts}"

metrics = {
ok: true,
file: task_file,
passed: 0,
failed: 0,
tasks: [],
duration_seconds: 0,
completed: true
}

env = { 'RUBYLIB' => ENV.fetch('RUBYLIB', '') }
error_msgs = []
Utils.execute(env, cmd) do |stdout_line, stderr_line, ret|
unless stdout_line.nil?
# Only print the Test case Summary line
if stdout_line.start_with?('{')
begin
data = JSON.parse(stdout_line, { symbolize_names: true })
metrics[:tasks] << data
Messages.task_summary(data)
if data[:ok]
metrics[:passed] += 1
else
metrics[:failed] += 1
end

next
rescue JSON::ParserError
end
end

next
# Print output/error only in verbose mode
Messages.diagnostic(stdout_line) if opts.verbose.positive?
end

# Print output/error only in verbose mode
Messages.diagnostic(stdout_line) if opts.verbose.positive?
end

unless stderr_line.nil?
error_msgs << stderr_line
Messages.diagnostic(stderr_line) if opts.verbose.positive?
end
unless stderr_line.nil?
error_msgs << stderr_line
Messages.diagnostic(stderr_line) if opts.verbose.positive?
end

unless ret.nil?
if ret != 0
if !ret.nil? && (ret != 0)
warn "# Failed to execute #{task_file}"
# Print the error lines only if verbose is not given
# If verbose is given, then those stderr messages are
Expand All @@ -78,29 +81,29 @@ def start(task_file, opts)
metrics[:ok] = false
end
end
end

metrics[:ok] = false if metrics[:failed] > 0
metrics[:ok] = false if (metrics[:failed]).positive?

metrics[:duration_seconds] = Time.now - t1
Messages.file_completed(task_file, metrics)
metrics
end
# rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/PerceivedComplexity
metrics[:duration_seconds] = Time.now - t1
Messages.file_completed(task_file, metrics)
metrics
end
# rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/PerceivedComplexity

def runner(task_file, args)
Store.set(:debug, args.verbose == 2)
Store.set(:wide, args.wide)
def runner(task_file, args)
Store.set(:debug, args.verbose == 2)
Store.set(:wide, args.wide)

full_path = File.expand_path(task_file)
full_path = File.expand_path(task_file)

begin
load full_path
rescue LoadError
exit
begin
load full_path
rescue LoadError
exit
end
end
end
end
Loading

0 comments on commit a745687

Please sign in to comment.