summaryrefslogtreecommitdiff
path: root/tasks
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-11-16 19:24:16 -0800
committerJohn Keiser <john@johnkeiser.com>2015-11-17 09:20:34 -0800
commit2d786b751c2a35902fdc7611249d02f42829455c (patch)
treecb8721caa7805129acaaf2662c466b7942933534 /tasks
parentd75e3ed39d4e0bcfe00a962bd46a4c2e870bb877 (diff)
downloadchef-2d786b751c2a35902fdc7611249d02f42829455c.tar.gz
Raise an error when a command fails
Diffstat (limited to 'tasks')
-rw-r--r--tasks/external_tests.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/tasks/external_tests.rb b/tasks/external_tests.rb
index 9304244424..91fa249824 100644
--- a/tasks/external_tests.rb
+++ b/tasks/external_tests.rb
@@ -1,33 +1,41 @@
require 'tempfile'
+require 'bundler'
+
+CURRENT_GEM_NAME = 'chef'
+CURRENT_GEM_PATH = File.expand_path('../..', __FILE__)
def bundle_exec_with_chef(test_gem, commands)
gem_path = Bundler.environment.specs[test_gem].first.full_gem_path
- gemfile_path = File.join(gem_path, 'Gemfile.chef-external-test')
+ gemfile_path = File.join(gem_path, "Gemfile.#{CURRENT_GEM_NAME}-external-test")
gemfile = File.open(gemfile_path, "w")
begin
IO.read(File.join(gem_path, 'Gemfile')).each_line do |line|
if line =~ /^\s*gemspec/
next
- elsif line =~ /^\s*gem 'chef'|\s*gem "chef"/
+ elsif line =~ /^\s*gem '#{CURRENT_GEM_NAME}'|\s*gem "#{CURRENT_GEM_NAME}"/
next
elsif line =~ /^\s*dev_gem\s*['"](.+)['"]\s*$/
line = "gem '#{$1}', github: 'poise/#{$1}'"
- elsif line =~ /\s*gem\s*['"]#{test_gem}['"]/ # foodcritic
+ elsif line =~ /\s*gem\s*['"]#{test_gem}['"]/ # foodcritic end
next
end
gemfile.puts(line)
end
- gemfile.puts("gem 'chef', path: #{File.expand_path('../..', __FILE__).inspect}")
+ gemfile.puts("gem #{CURRENT_GEM_NAME.inspect}, path: #{CURRENT_GEM_PATH.inspect}")
gemfile.puts("gemspec path: #{gem_path.inspect}")
gemfile.close
Dir.chdir(gem_path) do
- system({ 'BUNDLE_GEMFILE' => gemfile.path, 'RUBYOPT' => nil }, "bundle install")
+ unless system({ 'RUBYOPT' => nil, 'GEMFILE_MOD' => nil }, "bundle install --gemfile #{gemfile_path}")
+ raise "Error running bundle install --gemfile #{gemfile_path} in #{gem_path}: #{$?.exitstatus}\nGemfile:\n#{IO.read(gemfile_path)}"
+ end
Array(commands).each do |command|
- system({ 'BUNDLE_GEMFILE' => gemfile.path, 'RUBYOPT' => nil }, "bundle exec #{command}")
+ unless system({ 'BUNDLE_GEMFILE' => gemfile_path, 'RUBYOPT' => nil, 'GEMFILE_MOD' => nil }, "bundle exec #{command}")
+ raise "Error running bundle exec #{command} in #{gem_path} with BUNDLE_GEMFILE=#{gemfile_path}: #{$?.exitstatus}\nGemfile:\n#{IO.read(gemfile_path)}"
+ end
end
end
ensure
- File.delete(gemfile_path)
+ File.delete(gemfile_path) if File.exist?(gemfile_path)
end
end