cem_acpt 0.2.8-universal-java-17 → 0.2.9-universal-java-17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cem_acpt/rspec_utils.rb +92 -84
- data/lib/cem_acpt/test_runner/runner.rb +18 -16
- data/lib/cem_acpt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4181b3fae3e4d3f0029314896873f2f604374cc4583473b0b05e689464d346f
|
4
|
+
data.tar.gz: 5e01be5d223962785a18e685f17cc1c3cd393f705cd2b5df174327a8631e1598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9dc631cf11d32f85405358a8bc4e8501afc290a15ed68e80688472de838cfdd81cf09e9a10d346f396de6f1c2505188c443c60e0d4b106b346fd77f079c311c
|
7
|
+
data.tar.gz: 7866ca7c6272369e15c2fbf3f2dd69ce6d6caf6d059b08ad686e7b2fcaf5d63d5d093dbfac076c4c68f3ac7c07f4bcacc2bcd01107667531e069821c00e90313
|
data/Gemfile.lock
CHANGED
data/lib/cem_acpt/rspec_utils.rb
CHANGED
@@ -12,13 +12,17 @@ module CemAcpt
|
|
12
12
|
class BundlerNotFoundError < StandardError; end
|
13
13
|
class RSpecNotFoundError < StandardError; end
|
14
14
|
|
15
|
-
# Holds
|
16
|
-
class
|
17
|
-
|
18
|
-
attr_reader :debug, :format, :test_path, :use_bundler, :pty_pid
|
15
|
+
# Holds RSpec options used by Command
|
16
|
+
class Options
|
17
|
+
OPTIONS = %i[test_path bundle rspec use_bundler bundle_install format debug quiet env].freeze
|
19
18
|
|
19
|
+
attr_accessor(*OPTIONS)
|
20
|
+
|
21
|
+
# @param config [CemAcpt::Config] A config object
|
20
22
|
# @param opts [Hash] options hash for the RSpec command
|
21
23
|
# @option opts [String] :test_path The path (or glob path) to the test file(s) to run. If blank, runs all.
|
24
|
+
# @option opts [String] :bundle The path to the `bundle` binary.
|
25
|
+
# @option opts [String] :rspec The path to the `rspec` binary.
|
22
26
|
# @option opts [Hash] :format Format options for rspec where the key is the format (documentation, json, etc)
|
23
27
|
# and the value is the out-file path. If you do not want to save the results of a format to a file, the
|
24
28
|
# value should be `nil`.
|
@@ -30,56 +34,97 @@ module CemAcpt
|
|
30
34
|
# Default is `true`.
|
31
35
|
# @option opts [Boolean] :bundle_install Whether or not to run `bundle install` before the RSpec command
|
32
36
|
# if `use_bundler` is `true`.
|
33
|
-
# @option opts [Boolean] :use_shell Whether or not to add `$SHELL` as a prefix to the command
|
34
37
|
# @option opts [Hash] :env Environment variables to prepend to the command
|
35
|
-
def initialize(opts
|
36
|
-
@
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
def initialize(config, **opts)
|
39
|
+
@config = config
|
40
|
+
@opts = opts
|
41
|
+
define_option_instance_vars
|
42
|
+
end
|
43
|
+
|
44
|
+
# Finds and sets the paths to the `bundle` and `rspec` binaries. The paths can
|
45
|
+
# be either passed in as options in the `opts` Hash or interrogated from the
|
46
|
+
# system.
|
47
|
+
# @raise [CemAcpt::RSpecUtils::BundlerNotFoundError] if `@use_bundler` is true and
|
48
|
+
# `bundle` binary is not found.
|
49
|
+
# @raise [CemAcpt::RSpecUtils::RSpecNotFoundError] if `rspec` binary is not found.
|
50
|
+
def resolve_bin_paths
|
51
|
+
%i[bundle rspec].each do |bin|
|
52
|
+
bin_path = instance_variable_get("@#{bin}") || `#{ENV['SHELL']} -c 'command -v #{bin}'`.strip
|
53
|
+
bin_not_found(bin, bin_path) unless bin_path && File.exist?(bin_path)
|
54
|
+
instance_variable_set("@#{bin}", bin_path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Detects if the current Ruby context is JRuby
|
59
|
+
def jruby?
|
60
|
+
Object.const_defined?('JRUBY_VERSION')
|
45
61
|
end
|
46
62
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
63
|
+
private
|
64
|
+
|
65
|
+
def defaults
|
66
|
+
@defaults ||= { use_bundler: false,
|
67
|
+
bundle_install: false,
|
68
|
+
format: { documentation: nil },
|
69
|
+
debug: false,
|
70
|
+
quiet: false,
|
71
|
+
env: {} }
|
72
|
+
end
|
73
|
+
|
74
|
+
def define_option_instance_vars
|
75
|
+
OPTIONS.each do |o|
|
76
|
+
val = @config.get("rspec.#{o}") || @opts[o] || defaults[o] || nil
|
77
|
+
instance_variable_set("@#{o}", val)
|
53
78
|
end
|
54
79
|
end
|
55
80
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
81
|
+
# Handles binary paths which are not found
|
82
|
+
# @param bin [Symbol] The binary that was not found, either :bundle or :rspec.
|
83
|
+
# @param bin_path [String] The path to the binary that was checked.
|
84
|
+
# @raise [CemAcpt::RSpecUtils::BundlerNotFoundError] if `@use_bundler` is true and
|
85
|
+
# `bundle` binary is not found.
|
86
|
+
# @raise [CemAcpt::RSpecUtils::RSpecNotFoundError] if `rspec` binary is not found.
|
87
|
+
# @raise [RuntimeError] if `bin` is not :bundle or :rspec.
|
88
|
+
def bin_not_found(bin, bin_path)
|
89
|
+
msg_base = "#{bin} not found."
|
90
|
+
msg = bin_path.nil? ? "#{msg_base} Path is nil." : "#{msg_base} Path: #{bin_path}"
|
91
|
+
case bin
|
92
|
+
when :bundle
|
93
|
+
raise BundlerNotFoundError, msg if opts.use_bundler
|
94
|
+
when :rspec
|
95
|
+
raise RSpecNotFoundError, msg
|
96
|
+
else
|
97
|
+
raise "bin #{bin} not recognized!"
|
98
|
+
end
|
59
99
|
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Holds and formats a RSpec command
|
103
|
+
class Command
|
104
|
+
include CemAcpt::LoggingAsync
|
105
|
+
attr_reader :opts, :pty_pid
|
106
|
+
|
107
|
+
def initialize(opts = Options.new)
|
108
|
+
raise 'opts must be instance of CemAcpt::RSpecUtils::Options' unless opts.is_a?(CemAcpt::RSpecUtils::Options)
|
60
109
|
|
61
|
-
|
62
|
-
@
|
110
|
+
@opts = opts
|
111
|
+
@opts.resolve_bin_paths
|
112
|
+
@opts.env = @opts.env.merge({ 'RSPEC_DEBUG' => 'true' }) if @opts.debug
|
113
|
+
@pty_pid = nil
|
63
114
|
end
|
64
115
|
|
65
116
|
# Adds a new format to the RSpec command
|
66
117
|
# @param fmt [String] The name of the format (i.e. "documentation", "json", etc.)
|
67
118
|
# @param out [String] If specified, saves the specified format to a file at this path
|
68
119
|
def with_format(fmt, out: nil)
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
# Environment variables that will be used for the RSpec command
|
73
|
-
# @return [Hash] A Hash of environment variables with each key pair being: <var name> => <var value>
|
74
|
-
def env
|
75
|
-
@debug ? @env.merge({ 'RSPEC_DEBUG' => 'true' }) : @env
|
120
|
+
opts.format[fmt.to_sym] = out
|
76
121
|
end
|
77
122
|
|
78
123
|
# Returns an array representation of the RSpec command
|
79
124
|
def to_a
|
80
125
|
cmd = cmd_base.dup
|
81
|
-
cmd << test_path if test_path
|
82
|
-
format.each do |fmt, out|
|
126
|
+
cmd << opts.test_path if opts.test_path
|
127
|
+
opts.format.each do |fmt, out|
|
83
128
|
cmd += ['--format', fmt.to_s.shellescape]
|
84
129
|
cmd += ['--out', out.to_s.shellescape] if out
|
85
130
|
end
|
@@ -112,12 +157,12 @@ module CemAcpt
|
|
112
157
|
# @return [Integer] The exit code of the RSpec command
|
113
158
|
def execute_pty(log_prefix: 'RSPEC')
|
114
159
|
async_debug("Executing RSpec command '#{self}' in PTY...", log_prefix)
|
115
|
-
PTY.spawn(env, ENV['SHELL']) do |r, w, pid|
|
160
|
+
PTY.spawn(opts.env, ENV['SHELL']) do |r, w, pid|
|
116
161
|
@pty_pid = pid
|
117
162
|
async_debug("Spawned RSpec PTY with PID #{@pty_pid}", log_prefix)
|
118
163
|
export_envs(w)
|
119
164
|
w.puts "#{self}; exit $?"
|
120
|
-
|
165
|
+
handle_io(r, log_prefix: log_prefix)
|
121
166
|
end
|
122
167
|
$CHILD_STATUS
|
123
168
|
end
|
@@ -130,9 +175,9 @@ module CemAcpt
|
|
130
175
|
def execute_no_pty(log_prefix: 'RSPEC')
|
131
176
|
async_info("Executing RSpec command '#{self}' with Open3.popen2e()...", log_prefix)
|
132
177
|
exit_status = nil
|
133
|
-
Open3.popen2e(env, to_s) do |stdin, std_out_err, wait_thr|
|
178
|
+
Open3.popen2e(opts.env, to_s) do |stdin, std_out_err, wait_thr|
|
134
179
|
stdin.close
|
135
|
-
|
180
|
+
handle_io(std_out_err, log_prefix: log_prefix)
|
136
181
|
exit_status = wait_thr.value
|
137
182
|
end
|
138
183
|
exit_status
|
@@ -147,26 +192,21 @@ module CemAcpt
|
|
147
192
|
|
148
193
|
private
|
149
194
|
|
150
|
-
# Detects if the current Ruby context is JRuby
|
151
|
-
def jruby?
|
152
|
-
File.basename(RbConfig.ruby) == 'jruby'
|
153
|
-
end
|
154
|
-
|
155
195
|
# The base RSpec command
|
156
196
|
def cmd_base
|
157
|
-
use_bundler ? cmd_base_bundler : cmd_base_rspec
|
197
|
+
opts.use_bundler ? cmd_base_bundler : cmd_base_rspec
|
158
198
|
end
|
159
199
|
|
160
200
|
# The base RSpec command if `:use_bundler` is `true`.
|
161
201
|
def cmd_base_bundler
|
162
|
-
base = [
|
163
|
-
base.unshift("#{
|
202
|
+
base = [opts.bundle, 'exec', 'rspec']
|
203
|
+
base.unshift("#{opts.bundle} install;") if opts.bundle_install
|
164
204
|
base
|
165
205
|
end
|
166
206
|
|
167
207
|
# The base RSpec command if `:use_bundler` is `false`
|
168
208
|
def cmd_base_rspec
|
169
|
-
[
|
209
|
+
[opts.rspec]
|
170
210
|
end
|
171
211
|
|
172
212
|
# Puts export statements for each key-value pair in `env` to the given writer.
|
@@ -174,46 +214,14 @@ module CemAcpt
|
|
174
214
|
# pass the statements to a shell.
|
175
215
|
# @param writer [IO] An IO object that supprts `puts` and can send statements to a shell
|
176
216
|
def export_envs(writer)
|
177
|
-
env.each do |key, val|
|
217
|
+
@opts.env.each do |key, val|
|
178
218
|
writer.puts "export #{key}=#{val}"
|
179
219
|
end
|
180
220
|
end
|
181
221
|
|
182
|
-
#
|
183
|
-
|
184
|
-
|
185
|
-
# @param opts [Hash] The options hash
|
186
|
-
# @option opts [String] :bundle An absolute path on the system to the `bundle` binary.
|
187
|
-
# @option opts [String] :rspec An absolute path on the system to the `rspec` binary.
|
188
|
-
# @raise [CemAcpt::RSpecUtils::BundlerNotFoundError] if `@use_bundler` is true and
|
189
|
-
# `bundle` binary is not found.
|
190
|
-
# @raise [CemAcpt::RSpecUtils::RSpecNotFoundError] if `rspec` binary is not found.
|
191
|
-
def validate_and_set_bin_paths(opts = {})
|
192
|
-
%i[bundle rspec].each do |bin|
|
193
|
-
bin_path = opts[bin] || `command -v #{bin}`.strip
|
194
|
-
bin_not_found(bin, bin_path) unless bin_path && File.exist?(bin_path)
|
195
|
-
instance_variable_set("@#{bin}", bin_path)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
# Handles binary paths which are not found
|
200
|
-
# @param bin [Symbol] The binary that was not found, either :bundle or :rspec.
|
201
|
-
# @param bin_path [String] The path to the binary that was checked.
|
202
|
-
# @raise [CemAcpt::RSpecUtils::BundlerNotFoundError] if `@use_bundler` is true and
|
203
|
-
# `bundle` binary is not found.
|
204
|
-
# @raise [CemAcpt::RSpecUtils::RSpecNotFoundError] if `rspec` binary is not found.
|
205
|
-
# @raise [RuntimeError] if `bin` is not :bundle or :rspec.
|
206
|
-
def bin_not_found(bin, bin_path)
|
207
|
-
msg_base = "#{bin} not found."
|
208
|
-
msg = bin_path.nil? ? "#{msg_base} Path is nil." : "#{msg_base} Path: #{bin_path}"
|
209
|
-
case bin
|
210
|
-
when :bundle
|
211
|
-
raise BundlerNotFoundError, msg if @use_bundler
|
212
|
-
when :rspec
|
213
|
-
raise RSpecNotFoundError, msg
|
214
|
-
else
|
215
|
-
raise "bin #{bin} not recognized!"
|
216
|
-
end
|
222
|
+
# Handles IO output
|
223
|
+
def handle_io(io_stream, **kwargs)
|
224
|
+
opts.quiet ? wait_io(io_stream) : read_io(io_stream, log_prefix: kwargs[:log_prefix])
|
217
225
|
end
|
218
226
|
|
219
227
|
# Blocking wait on an IO stream. Wait stops once the IO stream has reached
|
@@ -145,12 +145,12 @@ module CemAcpt
|
|
145
145
|
async_info("Running test #{@node.test_data[:test_name]} on node #{@node.node_name}...", log_prefix('RSPEC'))
|
146
146
|
@node.run_tests do |cmd_env|
|
147
147
|
cmd_opts = rspec_opts
|
148
|
-
cmd_opts
|
148
|
+
cmd_opts.env = cmd_opts.env.merge(cmd_env) if cmd_env
|
149
149
|
# Documentation format gets logged in real time, JSON file is read after the fact
|
150
150
|
begin
|
151
151
|
@rspec_cmd = CemAcpt::RSpecUtils::Command.new(cmd_opts)
|
152
|
-
@rspec_cmd.execute(log_prefix: log_prefix('RSPEC'))
|
153
|
-
@run_result.from_json_file(cmd_opts
|
152
|
+
@rspec_cmd.execute(pty: false, log_prefix: log_prefix('RSPEC'))
|
153
|
+
@run_result.from_json_file(cmd_opts.format[:json])
|
154
154
|
rescue Errno::EIO => e
|
155
155
|
async_error("failed to run rspec: #{@node.test_data[:test_name]}: #{$ERROR_INFO}", log_prefix('RSPEC'))
|
156
156
|
@run_result.from_error(e)
|
@@ -191,19 +191,21 @@ module CemAcpt
|
|
191
191
|
|
192
192
|
# Options used with RSpec
|
193
193
|
def rspec_opts
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
194
|
+
opts_test_path = @node.test_data[:test_file]
|
195
|
+
opts_env = { 'TARGET_HOST' => @node.node_name }
|
196
|
+
opts_debug = (@debug_mode && @context.config.get('verbose'))
|
197
|
+
opts_quiet = @context.config.get('quiet')
|
198
|
+
opts_format = if @context.config.get('verbose')
|
199
|
+
{ json: "results_#{@node.test_data[:test_name]}.json", documentation: nil }
|
200
|
+
else
|
201
|
+
{ json: "results_#{@node.test_data[:test_name]}.json" }
|
202
|
+
end
|
203
|
+
CemAcpt::RSpecUtils::Options.new(@context.config,
|
204
|
+
test_path: opts_test_path,
|
205
|
+
env: opts_env,
|
206
|
+
debug: opts_debug,
|
207
|
+
quiet: opts_quiet,
|
208
|
+
format: opts_format)
|
207
209
|
end
|
208
210
|
end
|
209
211
|
end
|
data/lib/cem_acpt/version.rb
CHANGED