From 32e981ce7cfbc21d2c5fe1815536ab0e1cb884a4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 26 Oct 2015 18:10:26 -0700 Subject: [PATCH] core: machine-readable output should include standard UI output As a "ui" type --- lib/vagrant/ui.rb | 6 ++++++ test/unit/vagrant/ui_test.rb | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index ba982bc05..fb5929f32 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -103,6 +103,12 @@ module Vagrant raise Errors::UIExpectsTTY end + [:detail, :warn, :error, :info, :output, :success].each do |method| + define_method(method) do |message, *opts| + machine("ui", method.to_s, message) + end + end + def machine(type, *data) opts = {} opts = data.pop if data.last.kind_of?(Hash) diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index e7f2299dd..61bfe7270 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -215,6 +215,24 @@ describe Vagrant::UI::MachineReadable do end end + [:detail, :warn, :error, :info, :output, :success].each do |method| + describe "##{method}" do + it "outputs UI type to the machine-readable output" do + expect(subject).to receive(:safe_puts).with { |message| + parts = message.split(",") + expect(parts.length).to eq(5) + expect(parts[1]).to eq("") + expect(parts[2]).to eq("ui") + expect(parts[3]).to eq(method.to_s) + expect(parts[4]).to eq("foo") + true + } + + subject.send(method, "foo") + end + end + end + describe "#machine" do it "is formatted properly" do expect(subject).to receive(:safe_puts).with { |message|