From 9e4475cb77625c21f32be85975d91b224d2f6da4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Dec 2011 19:02:10 -0800 Subject: [PATCH] Test running shell scripts inline --- lib/vagrant/provisioners/shell.rb | 9 ++++++--- test/acceptance/provisioning/shell_test.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/provisioners/shell.rb b/lib/vagrant/provisioners/shell.rb index 450597a61..08940bece 100644 --- a/lib/vagrant/provisioners/shell.rb +++ b/lib/vagrant/provisioners/shell.rb @@ -27,9 +27,12 @@ module Vagrant end # Validate the existence of a script to upload - expanded_path = Pathname.new(path).expand_path(env.root_path) - if path && !expanded_path.file? - errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", :path => expanded_path)) + if path + expanded_path = Pathname.new(path).expand_path(env.root_path) + if !expanded_path.file? + errors.add(I18n.t("vagrant.provisioners.shell.path_invalid", + :path => expanded_path)) + end end # There needs to be a path to upload the script to diff --git a/test/acceptance/provisioning/shell_test.rb b/test/acceptance/provisioning/shell_test.rb index ab081de57..17af866c1 100644 --- a/test/acceptance/provisioning/shell_test.rb +++ b/test/acceptance/provisioning/shell_test.rb @@ -29,4 +29,25 @@ vf result_file.exist?.should be result_file.read.should == "success\n" end + + it "runs an inline script" do + require_box("default") + + assert_execute("vagrant", "box", "add", "base", box_path("default")) + + environment.workdir.join("Vagrantfile").open("w+") do |f| + f.write(<<-vf) +Vagrant::Config.run do |config| + config.vm.box = "base" + config.vm.provision :shell, :inline => "echo success > /vagrant/results" +end +vf + end + + assert_execute("vagrant", "up") + + result_file = environment.workdir.join("results") + result_file.exist?.should be + result_file.read.should == "success\n" + end end