diff options
author | Tim Smith <tsmith@chef.io> | 2017-03-09 10:10:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-09 10:10:36 -0800 |
commit | cab56af9f8e096f8ce0053e24d8f488c79708824 (patch) | |
tree | 18ddaf89bb8e132fb2dc2f6d03bb648f2c7d3c05 | |
parent | e231e61b81c789b3d68a3b2ddf1d94aee7c7b3cc (diff) | |
parent | 11e7f786e767dd41398d1309e133173f47eb731e (diff) | |
download | ohai-cab56af9f8e096f8ce0053e24d8f488c79708824.tar.gz |
Merge pull request #958 from chef/lua
Fix lua detection on new versions of lua
-rw-r--r-- | lib/ohai/plugins/lua.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/lua_spec.rb | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb index 8c1ff496..ad91c91d 100644 --- a/lib/ohai/plugins/lua.rb +++ b/lib/ohai/plugins/lua.rb @@ -27,7 +27,9 @@ Ohai.plugin(:Lua) do # Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio if so.exitstatus == 0 lua = Mash.new - lua[:version] = so.stderr.split[1] + # at some point in lua's history they went from outputting the version + # on stderr to doing it on stdout. This handles old / new versions + lua[:version] = so.stdout.empty? ? so.stderr.split[1] : so.stdout.split[1] languages[:lua] = lua if lua[:version] end rescue Ohai::Exceptions::Exec diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index 46a98574..58ddeba5 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -26,8 +26,8 @@ describe Ohai::System, "plugin lua" do before(:each) do plugin[:languages] = Mash.new - @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" - allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) + @message = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @message)) end it "gets the lua version from running lua -v" do @@ -51,4 +51,10 @@ describe Ohai::System, "plugin lua" do plugin.run expect(plugin.languages).not_to have_key(:lua) end + + it "sets languages[:lua][:version] when 'lua -v' returns output on stdout not stderr" do + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, @message, "")) + plugin.run + expect(plugin.languages[:lua][:version]).to eql("5.1.2") + end end |