diff --git a/plugins/commands/validate/command.rb b/plugins/commands/validate/command.rb index 9d6ad7bb2..bccbc5755 100644 --- a/plugins/commands/validate/command.rb +++ b/plugins/commands/validate/command.rb @@ -16,10 +16,10 @@ module VagrantPlugins argv = parse_options(opts) return if !argv - # Validate the configuration - @env.machine(@env.machine_names.first, @env.default_provider).action_raw( - :config_validate, - Vagrant::Action::Builtin::ConfigValidate) + # Validate the configuration of all machines + with_target_vms() do |machine| + machine.action_raw(:config_validate, Vagrant::Action::Builtin::ConfigValidate) + end @env.ui.info(I18n.t("vagrant.commands.validate.success")) diff --git a/test/unit/plugins/commands/validate/command_test.rb b/test/unit/plugins/commands/validate/command_test.rb index 66941d72c..2dfd93e75 100644 --- a/test/unit/plugins/commands/validate/command_test.rb +++ b/test/unit/plugins/commands/validate/command_test.rb @@ -48,5 +48,51 @@ describe VagrantPlugins::CommandValidate::Command do expect(err.message).to include("The following settings shouldn't exist: bix") } end + + it "validates correct Vagrantfile of all vms" do + iso_env.vagrantfile <<-EOH + Vagrant.configure("2") do |config| + config.vm.box = "hashicorp/precise64" + + config.vm.define "test" do |vm| + vm.vm.provider :virtualbox + end + + config.vm.define "machine" do |vm| + vm.vm.provider :virtualbox + end + end + EOH + + expect(env.ui).to receive(:info).with(any_args) { |message, _| + expect(message).to include("Vagrantfile validated successfully.") + } + + expect(subject.execute).to eq(0) + end + + it "validates the configuration of all vms" do + iso_env.vagrantfile <<-EOH + Vagrant.configure("2") do |config| + config.vm.box = "hashicorp/precise64" + + config.vm.define "test" do |vm| + vm.vm.provider :virtualbox + end + + config.vm.define "machine" do |vm| + vm.vm.not_provider :virtualbox + end + end + EOH + + expect { subject.execute }.to raise_error(Vagrant::Errors::ConfigInvalid) { |err| + expect(err.message).to include("The following settings shouldn't exist: not_provider") + } + end + + it "throws an exception if there's no Vagrantfile" do + expect { subject.execute }.to raise_error(Vagrant::Errors::NoEnvironmentError) + end end end