mirror of
https://github.com/inspec/inspec
synced 2024-11-14 17:07:09 +00:00
Fix extra '&&' in windows functional tests, add diagnostics (#3717)
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
commit
aea7052a5c
1 changed files with 18 additions and 5 deletions
|
@ -33,6 +33,15 @@ module Inspec
|
|||
@train_result = train_result
|
||||
@payload = OpenStruct.new
|
||||
end
|
||||
|
||||
# Intentional failure to cause CI to print output
|
||||
def diagnose!
|
||||
msg = ''
|
||||
msg += "\nInvocation:\n" + payload.invocation
|
||||
msg += "\nSTDOUT:\n" + stdout
|
||||
msg += "\nSTDERR:\n" + stderr
|
||||
msg.must_equal ''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,23 +96,27 @@ module FunctionalHelper
|
|||
|
||||
def inspec(commandline, prefix = nil)
|
||||
if is_windows?
|
||||
result = CMD.run_command("cmd /C \"#{prefix} bundle exec ruby #{exec_inspec} #{commandline}\"")
|
||||
invocation = "cmd /C \"#{prefix} bundle exec ruby #{exec_inspec} #{commandline}\""
|
||||
result = CMD.run_command(invocation)
|
||||
result.stdout.encode!(universal_newline: true)
|
||||
result.stderr.encode!(universal_newline: true)
|
||||
convert_windows_output(result.stdout)
|
||||
# remove the CLIXML header trash in windows
|
||||
result.stderr.gsub!("#< CLIXML\n", '')
|
||||
Inspec::FuncTestRunResult.new(result)
|
||||
ftrr = Inspec::FuncTestRunResult.new(result)
|
||||
else
|
||||
Inspec::FuncTestRunResult.new(CMD.run_command("#{prefix} #{exec_inspec} #{commandline}"))
|
||||
invocation = "#{prefix} #{exec_inspec} #{commandline}"
|
||||
ftrr = Inspec::FuncTestRunResult.new(CMD.run_command(invocation))
|
||||
end
|
||||
ftrr.payload.invocation = invocation
|
||||
ftrr
|
||||
end
|
||||
|
||||
def inspec_with_env(commandline, env = {})
|
||||
inspec(commandline, assemble_env_prefix(env))
|
||||
end
|
||||
|
||||
# This version allows additional options.
|
||||
# This version allows additional options.
|
||||
# @param String command_line Invocation, without the word 'inspec'
|
||||
# @param Hash opts Additonal options, see below
|
||||
# :env Hash A hash of environment vars to expose to the invocation.
|
||||
|
@ -174,7 +187,7 @@ module FunctionalHelper
|
|||
def assemble_env_prefix(env = {})
|
||||
if is_windows?
|
||||
env_prefix = env.to_a.map { |assignment| "set #{assignment[0]}=#{assignment[1]}" }.join('&& ')
|
||||
env_prefix += '&& '
|
||||
env_prefix += '&& ' unless env_prefix.empty?
|
||||
else
|
||||
env_prefix = env.to_a.map { |assignment| "#{assignment[0]}=#{assignment[1]}" }.join(' ')
|
||||
env_prefix += ' '
|
||||
|
|
Loading…
Reference in a new issue