Skip to content

Commit a745687

Browse files
committed
Rubocop reported fixes
Signed-off-by: Aravinda VK <[email protected]>
1 parent 2902a9a commit a745687

File tree

10 files changed

+760
-744
lines changed

10 files changed

+760
-744
lines changed

kadalu-binnacle.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# rubocop:disable Gemspec/RequiredRubyVersion
22
# frozen_string_literal: true
33

4-
require_relative 'lib/kadalu/kadalu'
54
require_relative 'lib/kadalu/binnacle/version'
65

76
Gem::Specification.new do |spec|

lib/kadalu/binnacle.rb

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,76 @@
22

33
require 'open3'
44

5-
require 'kadalu/kadalu'
65
require 'kadalu/binnacle/store'
76
require 'kadalu/binnacle/plugins'
87
require 'kadalu/binnacle/plugins/commands'
98
require 'kadalu/binnacle/plugins/compare'
9+
require 'kadalu/binnacle/plugins/http'
1010
require 'kadalu/binnacle/messages'
1111

12-
module Kadalu::Binnacle
13-
module_function
14-
15-
# Runs the given task file as a child process.
16-
# This is to prevent exiting the main process if the
17-
# child process exits. Collect the task file metrics and
18-
# return to the caller in the end.
19-
# rubocop: disable Metrics/AbcSize
20-
# rubocop: disable Metrics/CyclomaticComplexity
21-
# rubocop: disable Metrics/MethodLength
22-
# rubocop: disable Metrics/PerceivedComplexity
23-
def start(task_file, opts)
24-
t1 = Time.now
25-
26-
# First line TAP output
27-
Messages.file_started(task_file)
28-
29-
cmd_verbose_opts = ((0...opts.verbose).map { |_o| '-v' }).join(' ')
30-
wide_opts = opts.wide ? '-w' : ''
31-
cmd = "#{$PROGRAM_NAME} #{task_file} --runner #{cmd_verbose_opts} #{wide_opts}"
32-
33-
metrics = {
34-
ok: true,
35-
file: task_file,
36-
passed: 0,
37-
failed: 0,
38-
tasks: [],
39-
duration_seconds: 0,
40-
completed: true
41-
}
42-
43-
env = { 'RUBYLIB' => ENV.fetch('RUBYLIB', '') }
44-
error_msgs = []
45-
Utils.execute(env, cmd) do |stdout_line, stderr_line, ret|
46-
unless stdout_line.nil?
47-
# Only print the Test case Summary line
48-
if stdout_line.start_with?('{')
49-
data = JSON.parse(stdout_line, { symbolize_names: true })
50-
metrics[:tasks] << data
51-
Messages.task_summary(data)
52-
if data[:ok]
53-
metrics[:passed] += 1
54-
else
55-
metrics[:failed] += 1
12+
module Kadalu
13+
module Binnacle
14+
module_function
15+
16+
# Runs the given task file as a child process.
17+
# This is to prevent exiting the main process if the
18+
# child process exits. Collect the task file metrics and
19+
# return to the caller in the end.
20+
# rubocop: disable Metrics/AbcSize
21+
# rubocop: disable Metrics/CyclomaticComplexity
22+
# rubocop: disable Metrics/MethodLength
23+
# rubocop: disable Metrics/PerceivedComplexity
24+
def start(task_file, opts)
25+
t1 = Time.now
26+
27+
# First line TAP output
28+
Messages.file_started(task_file)
29+
30+
cmd_verbose_opts = ((0...opts.verbose).map { |_o| '-v' }).join(' ')
31+
wide_opts = opts.wide ? '-w' : ''
32+
cmd = "#{$PROGRAM_NAME} #{task_file} --runner #{cmd_verbose_opts} #{wide_opts}"
33+
34+
metrics = {
35+
ok: true,
36+
file: task_file,
37+
passed: 0,
38+
failed: 0,
39+
tasks: [],
40+
duration_seconds: 0,
41+
completed: true
42+
}
43+
44+
env = { 'RUBYLIB' => ENV.fetch('RUBYLIB', '') }
45+
error_msgs = []
46+
Utils.execute(env, cmd) do |stdout_line, stderr_line, ret|
47+
unless stdout_line.nil?
48+
# Only print the Test case Summary line
49+
if stdout_line.start_with?('{')
50+
begin
51+
data = JSON.parse(stdout_line, { symbolize_names: true })
52+
metrics[:tasks] << data
53+
Messages.task_summary(data)
54+
if data[:ok]
55+
metrics[:passed] += 1
56+
else
57+
metrics[:failed] += 1
58+
end
59+
60+
next
61+
rescue JSON::ParserError
62+
end
5663
end
5764

58-
next
65+
# Print output/error only in verbose mode
66+
Messages.diagnostic(stdout_line) if opts.verbose.positive?
5967
end
6068

61-
# Print output/error only in verbose mode
62-
Messages.diagnostic(stdout_line) if opts.verbose.positive?
63-
end
64-
65-
unless stderr_line.nil?
66-
error_msgs << stderr_line
67-
Messages.diagnostic(stderr_line) if opts.verbose.positive?
68-
end
69+
unless stderr_line.nil?
70+
error_msgs << stderr_line
71+
Messages.diagnostic(stderr_line) if opts.verbose.positive?
72+
end
6973

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

83-
metrics[:ok] = false if metrics[:failed] > 0
85+
metrics[:ok] = false if (metrics[:failed]).positive?
8486

85-
metrics[:duration_seconds] = Time.now - t1
86-
Messages.file_completed(task_file, metrics)
87-
metrics
88-
end
89-
# rubocop: enable Metrics/AbcSize
90-
# rubocop: enable Metrics/CyclomaticComplexity
91-
# rubocop: enable Metrics/MethodLength
92-
# rubocop: enable Metrics/PerceivedComplexity
87+
metrics[:duration_seconds] = Time.now - t1
88+
Messages.file_completed(task_file, metrics)
89+
metrics
90+
end
91+
# rubocop: enable Metrics/AbcSize
92+
# rubocop: enable Metrics/CyclomaticComplexity
93+
# rubocop: enable Metrics/MethodLength
94+
# rubocop: enable Metrics/PerceivedComplexity
9395

94-
def runner(task_file, args)
95-
Store.set(:debug, args.verbose == 2)
96-
Store.set(:wide, args.wide)
96+
def runner(task_file, args)
97+
Store.set(:debug, args.verbose == 2)
98+
Store.set(:wide, args.wide)
9799

98-
full_path = File.expand_path(task_file)
100+
full_path = File.expand_path(task_file)
99101

100-
begin
101-
load full_path
102-
rescue LoadError
103-
exit
102+
begin
103+
load full_path
104+
rescue LoadError
105+
exit
106+
end
104107
end
105108
end
106109
end

0 commit comments

Comments
 (0)