2017-02-17 18:35:26 +01:00
|
|
|
require "utils/shell"
|
|
|
|
|
|
|
|
describe Utils::Shell do
|
2017-04-22 16:28:07 +01:00
|
|
|
describe "::profile" do
|
2017-02-17 18:35:26 +01:00
|
|
|
it "returns ~/.bash_profile by default" do
|
|
|
|
ENV["SHELL"] = "/bin/another_shell"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.profile).to eq("~/.bash_profile")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns ~/.bash_profile for Bash" do
|
|
|
|
ENV["SHELL"] = "/bin/bash"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.profile).to eq("~/.bash_profile")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns ~/.zshrc for Zsh" do
|
|
|
|
ENV["SHELL"] = "/bin/zsh"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.profile).to eq("~/.zshrc")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns ~/.kshrc for Ksh" do
|
|
|
|
ENV["SHELL"] = "/bin/ksh"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.profile).to eq("~/.kshrc")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-22 16:28:07 +01:00
|
|
|
describe "::from_path" do
|
2017-02-17 18:35:26 +01:00
|
|
|
it "supports a raw command name" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.from_path("bash")).to eq(:bash)
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports full paths" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.from_path("/bin/bash")).to eq(:bash)
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports versions" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.from_path("zsh-5.2")).to eq(:zsh)
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "strips newlines" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.from_path("zsh-5.2\n")).to eq(:zsh)
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when input is invalid" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.from_path("")).to be nil
|
|
|
|
expect(subject.from_path("@@@@@@")).to be nil
|
|
|
|
expect(subject.from_path("invalid_shell-4.2")).to be nil
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "::sh_quote" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.send(:sh_quote, "")).to eq("''")
|
|
|
|
expect(subject.send(:sh_quote, "\\")).to eq("\\\\")
|
|
|
|
expect(subject.send(:sh_quote, "\n")).to eq("'\n'")
|
|
|
|
expect(subject.send(:sh_quote, "$")).to eq("\\$")
|
|
|
|
expect(subject.send(:sh_quote, "word")).to eq("word")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "::csh_quote" do
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.send(:csh_quote, "")).to eq("''")
|
|
|
|
expect(subject.send(:csh_quote, "\\")).to eq("\\\\")
|
2017-02-17 18:35:26 +01:00
|
|
|
# note this test is different than for sh
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.send(:csh_quote, "\n")).to eq("'\\\n'")
|
|
|
|
expect(subject.send(:csh_quote, "$")).to eq("\\$")
|
|
|
|
expect(subject.send(:csh_quote, "word")).to eq("word")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
2017-04-22 16:28:07 +01:00
|
|
|
describe "::prepend_path_in_profile" do
|
2017-02-17 18:35:26 +01:00
|
|
|
let(:path) { "/my/path" }
|
|
|
|
|
|
|
|
it "supports Tcsh" do
|
|
|
|
ENV["SHELL"] = "/bin/tcsh"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.prepend_path_in_profile(path))
|
2018-05-12 11:47:12 -05:00
|
|
|
.to eq("echo 'setenv PATH #{path}:$PATH' >> #{shell_profile}")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports Bash" do
|
|
|
|
ENV["SHELL"] = "/bin/bash"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.prepend_path_in_profile(path))
|
2018-05-12 11:47:12 -05:00
|
|
|
.to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{shell_profile}")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports Fish" do
|
|
|
|
ENV["SHELL"] = "/usr/local/bin/fish"
|
2018-05-12 11:47:12 -05:00
|
|
|
ENV["fish_user_paths"] = "/some/path"
|
2017-04-22 16:28:07 +01:00
|
|
|
expect(subject.prepend_path_in_profile(path))
|
2018-05-12 11:47:12 -05:00
|
|
|
.to eq("echo 'set -g fish_user_paths \"#{path}\" $fish_user_paths' >> #{shell_profile}")
|
2017-02-17 18:35:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|