summaryrefslogtreecommitdiff
path: root/spec/bundler/support/command_execution.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/support/command_execution.rb')
-rw-r--r--spec/bundler/support/command_execution.rb48
1 files changed, 40 insertions, 8 deletions
diff --git a/spec/bundler/support/command_execution.rb b/spec/bundler/support/command_execution.rb
index 5639fda3b6..e2915b996d 100644
--- a/spec/bundler/support/command_execution.rb
+++ b/spec/bundler/support/command_execution.rb
@@ -1,7 +1,36 @@
# frozen_string_literal: true
module Spec
- CommandExecution = Struct.new(:command, :working_directory, :exitstatus, :original_stdout, :original_stderr) do
+ class CommandExecution
+ def initialize(command, timeout:)
+ @command = command
+ @timeout = timeout
+ @original_stdout = String.new
+ @original_stderr = String.new
+ end
+
+ attr_accessor :exitstatus, :command, :original_stdout, :original_stderr
+ attr_reader :timeout
+ attr_writer :failure_reason
+
+ def raise_error!
+ return unless failure?
+
+ error_header = if failure_reason == :timeout
+ "Invoking `#{command}` was aborted after #{timeout} seconds with output:"
+ else
+ "Invoking `#{command}` failed with output:"
+ end
+
+ raise <<~ERROR
+ #{error_header}
+
+ ----------------------------------------------------------------------
+ #{stdboth}
+ ----------------------------------------------------------------------
+ ERROR
+ end
+
def to_s
"$ #{command}"
end
@@ -12,16 +41,11 @@ module Spec
end
def stdout
- original_stdout
+ normalize(original_stdout)
end
- # Can be removed once/if https://github.com/oneclick/rubyinstaller2/pull/369 is resolved
def stderr
- return original_stderr unless Gem.win_platform?
-
- original_stderr.split("\n").reject do |l|
- l.include?("operating_system_defaults")
- end.join("\n")
+ normalize(original_stderr)
end
def to_s_verbose
@@ -42,5 +66,13 @@ module Spec
return true unless exitstatus
exitstatus > 0
end
+
+ private
+
+ attr_reader :failure_reason
+
+ def normalize(string)
+ string.dup.force_encoding(Encoding::UTF_8).scrub.strip.gsub("\r\n", "\n")
+ end
end
end