diff options
| author | Mike McQuaid | 2016-09-04 21:23:33 +0100 |
|---|---|---|
| committer | GitHub | 2016-09-04 21:23:33 +0100 |
| commit | dfcbefff73e90eda5801d9892303e10fc31831b6 (patch) | |
| tree | e20a7c5a5a28458d7729155c2b537ac63bc0aadd /Library/Homebrew/test | |
| parent | 8e98a0a198551f19696b3c09469fcbb1e1223f73 (diff) | |
| parent | dcc3377aa30b34dfcced0df77696674f91a5a9f3 (diff) | |
| download | brew-dfcbefff73e90eda5801d9892303e10fc31831b6.tar.bz2 | |
Merge pull request #201 from gregory-nisbet/feature-env-shells
--env: support more shells, allow explicit shell selection
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/test_integration_cmds.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_shell.rb | 59 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_utils.rb | 11 |
3 files changed, 85 insertions, 5 deletions
diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb index 95b1b4b5f..c83d7522a 100644 --- a/Library/Homebrew/test/test_integration_cmds.rb +++ b/Library/Homebrew/test/test_integration_cmds.rb @@ -227,6 +227,26 @@ class IntegrationCommandTests < Homebrew::TestCase cmd("--env")) end + def test_env_bash + assert_match %r{export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"}, + cmd("--env", "--shell=bash") + end + + def test_env_fish + assert_match %r{set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"}, + cmd("--env", "--shell=fish") + end + + def test_env_csh + assert_match %r{setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};}, + cmd("--env", "--shell=tcsh") + end + + def test_env_plain + assert_match %r{CMAKE_PREFIX_PATH: #{Regexp.quote(HOMEBREW_PREFIX)}}, + cmd("--env", "--plain") + end + def test_prefix_formula assert_match "#{HOMEBREW_CELLAR}/testball", cmd("--prefix", testball) diff --git a/Library/Homebrew/test/test_shell.rb b/Library/Homebrew/test/test_shell.rb new file mode 100644 index 000000000..5e054f9d9 --- /dev/null +++ b/Library/Homebrew/test/test_shell.rb @@ -0,0 +1,59 @@ +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_equal nil, Utils::Shell.path_to_shell("") + assert_equal nil, Utils::Shell.path_to_shell("@@@@@@") + assert_equal 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) + original_shell = ENV["SHELL"] + 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}" + ) + + ENV["SHELL"] = original_shell + 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/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 9fd6f65ef..fa66aefe2 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -1,6 +1,7 @@ require "testing_env" require "utils" require "tempfile" +require "utils/shell" class TtyTests < Homebrew::TestCase def test_strip_ansi @@ -157,15 +158,15 @@ class UtilTests < Homebrew::TestCase def test_shell_profile ENV["SHELL"] = "/bin/sh" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/bash" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/another_shell" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/zsh" - assert_equal "~/.zshrc", shell_profile + assert_equal "~/.zshrc", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/ksh" - assert_equal "~/.kshrc", shell_profile + assert_equal "~/.kshrc", Utils::Shell.shell_profile end def test_popen_read |
