Merge pull request #54 from MichaelAquilina/help_text
Show help text if virtualenv is not installed
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index b90301d50b146e18e61acbfc06877943cdfe31d9..c4a42062bb158a8d44d73aee40d5aca64b55e0b2 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -10,6 +10,18 @@ PURPLE="\e[35m"
6 BOLD="\e[1m"
7 NORMAL="\e[0m"
8 9+
10+if ! type "virtualenv" > /dev/null; then
11+ export DISABLE_AUTOSWITCH_VENV="1"
12+ printf "${BOLD}${RED}"
13+ printf "zsh-autoswitch-virtualenv requires virtualenv to be installed!\n\n"
14+ printf "${NORMAL}"
15+ printf "If this is already installed but you are still seeing this message, \n"
16+ printf "then make sure the ${BOLD}virtualenv${NORMAL} command is in your PATH.\n"
17+ printf "\n"
18+fi
19+
20+
21 function _print_python_version() {
22 # For some reason python --version writes to stderr
23 if type python > /dev/null; then
24diff --git a/tests/test_help.zunit b/tests/test_help.zunit
25new file mode 100644
26index 0000000000000000000000000000000000000000..d31bc1375c0649abf1f6281725066aceea3ed925
27--- /dev/null
28+++ b/tests/test_help.zunit
29@@ -0,0 +1,21 @@
30+#!/usr/bin/env zunit
31+
32+@test 'prints help message and disables plugin if virtualenv not setup' {
33+ # Mock type to fail
34+ function type() {
35+ if [[ "$1" == "virtualenv" ]]; then
36+ return 1
37+ fi
38+ return 0
39+ }
40+
41+ run load ../autoswitch_virtualenv.plugin.zsh
42+
43+ assert $status equals 0
44+ assert "$lines[1]" contains "zsh-autoswitch-virtualenv requires virtualenv to be installed!"
45+ assert "$lines[2]" is_empty
46+ assert "$lines[3]" contains "If this is already installed but you are still seeing this message,"
47+ assert "$lines[4]" contains "then make sure the \e[1mvirtualenv\e[0m command is in your PATH.\n"
48+ assert "$lines[5]" is_empty
49+ assert ${#lines} equals 4
50+}