aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/utils
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test/utils')
-rw-r--r--Library/Homebrew/test/utils/bottles/bintray_spec.rb18
-rw-r--r--Library/Homebrew/test/utils/bottles/bottles_spec.rb80
-rw-r--r--Library/Homebrew/test/utils/popen_spec.rb28
-rw-r--r--Library/Homebrew/test/utils/shell_spec.rb93
4 files changed, 219 insertions, 0 deletions
diff --git a/Library/Homebrew/test/utils/bottles/bintray_spec.rb b/Library/Homebrew/test/utils/bottles/bintray_spec.rb
new file mode 100644
index 000000000..a7dfc00ea
--- /dev/null
+++ b/Library/Homebrew/test/utils/bottles/bintray_spec.rb
@@ -0,0 +1,18 @@
+require "utils/bottles"
+
+describe Utils::Bottles::Bintray do
+ describe "::package" do
+ it "converts a Formula name to a package name" do
+ expect(described_class.package("openssl@1.1")).to eq("openssl:1.1")
+ expect(described_class.package("gtk+")).to eq("gtkx")
+ expect(described_class.package("llvm")).to eq("llvm")
+ end
+ end
+
+ describe "::repository" do
+ it "returns the repository for a given Tap" do
+ expect(described_class.repository(Tap.new("homebrew", "bintray-test")))
+ .to eq("bottles-bintray-test")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/bottles/bottles_spec.rb b/Library/Homebrew/test/utils/bottles/bottles_spec.rb
new file mode 100644
index 000000000..8b54b0b34
--- /dev/null
+++ b/Library/Homebrew/test/utils/bottles/bottles_spec.rb
@@ -0,0 +1,80 @@
+require "utils/bottles"
+
+describe Utils::Bottles do
+ describe "#tag", :needs_macos do
+ it "returns :tiger_foo on Tiger PowerPC" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:foo)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:tiger_foo)
+ end
+
+ it "returns :tiger on Tiger Intel" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:tiger)
+ end
+
+ it "returns :tiger_g5_64 on Tiger PowerPC 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:g5)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:tiger_g5_64)
+ end
+
+ # Note that this will probably never be used
+ it "returns :tiger_64 on Tiger Intel 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:tiger_64)
+ end
+
+ it "returns :leopard on Leopard Intel" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:leopard)
+ end
+
+ it "returns :leopard_g5_64 on Leopard PowerPC 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:g5)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:leopard_g5_64)
+ end
+
+ it "returns :leopard_64 on Leopard Intel 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:leopard_64)
+ end
+
+ it "returns :snow_leopard_32 on Snow Leopard 32-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
+ allow(Hardware::CPU).to receive(:is_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:snow_leopard_32)
+ end
+
+ it "returns :snow_leopard on Snow Leopard 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
+ allow(Hardware::CPU).to receive(:is_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:snow_leopard)
+ end
+
+ it "returns :lion on Lion" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.7"))
+ expect(described_class.tag).to eq(:lion)
+ end
+
+ it "returns :mountain_lion on Mountain Lion" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.8"))
+ expect(described_class.tag).to eq(:mountain_lion)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb
new file mode 100644
index 000000000..e3704a876
--- /dev/null
+++ b/Library/Homebrew/test/utils/popen_spec.rb
@@ -0,0 +1,28 @@
+require "utils/popen"
+
+describe Utils do
+ describe "::popen_read" do
+ it "reads the standard output of a given command" do
+ expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success")
+ expect($?).to be_a_success
+ end
+
+ it "can be given a block to manually read from the pipe" do
+ expect(
+ subject.popen_read("sh", "-c", "echo success") do |pipe|
+ pipe.read.chomp
+ end,
+ ).to eq("success")
+ expect($?).to be_a_success
+ end
+ end
+
+ describe "::popen_write" do
+ it "with supports writing to a command's standard input" do
+ subject.popen_write("grep", "-q", "success") do |pipe|
+ pipe.write("success\n")
+ end
+ expect($?).to be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb
new file mode 100644
index 000000000..c44bd8253
--- /dev/null
+++ b/Library/Homebrew/test/utils/shell_spec.rb
@@ -0,0 +1,93 @@
+require "utils/shell"
+
+describe Utils::Shell do
+ describe "::shell_profile" do
+ it "returns ~/.bash_profile by default" do
+ ENV["SHELL"] = "/bin/another_shell"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.bash_profile for Sh" do
+ ENV["SHELL"] = "/bin/another_shell"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.bash_profile for Bash" do
+ ENV["SHELL"] = "/bin/bash"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.zshrc for Zsh" do
+ ENV["SHELL"] = "/bin/zsh"
+ expect(subject.shell_profile).to eq("~/.zshrc")
+ end
+
+ it "returns ~/.kshrc for Ksh" do
+ ENV["SHELL"] = "/bin/ksh"
+ expect(subject.shell_profile).to eq("~/.kshrc")
+ end
+ end
+
+ describe "::path_to_shell" do
+ it "supports a raw command name" do
+ expect(subject.path_to_shell("bash")).to eq(:bash)
+ end
+
+ it "supports full paths" do
+ expect(subject.path_to_shell("/bin/bash")).to eq(:bash)
+ end
+
+ it "supports versions" do
+ expect(subject.path_to_shell("zsh-5.2")).to eq(:zsh)
+ end
+
+ it "strips newlines" do
+ expect(subject.path_to_shell("zsh-5.2\n")).to eq(:zsh)
+ end
+
+ it "returns nil when input is invalid" do
+ expect(subject.path_to_shell("")).to be nil
+ expect(subject.path_to_shell("@@@@@@")).to be nil
+ expect(subject.path_to_shell("invalid_shell-4.2")).to be nil
+ end
+ end
+
+ specify "::sh_quote" do
+ expect(subject.sh_quote("")).to eq("''")
+ expect(subject.sh_quote("\\")).to eq("\\\\")
+ expect(subject.sh_quote("\n")).to eq("'\n'")
+ expect(subject.sh_quote("$")).to eq("\\$")
+ expect(subject.sh_quote("word")).to eq("word")
+ end
+
+ specify "::csh_quote" do
+ expect(subject.csh_quote("")).to eq("''")
+ expect(subject.csh_quote("\\")).to eq("\\\\")
+ # note this test is different than for sh
+ expect(subject.csh_quote("\n")).to eq("'\\\n'")
+ expect(subject.csh_quote("$")).to eq("\\$")
+ expect(subject.csh_quote("word")).to eq("word")
+ end
+
+ describe "::prepend_path_in_shell_profile" do
+ let(:path) { "/my/path" }
+
+ it "supports Tcsh" do
+ ENV["SHELL"] = "/bin/tcsh"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'setenv PATH #{path}:$")
+ end
+
+ it "supports Bash" do
+ ENV["SHELL"] = "/bin/bash"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'export PATH=\"#{path}:$")
+ end
+
+ it "supports Fish" do
+ ENV["SHELL"] = "/usr/local/bin/fish"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'set -g fish_user_paths \"#{path}\" $fish_user_paths' >>")
+ end
+ end
+end