83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/pdk/tests/unit.rb', line 83
def self.invoke(report, options = {})
require 'pdk/util'
require 'pdk/util/bundler'
PDK::Util::Bundler.ensure_binstubs!('rake', 'rspec-core')
setup
tests = options[:tests]
tests = tests.tr('\\', '/') unless tests.nil?
environment = {}
environment['PUPPET_GEM_VERSION'] = options[:puppet] if options[:puppet]
spinner_msg = options[:parallel] ? 'Running unit tests in parallel.' : 'Running unit tests.'
if options[:interactive]
environment['CI_SPEC_OPTIONS'] = if options[:verbose]
'--format documentation'
else
'--format progress'
end
result = interactive_rake(cmd(tests, options), environment)
return result[:exit_code]
end
if (options[:verbose]) && (options[:format])
environment['CI_SPEC_OPTIONS'] = '--format documentation'
result = interactive_rake(cmd(tests, options), environment)
return result[:exit_code] unless (result[:exit_code]).zero?
spinner_msg = "Exporting unit tests -> #{options[:format]}"
end
environment['CI_SPEC_OPTIONS'] = '--format j'
result = rake(cmd(tests, options), spinner_msg, environment)
json_result = if options[:parallel]
PDK::Util.find_all_json_in(result[:stdout])
else
PDK::Util.find_first_json_in(result[:stdout])
end
if parallel_with_no_tests?(options[:parallel], json_result, result)
json_result = [{ 'messages' => ['No examples found.'] }]
result[:exit_code] = 0
end
raise PDK::CLI::FatalError, format('Unit test output did not contain a valid JSON result: %{output}', output: result[:stdout]) if json_result.nil? || json_result.empty?
json_result = merge_json_results(json_result) if options[:parallel]
parse_output(report, json_result, result[:duration])
result[:exit_code]
ensure
tear_down if options[:'clean-fixtures']
end
|