summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-01-23 10:40:45 -0800
committerTim Smith <tsmith@chef.io>2017-01-23 10:40:45 -0800
commitf328bf612d47225eacf1e4ce0c43f41999d30afc (patch)
tree6cf0fc2795716867c2910d014caf9ff22a264127
parent90ade0a53c3296aa268771101344616756b15a87 (diff)
downloadohai-f328bf612d47225eacf1e4ce0c43f41999d30afc.tar.gz
Only look for xlc on AIX and rename collect_cc to collect_sunpro
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/c.rb12
-rw-r--r--spec/unit/plugins/c_spec.rb80
2 files changed, 52 insertions, 40 deletions
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index c9abb8b1..61b20cc6 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -137,7 +137,7 @@ Ohai.plugin(:C) do
end
end
- def collect_cc
+ def collect_sunpro
# sun pro
collect("cc -V -flags") do |so|
output = so.stderr.split
@@ -162,6 +162,13 @@ Ohai.plugin(:C) do
end
end
+ collect_data(:aix) do
+ @c = Mash.new
+ collect_xlc
+ collect_gcc
+ languages[:c] = @c unless @c.empty?
+ end
+
collect_data(:darwin) do
@c = Mash.new
collect_gcc if xcode_installed?
@@ -186,8 +193,7 @@ Ohai.plugin(:C) do
@c = Mash.new
collect_gcc
collect_glibc
- collect_xlc
- collect_cc
+ collect_sunpro
languages[:c] = @c unless @c.empty?
end
end
diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb
index 8ddb6d71..ca963f3c 100644
--- a/spec/unit/plugins/c_spec.rb
+++ b/spec/unit/plugins/c_spec.rb
@@ -89,6 +89,49 @@ describe Ohai::System, "plugin c" do
allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
end
+ context "on AIX" do
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:aix)
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
+ end
+
+ #ibm xlc
+ it "gets the xlc version from running xlc -qversion" do
+ expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
+ plugin.run
+ end
+
+ it "sets languages[:c][:xlc][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:xlc][:version]).to eql("9.0")
+ end
+
+ it "sets languages[:c][:xlc][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:xlc][:description]).to eql("IBM XL C/C++ Enterprise Edition for AIX, V9.0")
+ end
+
+ it "does not set the languages[:c][:xlc] tree up if xlc command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
+ end
+
+ it "does not set the languages[:c][:xlc] tree up if xlc command fails" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
+ end
+
+ it "sets the languages[:c][:xlc] tree up if xlc exit status is 249" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
+ end
+
+ end
+
context "on HPUX" do
before(:each) do
allow(plugin).to receive(:collect_os).and_return(:hpux)
@@ -216,8 +259,6 @@ describe Ohai::System, "plugin c" do
# glibc
allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, ""))
allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, ""))
- #ibm xlc
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
#sun pro
allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
end
@@ -304,41 +345,6 @@ describe Ohai::System, "plugin c" do
expect(plugin.languages[:c][:glibc][:version]).to eql("2.5")
end
- #ibm xlc
- it "gets the xlc version from running xlc -qversion" do
- expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
- plugin.run
- end
-
- it "sets languages[:c][:xlc][:version]" do
- plugin.run
- expect(plugin.languages[:c][:xlc][:version]).to eql("9.0")
- end
-
- it "sets languages[:c][:xlc][:description]" do
- plugin.run
- expect(plugin.languages[:c][:xlc][:description]).to eql("IBM XL C/C++ Enterprise Edition for AIX, V9.0")
- end
-
- it "does not set the languages[:c][:xlc] tree up if xlc command exits nonzero" do
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
- plugin.run
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
- end
-
- it "does not set the languages[:c][:xlc] tree up if xlc command fails" do
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec)
- plugin.run
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
- end
-
- it "sets the languages[:c][:xlc] tree up if xlc exit status is 249" do
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
- plugin.run
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
- end
-
#sun pro
it "gets the cc version from running cc -V -flags" do
expect(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))