aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-17 18:35:26 +0100
committerMarkus Reiter2017-02-18 16:38:45 +0100
commitaeaf3d594c5ba417bfad582f48c79a2883f8475c (patch)
tree1bc53e96d49f20e606a948373d60f597bb56eeb1 /Library
parent61a41d0da6862b2dc3493bd246b8e3c7a6cf5640 (diff)
downloadbrew-aeaf3d594c5ba417bfad582f48c79a2883f8475c.tar.bz2
Convert Utils::Shell test to spec.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/shell_test.rb56
-rw-r--r--Library/Homebrew/test/utils/shell_spec.rb93
2 files changed, 93 insertions, 56 deletions
diff --git a/Library/Homebrew/test/shell_test.rb b/Library/Homebrew/test/shell_test.rb
deleted file mode 100644
index 970489702..000000000
--- a/Library/Homebrew/test/shell_test.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require "testing_env"
-require "utils/shell"
-
-class ShellSmokeTest < Homebrew::TestCase
- def test_path_to_shell
- # raw command name
- assert_equal :bash, Utils::Shell.path_to_shell("bash")
- # full path
- assert_equal :bash, Utils::Shell.path_to_shell("/bin/bash")
- # versions
- assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2")
- # strip newline too
- assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2\n")
- end
-
- def test_path_to_shell_failure
- assert_nil Utils::Shell.path_to_shell("")
- assert_nil Utils::Shell.path_to_shell("@@@@@@")
- assert_nil Utils::Shell.path_to_shell("invalid_shell-4.2")
- end
-
- def test_sh_quote
- assert_equal "''", Utils::Shell.sh_quote("")
- assert_equal "\\\\", Utils::Shell.sh_quote("\\")
- assert_equal "'\n'", Utils::Shell.sh_quote("\n")
- assert_equal "\\$", Utils::Shell.sh_quote("$")
- assert_equal "word", Utils::Shell.sh_quote("word")
- end
-
- def test_csh_quote
- assert_equal "''", Utils::Shell.csh_quote("")
- assert_equal "\\\\", Utils::Shell.csh_quote("\\")
- # note this test is different than for sh
- assert_equal "'\\\n'", Utils::Shell.csh_quote("\n")
- assert_equal "\\$", Utils::Shell.csh_quote("$")
- assert_equal "word", Utils::Shell.csh_quote("word")
- end
-
- def prepend_path_shell(shell, path, fragment)
- ENV["SHELL"] = shell
-
- prepend_message = Utils::Shell.prepend_path_in_shell_profile(path)
- assert(
- prepend_message.start_with?(fragment),
- "#{shell}: expected #{prepend_message} to match #{fragment}",
- )
- end
-
- def test_prepend_path_in_shell_profile
- prepend_path_shell "/bin/tcsh", "/path", "echo 'setenv PATH /path"
-
- prepend_path_shell "/bin/bash", "/path", "echo 'export PATH=\"/path"
-
- prepend_path_shell "/usr/local/bin/fish", "/path", "echo 'set -g fish_user_paths \"/path\" $fish_user_paths' >>"
- 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