summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml84
-rwxr-xr-xpowerlevel9k.zsh-theme54
-rwxr-xr-xtest/segments/anaconda.spec52
-rwxr-xr-xtest/segments/aws_eb_env.spec51
-rwxr-xr-xtest/segments/background_jobs.spec64
-rwxr-xr-xtest/segments/battery.spec184
-rwxr-xr-xtest/segments/context.spec75
-rwxr-xr-xtest/segments/custom.spec64
-rwxr-xr-xtest/segments/detect_virt.spec68
-rwxr-xr-xtest/segments/disk_usage.spec112
-rwxr-xr-xtest/segments/go_version.spec2
-rwxr-xr-xtest/segments/ip.spec202
-rwxr-xr-xtest/segments/load.spec137
-rwxr-xr-xtest/segments/node_version.spec36
-rwxr-xr-xtest/segments/nodeenv.spec81
-rwxr-xr-xtest/segments/nvm.spec62
-rwxr-xr-xtest/segments/php_version.spec36
-rwxr-xr-xtest/segments/public_ip.spec188
-rwxr-xr-xtest/segments/ram.spec62
-rwxr-xr-xtest/segments/ssh.spec70
-rwxr-xr-xtest/segments/swap.spec52
-rwxr-xr-xtest/segments/swift_version.spec52
-rwxr-xr-xtest/segments/symfony_version.spec99
-rwxr-xr-xtest/segments/todo.spec52
-rwxr-xr-xtest/segments/vcs-git.spec309
-rwxr-xr-xtest/segments/vcs-hg.spec169
-rwxr-xr-xtest/segments/vi_mode.spec38
-rwxr-xr-xtest/suite.spec17
28 files changed, 2426 insertions, 46 deletions
diff --git a/.travis.yml b/.travis.yml
index 136b661e..7c526e54 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,33 +1,77 @@
-sudo: true
-dist: trusty
language: sh
+
+os:
+ - linux
+ - osx
+
addons:
apt:
packages:
- build-essential
+ - git
+ - mercurial
+ - subversion
+ - jq
+ - node
+ - golang
+ - ruby
+ - python
+ - python-virtualenv
+
+before_install:
+ - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
+
+env:
+ global:
+ - ZSH_DIST=$HOME/.zshdist
+ matrix:
+ # Use _ZSH_VERSION since if ZSH_VERSION is present, travis cacher thinks it
+ # is running in zsh and tries to use zsh specific functions.
+ - _ZSH_VERSION=5.5.1
+ - _ZSH_VERSION=5.5
+ - _ZSH_VERSION=5.4.2
+ - _ZSH_VERSION=5.4.1
+ - _ZSH_VERSION=5.3.1
+ - _ZSH_VERSION=5.3
+ - _ZSH_VERSION=5.2
+ - _ZSH_VERSION=5.1.1
+ - _ZSH_VERSION=5.0.8
+ - _ZSH_VERSION=5.0.2
+
+cache:
+ directories:
+ - $ZSH_DIST
before_script:
+ - >
+ setup_zsh() {
+ dest="$ZSH_DIST/$1"
+ if [[ ! -d $dest/bin ]]; then
+ coreutils_mktemp="mktemp"
+ if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+ coreutils_mktemp="gmktemp"
+ fi
+ tmp="$(${coreutils_mktemp} --directory --tmpdir="${TMPDIR:/tmp}" zshbuild.XXXXXX)"
+ (
+ cd "$tmp" &&
+ curl -L http://downloads.sourceforge.net/zsh/zsh-${1}.tar.gz | tar zx &&
+ cd zsh-$1 &&
+ ./configure --prefix="$dest" &&
+ make &&
+ mkdir -p "$dest" &&
+ make install ||
+ echo "Failed to build zsh-${1}!"
+ )
+ fi
+ export PATH="$dest/bin:$PATH"
+ }
+ - setup_zsh $_ZSH_VERSION
# Show the git version being used to test.
- "git --version"
+ # Show the mercurial version being used to test.
+ - "hg --version"
# Show the zsh version being used to test.
- "zsh --version"
-install:
- - "sudo apt-get update -qq"
- - "sudo apt-get install -y zsh"
- - "sudo chsh -s $(which zsh)"
- - "sudo apt-get install -y git mercurial subversion jq node golang ruby python python-virtualenv"
-
script:
- - test/powerlevel9k.spec
- - test/functions/utilities.spec
- - test/functions/colors.spec
- - test/functions/icons.spec
- - test/segments/command_execution_time.spec
- - test/segments/dir.spec
- - test/segments/rust_version.spec
- - test/segments/go_version.spec
- - test/segments/vcs.spec
- - test/segments/kubecontext.spec
- - test/segments/laravel_version.spec
- - test/segments/status.spec
+ - test/suite.spec
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3e425c48..25e43074 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -409,12 +409,13 @@ prompt_battery() {
'charged' 'green'
'disconnected' "$DEFAULT_COLOR_INVERTED"
)
+ local ROOT_PREFIX="${4}"
# Set default values if the user did not configure them
set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
- if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then
+ if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then
# obtain battery information from system
- local raw_data="$(pmset -g batt | awk 'FNR==2{print}')"
+ local raw_data="$(${ROOT_PREFIX}/usr/bin/pmset -g batt | awk 'FNR==2{print}')"
# return if there is no battery on system
[[ -z $(echo $raw_data | grep "InternalBattery") ]] && return
@@ -446,7 +447,7 @@ prompt_battery() {
fi
if [[ "$OS" == 'Linux' ]] || [[ "$OS" == 'Android' ]]; then
- local sysp="/sys/class/power_supply"
+ local sysp="${ROOT_PREFIX}/sys/class/power_supply"
# Reported BAT0 or BAT1 depending on kernel version
[[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0
@@ -468,8 +469,8 @@ prompt_battery() {
[[ $bat_percent =~ 100 ]] && current_state="charged"
[[ $bat_percent -lt 100 ]] && current_state="charging"
fi
- if [[ -f /usr/bin/acpi ]]; then
- local time_remaining=$(acpi | awk '{ print $5 }')
+ if [[ -f ${ROOT_PREFIX}/usr/bin/acpi ]]; then
+ local time_remaining=$(${ROOT_PREFIX}/usr/bin/acpi | awk '{ print $5 }')
if [[ $time_remaining =~ rate ]]; then
local tstring="..."
elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then
@@ -702,11 +703,13 @@ prompt_host() {
# The 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment.
prompt_custom() {
- local command=POWERLEVEL9K_CUSTOM_$3:u
+ local segment_name="${3:u}"
+ # Get content of custom segment
+ local command="POWERLEVEL9K_CUSTOM_${segment_name}"
local segment_content="$(eval ${(P)command})"
if [[ -n $segment_content ]]; then
- "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content"
+ "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content" "CUSTOM_${segment_name}_ICON"
fi
}
@@ -1043,18 +1046,14 @@ prompt_history() {
################################################################
# Detection for virtualization (systemd based systems only)
prompt_detect_virt() {
- if ! command -v systemd-detect-virt > /dev/null; then
- return
- fi
- local virt=$(systemd-detect-virt)
+ local virt=$(systemd-detect-virt 2> /dev/null)
if [[ "$virt" == "none" ]]; then
if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then
virt="chroot"
- "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
- else
- ;
fi
- else
+ fi
+
+ if [[ -n "${virt}" ]]; then
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "$virt"
fi
}
@@ -1089,18 +1088,20 @@ prompt_ip() {
else
if defined POWERLEVEL9K_IP_INTERFACE; then
# Get the IP address of the specified interface.
- ip=$(ip -4 a show "$POWERLEVEL9K_IP_INTERFACE" | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*")
+ ip=$(ip -4 a show "$POWERLEVEL9K_IP_INTERFACE" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+")
else
local interfaces callback
# Get all network interface names that are up
- interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o "[a-z0-9]*")
- callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o "[0-9.]*"'
+ interfaces=$(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+")
+ callback='ip -4 a show $item | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+"'
ip=$(getRelevantItem "$interfaces" "$callback")
fi
fi
- "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON'
+ if [[ -n "$ip" ]]; then
+ "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON'
+ fi
}
################################################################
@@ -1131,6 +1132,7 @@ prompt_laravel_version() {
# Segment to display load
set_default POWERLEVEL9K_LOAD_WHICH 5
prompt_load() {
+ local ROOT_PREFIX="${4}"
# The load segment can have three different states
local current_state="unknown"
local load_select=2
@@ -1166,7 +1168,7 @@ prompt_load() {
fi
;;
*)
- load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
+ load_avg=$(cut -d" " -f${load_select} ${ROOT_PREFIX}/proc/loadavg)
cores=$(nproc)
esac
@@ -1239,6 +1241,7 @@ prompt_php_version() {
################################################################
# Segment to display free RAM and used Swap
prompt_ram() {
+ local ROOT_PREFIX="${4}"
local base=''
local ramfree=0
if [[ "$OS" == "OSX" ]]; then
@@ -1250,9 +1253,9 @@ prompt_ram() {
ramfree=$(( ramfree * 4096 ))
else
if [[ "$OS" == "BSD" ]]; then
- ramfree=$(grep 'avail memory' /var/run/dmesg.boot | awk '{print $4}')
+ ramfree=$(grep 'avail memory' ${ROOT_PREFIX}/var/run/dmesg.boot | awk '{print $4}')
else
- ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
base='K'
fi
fi
@@ -1417,6 +1420,7 @@ prompt_status() {
################################################################
# Segment to display Swap information
prompt_swap() {
+ local ROOT_PREFIX="${4}"
local swap_used=0
local base=''
@@ -1431,8 +1435,8 @@ prompt_swap() {
base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$")
else
- swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
- swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
+ swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" ${ROOT_PREFIX}/proc/meminfo | grep -o -E "[0-9]+")
swap_used=$(( swap_total - swap_free ))
base='K'
fi
@@ -1605,7 +1609,7 @@ set_default POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
prompt_vi_mode() {
case ${KEYMAP} in
vicmd)
- "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "default" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
+ "$1_prompt_segment" "$0_NORMAL" "$2" "$DEFAULT_COLOR" "white" "$POWERLEVEL9K_VI_COMMAND_MODE_STRING"
;;
main|viins|*)
if [[ -z $POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then return; fi
diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec
new file mode 100755
index 00000000..11add849
--- /dev/null
+++ b/test/segments/anaconda.spec
@@ -0,0 +1,52 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world)
+ # Unset anacona variables
+ unset CONDA_ENV_PATH
+ unset CONDA_PREFIX
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() {
+ CONDA_ENV_PATH=/tmp
+ unset CONDA_PREFIX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(tmp) %k%F{blue}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() {
+ unset CONDA_ENV_PATH
+ local CONDA_PREFIX="test"
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(test) %k%F{blue}%f " "$(build_left_prompt)"
+}
+
+function testAnacondaSegmentWorks() {
+ local CONDA_ENV_PATH=/tmp
+ local CONDA_PREFIX="test"
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
+ local POWERLEVEL9K_PYTHON_ICON="icon-here"
+
+ assertEquals "%K{blue} %F{black%}icon-here %f%F{black}(tmptest) %k%F{blue}%f " "$(build_left_prompt)"
+
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec
new file mode 100755
index 00000000..530da6a1
--- /dev/null
+++ b/test/segments/aws_eb_env.spec
@@ -0,0 +1,51 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testAwsEbEnvSegmentPrintsNothingIfNoElasticBeanstalkEnvironmentIsSet() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env custom_world)
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() {
+ mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk
+ echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
+ cd /tmp/powerlevel9k-test
+
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env)
+
+ assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)"
+
+ rm -fr /tmp/powerlevel9k-test
+ cd -
+}
+
+function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirectory() {
+ # Skip test, because currently we cannot detect
+ # if the configuration is in a parent directory
+ startSkipping # Skip test
+ mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk
+ mkdir -p /tmp/powerlevel9k-test/1/12/123/1234/12345
+ echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml
+ cd /tmp/powerlevel9k-test/1/12/123/1234/12345
+
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env)
+
+ assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)"
+
+ rm -fr /tmp/powerlevel9k-test
+ cd -
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec
new file mode 100755
index 00000000..9f866ff0
--- /dev/null
+++ b/test/segments/background_jobs.spec
@@ -0,0 +1,64 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() {
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs custom_world)
+ alias jobs="nojobs 2>/dev/null"
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias jobs
+}
+
+function testBackgroundJobsSegmentWorksWithOneBackgroundJob() {
+ unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo '[1] + 30444 suspended nvim xx'
+ }
+
+ assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() {
+ unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo "[1] 31190 suspended nvim xx"
+ echo "[2] - 31194 suspended nvim xx2"
+ echo "[3] + 31206 suspended nvim xx3"
+ }
+
+ assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+function testBackgroundJobsSegmentWithVerboseMode() {
+ local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=true
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs)
+ jobs() {
+ echo "[1] 31190 suspended nvim xx"
+ echo "[2] - 31194 suspended nvim xx2"
+ echo "[3] + 31206 suspended nvim xx3"
+ }
+
+ assertEquals "%K{black} %F{cyan%}⚙ %f%F{cyan}3 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction jobs
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/battery.spec b/test/segments/battery.spec
new file mode 100755
index 00000000..808ecc6a
--- /dev/null
+++ b/test/segments/battery.spec
@@ -0,0 +1,184 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ # Prepare folder for pmset (OSX)
+ PMSET_PATH=$FOLDER/usr/bin
+ mkdir -p $PMSET_PATH
+ # Prepare folder for $BATTERY (Linux)
+ BATTERY_PATH=$FOLDER/sys/class/power_supply
+ mkdir -p $BATTERY_PATH
+ mkdir -p $BATTERY_PATH/BAT0
+ mkdir -p $BATTERY_PATH/BAT1
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}" &>/dev/null
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test &>/dev/null
+ unset PMSET_PATH
+ unset BATTERY_PATH
+ unset FOLDER
+}
+
+# Mock Battery
+# For mocking pmset on OSX this function takes one argument (the
+# content that pmset should echo).
+# For mocking the battery on Linux this function takes two
+# arguments: $1 is the capacity; $2 the battery status.
+function makeBatterySay() {
+ if [[ -z "${FOLDER}" ]]; then
+ echo "Fake root path is not correctly set!"
+ exit 1
+ fi
+ # OSX
+ echo "#!/bin/sh" > $PMSET_PATH/pmset
+ echo "echo \"$1\"" >> $PMSET_PATH/pmset
+ chmod +x $PMSET_PATH/pmset
+
+ # Linux
+ local capacity="$1"
+ echo "$capacity" > $BATTERY_PATH/BAT0/capacity
+ echo "$capacity" > $BATTERY_PATH/BAT1/capacity
+ local battery_status="$2"
+ echo "$battery_status" > $BATTERY_PATH/BAT0/status
+ echo "$battery_status" > $BATTERY_PATH/BAT1/status
+}
+
+function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true"
+
+ assertEquals "%K{black} %F{red%}🔋 %f%F{red}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() {
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsFullOnOSX() {
+ local OS='OSX' # Fake OSX
+ makeBatterySay "Now drawing from 'AC Power'
+ -InternalBattery-0 (id=1234567) 99%; charged; 0:00 remaining present: true"
+
+ assertEquals "%K{black} %F{green%}🔋 %f%F{green}99%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsCalculatingOnOSX() {
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "Now drawing from 'Battery Power'
+ -InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "4" "Discharging"
+
+ assertEquals "%K{black} %F{red%}🔋 %f%F{red}4%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "4" "Charging"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}4%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "10" "Discharging"
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}10%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "10" "Charging"
+
+ assertEquals "%K{black} %F{yellow%}🔋 %f%F{yellow}10%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsFullOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "100" "Full"
+
+ assertEquals "%K{black} %F{green%}🔋 %f%F{green}100%% " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "50" "Discharging"
+ echo "echo 'Batter 0: Discharging, 50%, 01:38:54 remaining'" > ${FOLDER}/usr/bin/acpi
+ chmod +x ${FOLDER}/usr/bin/acpi
+ # For running on Mac, we need to mock date :(
+ [[ -f /usr/local/bin/gdate ]] && alias date=gdate
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})"
+
+ unalias date &>/dev/null
+}
+
+function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() {
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery)
+ makeBatterySay "50" "Discharging"
+ # Todo: Include real acpi output!
+ echo "echo 'Batter 0: Discharging, 50%, rate remaining'" > ${FOLDER}/usr/bin/acpi
+ chmod +x ${FOLDER}/usr/bin/acpi
+
+ assertEquals "%K{black} %F{white%}🔋 %f%F{white}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/context.spec b/test/segments/context.spec
new file mode 100755
index 00000000..e86bc357
--- /dev/null
+++ b/test/segments/context.spec
@@ -0,0 +1,75 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Test specific settings
+ OLD_DEFAULT_USER=$DEFAULT_USER
+ unset DEFAULT_USER
+}
+
+function tearDown() {
+ # Restore old variables
+ [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER
+}
+
+function testContextSegmentDoesNotGetRenderedWithDefaultUser() {
+ local DEFAULT_USER=$(whoami)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context custom_world)
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() {
+ local SSH_CLIENT="putty"
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentWithForeignUser() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+# TODO: How to test root?
+function testContextSegmentWithRootUser() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ startSkipping # Skip test
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testOverridingContextTemplate() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_CONTEXT_TEMPLATE=xx
+
+ assertEquals "%K{black} %F{yellow}xx %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true
+ local DEFAULT_USER=$(whoami)
+
+ assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)"
+}
+
+function testContextSegmentIsShownIfForced() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
+ local POWERLEVEL9K_ALWAYS_SHOW_USER=true
+ local DEFAULT_USER=$(whoami)
+
+ assertEquals "%K{black} %F{yellow}$(whoami) %k%F{black}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/custom.spec b/test/segments/custom.spec
new file mode 100755
index 00000000..dea1577f
--- /dev/null
+++ b/test/segments/custom.spec
@@ -0,0 +1,64 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testCustomDirectOutputSegment() {
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testCustomClosureSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ function p9k_hello_world() {
+ echo "world"
+ }
+ local POWERLEVEL9K_CUSTOM_WORLD='p9k_hello_world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingBackgroundForCustomSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND="yellow"
+
+ assertEquals "%K{yellow} %F{black}world %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testSettingForegroundForCustomSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND="red"
+
+ assertEquals "%K{white} %F{red}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingVisualIdentifierForCustomSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw"
+
+ assertEquals "%K{white} %F{black%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSettingVisualIdentifierForegroundColorForCustomSegment() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD="echo world"
+ local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw"
+ local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR="red"
+
+ assertEquals "%K{white} %F{red%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec
new file mode 100755
index 00000000..efda6f43
--- /dev/null
+++ b/test/segments/detect_virt.spec
@@ -0,0 +1,68 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() {
+ alias systemd-detect-virt="novirt"
+
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfSystemdReturnsPlainName() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ alias systemd-detect-virt="echo 'xxx'"
+
+ assertEquals "%K{black} %F{yellow}xxx %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfRootFsIsOnExpectedInode() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ # Well. This is a weak test, as it fixates the implementation,
+ # but it is necessary, as the implementation relys on the root
+ # directory having the inode number "2"..
+ alias systemd-detect-virt="echo 'none'"
+
+ # The original command in the implementation is "ls -di / | grep -o 2",
+ # which translates to: Show the inode number of "/" and test if it is "2".
+ alias ls="echo '2'"
+
+ assertEquals "%K{black} %F{yellow}none %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias ls
+ unalias systemd-detect-virt
+}
+
+function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt)
+ # Well. This is a weak test, as it fixates the implementation,
+ # but it is necessary, as the implementation relys on the root
+ # directory having the inode number "2"..
+ alias systemd-detect-virt="echo 'none'"
+
+ # The original command in the implementation is "ls -di / | grep -o 2",
+ # which translates to: Show the inode number of "/" and test if it is "2".
+ alias ls="echo '3'"
+
+ assertEquals "%K{black} %F{yellow}chroot %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias ls
+ unalias systemd-detect-virt
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec
new file mode 100755
index 00000000..574445d9
--- /dev/null
+++ b/test/segments/disk_usage.spec
@@ -0,0 +1,112 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Test specific
+ P9K_HOME=$(pwd)
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p $FOLDER
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+ unset P9K_HOME
+
+ # Remove IP cache file
+ rm -f ${POWERLEVEL9K_PUBLIC_IP_FILE}
+}
+
+function testDiskUsageSegmentWhenDiskIsAlmostFull() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 97% /"
+ }
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+
+ assertEquals "%K{red} %F{white%}hdd %f%F{white}97%% %k%F{red}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWhenDiskIsVeryFull() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 94% /"
+ }
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+
+ assertEquals "%K{yellow} %F{black%}hdd %f%F{black}94%% %k%F{yellow}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWhenDiskIsQuiteEmpty() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 4% /"
+ }
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+
+ assertEquals "%K{black} %F{yellow%}hdd %f%F{yellow}4%% %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShouldBeDisplayed() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 4% /"
+ }
+
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage custom_world)
+ local POWERLEVEL9K_DISK_USAGE_ONLY_WARNING=true
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentWarningLevelCouldBeAdjusted() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 11% /"
+ }
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=10
+
+ assertEquals "%K{yellow} %F{black%}hdd %f%F{black}11%% %k%F{yellow}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() {
+ df() {
+ echo "Filesystem 1K-blocks Used Available Use% Mounted on
+/dev/disk1 487219288 471466944 15496344 11% /"
+ }
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage)
+ local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=5
+ local POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL=10
+
+ assertEquals "%K{red} %F{white%}hdd %f%F{white}11%% %k%F{red}%f " "$(build_left_prompt)"
+
+ unfunction df
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec
index 9104ac8b..3ff0b0e6 100755
--- a/test/segments/go_version.spec
+++ b/test/segments/go_version.spec
@@ -40,7 +40,7 @@ function testGo() {
PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
- assertEquals "%K{green} %F{grey93%} %f%F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
+ assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_GO_ICON
unset PWD
diff --git a/test/segments/ip.spec b/test/segments/ip.spec
new file mode 100755
index 00000000..3ae2d389
--- /dev/null
+++ b/test/segments/ip.spec
@@ -0,0 +1,202 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testIpSegmentPrintsNothingOnOsxIfNotConnected() {
+ alias networksetup='echo "not connected"'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
+ local OS="OSX" # Fake OSX
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias networksetup
+}
+
+function testIpSegmentPrintsNothingOnLinuxIfNotConnected() {
+ alias ip='echo "not connected"'
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world)
+ local OS="Linux" # Fake Linux
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias ip
+}
+
+function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='OSX' # Fake OSX
+ alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled.
+(1) Ethernet
+(Hardware Port: Ethernet, Device: en0)
+
+(2) FireWire
+(Hardware Port: FireWire, Device: fw0)
+
+(3) Wi-Fi
+(Hardware Port: Wi-Fi, Device: en1)
+
+(4) Bluetooth PAN
+(Hardware Port: Bluetooth PAN, Device: en3)
+
+(5) Thunderbolt Bridge
+(Hardware Port: Thunderbolt Bridge, Device: bridge0)
+
+(6) Apple USB Ethernet Adapter
+(Hardware Port: Apple USB Ethernet Adapter, Device: en4)
+'"
+
+ alias ipconfig="_(){ echo '1.2.3.4'; };_"
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unalias ipconfig
+ unalias networksetup
+}
+
+# There could be more than one confiured network interfaces.
+# `networksetup -listnetworkserviceorder` lists the interfaces
+# in hierarchical order, but from outside this is not obvious
+# (implementation detail). So we need a test for this case.
+function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='OSX' # Fake OSX
+ alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled.
+(1) Ethernet
+(Hardware Port: Ethernet, Device: en0)
+
+(2) FireWire
+(Hardware Port: FireWire, Device: fw0)
+
+(3) Wi-Fi
+(Hardware Port: Wi-Fi, Device: en1)
+
+(4) Bluetooth PAN
+(Hardware Port: Bluetooth PAN, Device: en3)
+
+(5) Thunderbolt Bridge
+(Hardware Port: Thunderbolt Bridge, Device: bridge0)
+
+(6) Apple USB Ethernet Adapter
+(Hardware Port: Apple USB Ethernet Adapter, Device: en4)
+'"
+
+ # Return a unique IP address for every interface
+ ipconfig() {
+ case "${2}" {
+ en0)
+ echo 1.2.3.4
+ ;;
+ fw0)
+ echo 2.3.4.5
+ ;;
+ en1)
+ echo 3.4.5.6
+ ;;
+ en3)
+ echo 4.5.6.7
+ ;;
+ }
+ }
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ipconfig
+ unalias networksetup
+}
+
+function testIpSegmentWorksOnOsxWithInterfaceSpecified() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='OSX' # Fake OSX
+ local POWERLEVEL9K_IP_INTERFACE='xxx'
+ alias ipconfig="_(){ echo '1.2.3.4'; };_"
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unalias ipconfig
+}
+
+function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() {
+ setopt aliases
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='Linux' # Fake Linux
+ # That command is harder to test, as it is used at first
+ # to get all relevant network interfaces and then for
+ # getting the configuration of that segment..
+ ip(){
+ if [[ "$*" == 'link ls up' ]]; then
+ echo "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
+2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff";
+ fi
+
+ if [[ "$*" == '-4 a show eth0' ]]; then
+ echo '2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
+ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
+ valid_lft forever preferred_lft forever';
+ fi
+ }
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() {
+ setopt aliases
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='Linux' # Fake Linux
+ # That command is harder to test, as it is used at first
+ # to get all relevant network interfaces and then for
+ # getting the configuration of that segment..
+ ip(){
+ if [[ "$*" == 'link ls up' ]]; then
+ echo "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
+2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
+3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff
+4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff";
+ fi
+
+ if [[ "$*" == '-4 a show eth1' ]]; then
+ echo '3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
+ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
+ valid_lft forever preferred_lft forever';
+ fi
+ }
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+function testIpSegmentWorksOnLinuxWithInterfaceSpecified() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip)
+ local OS='Linux' # Fake Linux
+ local POWERLEVEL9K_IP_INTERFACE='xxx'
+ ip(){
+ echo '2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
+inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
+ valid_lft forever preferred_lft forever';
+ }
+
+ assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)"
+
+ unfunction ip
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/load.spec b/test/segments/load.spec
new file mode 100755
index 00000000..45e28db3
--- /dev/null
+++ b/test/segments/load.spec
@@ -0,0 +1,137 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/load-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testLoadSegmentWorksOnOsx() {
+ sysctl() {
+ if [[ "$*" == 'vm.loadavg' ]]; then
+ echo "vm.loadavg: { 1,38 1,45 2,16 }";
+ fi
+
+ if [[ "$*" == '-n hw.logicalcpu' ]]; then
+ echo "4";
+ fi
+ }
+
+ local OS="OSX" # Fake OSX
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testLoadSegmentWorksOnBsd() {
+ sysctl() {
+ if [[ "$*" == 'vm.loadavg' ]]; then
+ echo "vm.loadavg: { 1,38 1,45 2,16 }";
+ fi
+
+ if [[ "$*" == '-n hw.ncpu' ]]; then
+ echo "4";
+ fi
+ }
+
+ local OS="BSD" # Fake BSD
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testLoadSegmentWorksOnLinux() {
+ # Prepare loadavg
+ mkdir proc
+ echo "1.38 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+
+ local OS="Linux" # Fake Linux
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test normal state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentNormalState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "1.00 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+
+ local OS="Linux" # Fake Linux
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{green} %F{black%}L %f%F{black}1.00 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test warning state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentWarningState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "2.01 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+
+ local OS="Linux" # Fake Linux
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{yellow} %F{black%}L %f%F{black}2.01 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+# Test critical state. This test is not OS specific.
+# We test it as the Linux version, but that
+# does not matter here.
+function testLoadSegmentCriticalState() {
+ # Prepare loadavg
+ mkdir proc
+ echo "2.81 0.01 0.05 1/87 8641" > proc/loadavg
+
+ alias nproc="echo 4"
+
+ local OS="Linux" # Fake Linux
+ local POWERLEVEL9K_LOAD_WHICH=1
+
+ assertEquals "%K{red} %F{black%}L %f%F{black}2.81 " "$(prompt_load left 1 false ${FOLDER})"
+
+ unalias nproc
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec
new file mode 100755
index 00000000..2fe3594e
--- /dev/null
+++ b/test/segments/node_version.spec
@@ -0,0 +1,36 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testNodeVersionSegmentPrintsNothingWithoutNode() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias node="nonode 2>/dev/null"
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_CUSTOM_WORLD
+ unalias node
+}
+
+function testNodeVersionSegmentWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version)
+ node() {
+ echo "v1.2.3"
+ }
+
+ assertEquals "%K{green} %F{white%}⬢ %f%F{white}1.2.3 %k%F{green}%f " "$(build_left_prompt)"
+
+ unfunction node
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec
new file mode 100755
index 00000000..bfa1d7fa
--- /dev/null
+++ b/test/segments/nodeenv.spec
@@ -0,0 +1,81 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Test specfic
+ # unset all possible user specified variables
+ unset NODE_VIRTUAL_ENV_DISABLE_PROMPT
+ unset NODE_VIRTUAL_ENV
+}
+
+function testNodeenvSegmentPrintsNothingWithoutNode() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias node="nonode 2>/dev/null"
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias node
+}
+
+function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ node() {
+ echo "v1.2.3"
+ }
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction node
+}
+
+function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ node() {
+ echo "v1.2.3"
+ }
+ NODE_VIRTUAL_ENV="node-env"
+ NODE_VIRTUAL_ENV_DISABLE_PROMPT=true
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unset NODE_VIRTUAL_ENV_DISABLE_PROMPT
+ unset NODE_VIRTUAL_ENV
+ unfunction node
+}
+
+function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv)
+ alias node="nonode 2>/dev/null"
+ NODE_VIRTUAL_ENV="node-env"
+
+ assertEquals "%K{black} %F{green%}⬢ %f%F{green}[node-env] %k%F{black}%f " "$(build_left_prompt)"
+
+ unset NODE_VIRTUAL_ENV
+ unalias node
+}
+
+function testNodeenvSegmentWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv)
+ node() {
+ echo "v1.2.3"
+ }
+ NODE_VIRTUAL_ENV="node-env"
+
+ assertEquals "%K{black} %F{green%}⬢ %f%F{green}v1.2.3[node-env] %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction node
+ unset NODE_VIRTUAL_ENV
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec
new file mode 100755
index 00000000..8f3b3c26
--- /dev/null
+++ b/test/segments/nvm.spec
@@ -0,0 +1,62 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/nvm-test
+ mkdir -p "${FOLDER}/bin"
+ OLD_PATH=$PATH
+ PATH=${FOLDER}/bin:$PATH
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Restore old path
+ PATH="${OLD_PATH}"
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testNvmSegmentWorksWithoutHavingADefaultAlias() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm)
+
+ function nvm_version() {
+ [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0'
+ }
+
+ assertEquals "%K{magenta} %F{black%}⬢ %f%F{black}4.6.0 %k%F{magenta}%f " "$(build_left_prompt)"
+}
+
+function testNvmSegmentPrintsNothingWhenOnDefaultVersion() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ function nvm_version() {
+ [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v4.6.0'
+ }
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec
new file mode 100755
index 00000000..ccf157c9
--- /dev/null
+++ b/test/segments/php_version.spec
@@ -0,0 +1,36 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias php="nophp"
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+function testPhpVersionSegmentWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version)
+ alias php="echo 'PHP 5.6.27 (cli) (built: Oct 23 2016 11:47:58)
+Copyright (c) 1997-2016 The PHP Group
+Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
+'"
+
+ assertEquals "%K{013} %F{255}PHP 5.6.27 %k%F{fuchsia}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec
new file mode 100755
index 00000000..a9c0a770
--- /dev/null
+++ b/test/segments/public_ip.spec
@@ -0,0 +1,188 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ # Test specific
+ P9K_HOME=$(pwd)
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ # Change cache file, so that the users environment don't
+ # interfere with the tests.
+ POWERLEVEL9K_PUBLIC_IP_FILE=$FOLDER/public_ip_file
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+ unset P9K_HOME
+
+ # Unset cache file
+ unset POWERLEVEL9K_PUBLIC_IP_FILE
+}
+
+function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip custom_world)
+ local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz'
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ # We need to overwrite dig, as this is a fallback method that
+ # uses an alternative host.
+ alias dig='nodig'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias dig
+}
+
+function testPublicIpSegmentPrintsNoticeIfNotConnected() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_HOST='http://unknown.xyz'
+ local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected"
+ # We need to overwrite dig, as this is a fallback method that
+ # uses an alternative host.
+ alias dig='nodig'
+
+ assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias dig
+}
+
+function testPublicIpSegmentWorksWithWget() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias dig='nodig'
+ alias curl='nocurl'
+ wget() {
+ echo "wget 1.2.3.4"
+ }
+
+ assertEquals "%K{black} %F{white}wget 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction wget
+ unalias dig
+ unalias curl
+}
+
+function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias dig='nodig'
+ alias wget='nowget'
+ curl() {
+ echo "curl 1.2.3.4"
+ }
+
+ assertEquals "%K{black} %F{white}curl 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction curl
+ unalias dig
+ unalias wget
+}
+
+function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ alias curl='nocurl'
+ alias wget='nowget'
+ dig() {
+ echo "dig 1.2.3.4"
+ }
+
+ assertEquals "%K{black} %F{white}dig 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+ unalias curl
+ unalias wget
+}
+
+function testPublicIpSegmentCachesFile() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ dig() {
+ echo "first"
+ }
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentRefreshesCachesFileAfterTimeout() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_TIMEOUT=2
+ dig() {
+ echo "first"
+ }
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ sleep 3
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentRefreshesCachesFileIfEmpty() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ dig() {
+ echo "first"
+ }
+
+ assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)"
+
+ # Truncate cache file
+ echo "" >! $POWERLEVEL9K_PUBLIC_IP_FILE
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+function testPublicIpSegmentWhenGoingOnline() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip)
+ local POWERLEVEL9K_PUBLIC_IP_METHODS="dig"
+ local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected"
+ alias dig="nodig"
+
+ assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)"
+
+ unalias dig
+
+ dig() {
+ echo "second"
+ }
+
+ # Segment should not have changed!
+ assertEquals "%K{black} %F{white}second %k%F{black}%f " "$(build_left_prompt)"
+
+ unfunction dig
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/ram.spec b/test/segments/ram.spec
new file mode 100755
index 00000000..104b8c82
--- /dev/null
+++ b/test/segments/ram.spec
@@ -0,0 +1,62 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/ram-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testRamSegmentWorksOnOsx() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ram)
+ local OS="OSX" # Fake OSX
+ alias vm_stat="echo 'Mach Virtual Memory Statistics: (page size of 4096 bytes)
+Pages free: 299687.
+Pages active: 1623792.
+Pages inactive: 1313411.
+'"
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}6.15G " "$(prompt_ram left 1 false ${FOLDER})"
+
+ unalias vm_stat
+}
+
+function testRamSegmentWorksOnBsd() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ram)
+ local OS="BSD" # Fake BSD
+ mkdir -p var/run
+ echo "avail memory 5678B 299687 4444G 299" > var/run/dmesg.boot
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29M " "$(prompt_ram left 1 false ${FOLDER})"
+}
+
+function testRamSegmentWorksOnLinux() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ram)
+ local OS="Linux" # Fake Linux
+ mkdir proc
+ echo "MemAvailable: 299687" > proc/meminfo
+
+ assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29G " "$(prompt_ram left 1 false ${FOLDER})"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec
new file mode 100755
index 00000000..2ad4341e
--- /dev/null
+++ b/test/segments/ssh.spec
@@ -0,0 +1,70 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function mockRust() {
+ echo 'rustc 0.4.1a-alpha'
+}
+
+function testSshSegmentPrintsNothingIfNoSshConnection() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo "world"'
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ unset SSH_CLIENT
+ unset SSH_TTY
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSshSegmentWorksIfOnlySshClientIsSet() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_CLIENT='ssh-client'
+ unset SSH_TTY
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_CLIENT
+}
+
+function testSshSegmentWorksIfOnlySshTtyIsSet() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_TTY='ssh-tty'
+ unset SSH_CLIENT
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_TTY
+}
+
+function testSshSegmentWorksIfAllNecessaryVariablesAreSet() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh)
+ local POWERLEVEL9K_SSH_ICON="ssh-icon"
+ # Weak test: Emulate No SSH connection by unsetting
+ # $SSH_CLIENT and $SSH_TTY
+ SSH_CLIENT='ssh-client'
+ SSH_TTY='ssh-tty'
+
+ assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)"
+
+ unset SSH_TTY
+ unset SSH_CLIENT
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/swap.spec b/test/segments/swap.spec
new file mode 100755
index 00000000..52719395
--- /dev/null
+++ b/test/segments/swap.spec
@@ -0,0 +1,52 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/swap-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSwapSegmentWorksOnOsx() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap)
+ local OS="OSX" # Fake OSX
+ sysctl() {
+ echo "vm.swapusage: total = 3072,00M used = 1620,50M free = 1451,50M (encrypted)"
+ }
+
+ assertEquals "%K{yellow} %F{black%}SWP %f%F{black}1.58G " "$(prompt_swap left 1 false ${FOLDER})"
+
+ unfunction sysctl
+}
+
+function testSwapSegmentWorksOnLinux() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap)
+ local OS="Linux" # Fake Linux
+ mkdir proc
+ echo "SwapTotal: 1000000" > proc/meminfo
+ echo "SwapFree: 1000" >> proc/meminfo
+
+ assertEquals "%K{yellow} %F{black%}SWP %f%F{black}0.95G " "$(prompt_swap left 1 false ${FOLDER})"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec
new file mode 100755
index 00000000..e58cc817
--- /dev/null
+++ b/test/segments/swift_version.spec
@@ -0,0 +1,52 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias swift="noswift"
+
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias swift
+}
+
+function testSwiftSegmentWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version)
+ function swift() {
+ echo "Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)\nTarget: x86_64-apple-macosx10.9"
+ }
+
+ assertEquals "%K{magenta} %F{white%}Swift %f%F{white}3.0.1 %k%F{magenta}%f " "$(build_left_prompt)"
+
+ unfunction swift
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec
new file mode 100755
index 00000000..ba0bf96a
--- /dev/null
+++ b/test/segments/symfony_version.spec
@@ -0,0 +1,99 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ alias php="nophp"
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unalias php
+}
+
+function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ # "Symfony" is not a command, but rather a framework.
+ # To sucessfully execute this test, we just need to
+ # navigate into a folder that does not contain symfony.
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ mkdir app
+ touch app/AppKernel.php
+ function php() {
+ echo "Warning: Unsupported declare strict_types in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 19
+
+ Parse error: parse error, expecting `;´ or `{´ in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 97"
+ }
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+function testSymfonyVersionSegmentWorks() {
+ startSkipping # Skip test
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version)
+ mkdir app
+ touch app/AppKernel.php
+
+ function php() {
+ echo "Symfony version 3.1.4 - app/dev/debug"
+ }
+
+ assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+function testSymfonyVersionSegmentWorksInNestedFolder() {
+ startSkipping # Skip test
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version)
+ mkdir app
+ touch app/AppKernel.php
+
+ function php() {
+ echo "Symfony version 3.1.4 - app/dev/debug"
+ }
+
+ mkdir -p src/P9K/AppBundle
+ cd src/P9K/AppBundle
+
+ assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)"
+
+ unfunction php
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/todo.spec b/test/segments/todo.spec
new file mode 100755
index 00000000..0d2d8203
--- /dev/null
+++ b/test/segments/todo.spec
@@ -0,0 +1,52 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test
+ mkdir -p "${FOLDER}"
+ mkdir ${FOLDER}/bin
+ OLD_PATH=$PATH
+ PATH=${FOLDER}/bin:$PATH
+ cd $FOLDER
+}
+
+function tearDown() {
+ # Reset PATH
+ PATH=$OLD_PATH
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+}
+
+function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo custom_world)
+ local POWERLEVEL9K_CUSTOM_WORLD='echo world'
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testTodoSegmentWorksAsExpected() {
+ # TODO: Skript in den PATH legen!
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo)
+ echo '#!/bin/sh' > ${FOLDER}/bin/todo.sh
+ echo 'echo "TODO: 34 of 100 tasks shown";' >> ${FOLDER}/bin/todo.sh
+ chmod +x ${FOLDER}/bin/todo.sh
+
+ assertEquals "%K{244} %F{black%}☑ %f%F{black}100 %k%F{grey50}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec
new file mode 100755
index 00000000..9429589d
--- /dev/null
+++ b/test/segments/vcs-git.spec
@@ -0,0 +1,309 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and git init it.
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ # Set username and email
+ OLD_GIT_AUTHOR_NAME=$GIT_AUTHOR_NAME
+ GIT_AUTHOR_NAME="Testing Tester"
+ OLD_GIT_AUTHOR_EMAIL=$GIT_AUTHOR_EMAIL
+ GIT_AUTHOR_EMAIL="test@powerlevel9k.theme"
+
+ # Set default username if not already set!
+ if [[ -z $(git config user.name) ]]; then
+ GIT_AUTHOR_NAME_SET_BY_TEST=true
+ git config --global user.name "${GIT_AUTHOR_NAME}"
+ fi
+ # Set default email if not already set!
+ if [[ -z $(git config user.email) ]]; then
+ GIT_AUTHOR_EMAIL_SET_BY_TEST=true
+ git config --global user.email "${GIT_AUTHOR_EMAIL}"
+ fi
+
+ # Initialize FOLDER as git repository
+ git init 1>/dev/null
+}
+
+function tearDown() {
+ if [[ -n "${OLD_GIT_AUTHOR_NAME}" ]]; then
+ GIT_AUTHOR_NAME=$OLD_GIT_AUTHOR
+ unset OLD_GIT_AUTHOR_NAME
+ else
+ unset GIT_AUTHOR_NAME
+ fi
+
+ if [[ -n "${OLD_GIT_AUTHOR_EMAIL}" ]]; then
+ GIT_AUTHOR_EMAIL=$OLD_GIT_AUTHOR_EMAIL
+ unset OLD_GIT_AUTHOR_EMAIL
+ else
+ unset GIT_AUTHOR_EMAIL
+ fi
+
+ if [[ "${GIT_AUTHOR_NAME_SET_BY_TEST}" == "true" ]]; then
+ git config --global --unset user.name
+ fi
+ if [[ "${GIT_AUTHOR_EMAIL_SET_BY_TEST}" == "true" ]]; then
+ git config --global --unset user.email
+ fi
+
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}"
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test
+ unset FOLDER
+}
+
+function testColorOverridingForCleanStateWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
+
+ assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForModifiedStateWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
+ local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
+
+ touch testfile
+ git add testfile
+ git commit -m "test" 1>/dev/null
+ echo "test" > testfile
+
+ assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForUntrackedStateWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'
+
+ touch testfile
+
+ assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testGitIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_ICON='Git-Icon'
+
+ assertEquals "%K{green} %F{black%}Git-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testGitlabIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_GITLAB_ICON='GL-Icon'
+
+ # Add a GitLab project as remote origin. This is
+ # sufficient to show the GitLab-specific icon.
+ git remote add origin https://gitlab.com/dritter/gitlab-test-project.git
+
+ assertEquals "%K{green} %F{black%}GL-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testBitbucketIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_BITBUCKET_ICON='BB-Icon'
+
+ # Add a BitBucket project as remote origin. This is
+ # sufficient to show the BitBucket-specific icon.
+ git remote add origin https://dritter@bitbucket.org/dritter/dr-test.git
+
+ assertEquals "%K{green} %F{black%}BB-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testGitHubIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_GIT_GITHUB_ICON='GH-Icon'
+
+ # Add a GitHub project as remote origin. This is
+ # sufficient to show the GitHub-specific icon.
+ git remote add origin https://github.com/dritter/test.git
+
+ assertEquals "%K{green} %F{black%}GH-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testUntrackedFilesIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
+
+ # Create untracked file
+ touch "i-am-untracked.txt"
+
+ assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testStagedFilesIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_STAGED_ICON='+'
+
+ # Create staged file
+ touch "i-am-added.txt"
+ git add i-am-added.txt &>/dev/null
+ git commit -m "initial commit" &>/dev/null
+ echo "xx" >> i-am-added.txt
+ git add i-am-added.txt &>/dev/null
+
+ assertEquals "%K{yellow} %F{black} master ✚ %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testUnstagedFilesIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_UNSTAGED_ICON='M'
+
+ # Create unstaged (modified, but not added to index) file
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" 1>/dev/null
+ echo "xx" > i-am-modified.txt
+
+ assertEquals "%K{yellow} %F{black} master ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testStashIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_STASH_ICON='S'
+
+ # Create modified file
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" 1>/dev/null
+ echo "xx" > i-am-modified.txt
+ git stash 1>/dev/null
+
+ assertEquals "%K{green} %F{black} master S1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+ git tag "v0.0.1"
+
+ assertEquals "%K{green} %F{black} master Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconInDetachedHeadState() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" &>/dev/null
+ git tag "v0.0.1"
+ touch "file2.txt"
+ git add file2.txt
+ git commit -m "Add File2" &>/dev/null
+ git checkout v0.0.1 &>/dev/null
+ local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD)
+
+ assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testActionHintWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ echo "yy" >> i-am-modified.txt
+ git commit -a -m "Provoke conflict" &>/dev/null
+ git pull &>/dev/null
+
+ assertEquals "%K{yellow} %F{black} master %F{red}| merge%f %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testIncomingHintWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='I'
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ git fetch &>/dev/null
+
+ assertEquals "%K{green} %F{black} master I1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testOutgoingHintWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='o'
+
+ touch "i-am-modified.txt"
+ git add i-am-modified.txt
+ git commit -m "Add File" &>/dev/null
+
+ git clone . ../vcs-test2 &>/dev/null
+
+ cd ../vcs-test2
+
+ echo "xx" >> i-am-modified.txt
+ git commit -a -m "Modified file" &>/dev/null
+
+ assertEquals "%K{green} %F{black} master o1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=true
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+ local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=3 HEAD)
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+ assertEquals "%K{green} %F{black}${hash}  master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=false
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ git add file.txt
+ git commit -m "Add File" 1>/dev/null
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+ assertEquals "%K{green} %F{black} master %k%F{green}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec
new file mode 100755
index 00000000..6d8c6428
--- /dev/null
+++ b/test/segments/vcs-hg.spec
@@ -0,0 +1,169 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+
+ P9K_HOME=$(pwd)
+ ### Test specific
+ # Create default folder and hg init it.
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p "${FOLDER}"
+ cd $FOLDER
+
+ export HGUSER="Test bot <bot@example.com>"
+
+ hg init 1>/dev/null
+}
+
+function tearDown() {
+ # Go back to powerlevel9k folder
+ cd "${P9K_HOME}"
+ # Remove eventually created test-specific folder
+ rm -fr "${FOLDER}" &>/dev/null
+ # At least remove test folder completely
+ rm -fr /tmp/powerlevel9k-test &>/dev/null
+ unset FOLDER
+ unset HGUSER
+}
+
+function testColorOverridingForCleanStateWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
+ local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
+
+ assertEquals "%K{white} %F{cyan} default %k%F{white}%f " "$(build_left_prompt)"
+}
+
+function testColorOverridingForModifiedStateWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
+ local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'
+
+ touch testfile
+ hg add testfile
+ hg commit -m "test" 1>/dev/null
+ echo "test" > testfile
+
+ assertEquals "%K{yellow} %F{red} default ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+# There is no staging area in mercurial, therefore there are no "untracked"
+# files.. In case there are added files, we show the VCS segment with a
+# yellow background.
+# This may be improved in future versions, to be a bit more consistent with
+# the git part.
+function testAddedFilesIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ touch "myfile.txt"
+ hg add myfile.txt
+
+ assertEquals "%K{yellow} %F{black} default ● %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+# We don't support tagging in mercurial right now..
+function testTagIconWorks() {
+ startSkipping # Skip test
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+ hg tag "v0.0.1"
+
+ assertEquals "%K{green} %F{black} default Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testTagIconInDetachedHeadState() {
+ startSkipping # Skip test
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_TAG_ICON='T'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" &>/dev/null
+ hg tag "v0.0.1"
+ touch "file2.txt"
+ hg add file2.txt
+ hg commit -m "Add File2" &>/dev/null
+ hg checkout v0.0.1 &>/dev/null
+ local hash=$(hg id)
+
+ assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testActionHintWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ touch "i-am-modified.txt"
+ hg add i-am-modified.txt
+ hg commit -m "Add File" &>/dev/null
+
+ hg clone . ../vcs-test2 &>/dev/null
+ echo "xx" >> i-am-modified.txt
+ hg commit -m "Modified file" &>/dev/null
+
+ cd ../vcs-test2
+ echo "yy" >> i-am-modified.txt
+ hg commit -m "Provoke conflict" 2>/dev/null
+ hg pull 1>/dev/null
+ hg merge --tool internal:merge >/dev/null 2>&1
+
+ assertEquals "%K{yellow} %F{black} default %F{red}| merging%f %k%F{yellow}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=true
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+ local hash=$(hg id | head -c ${POWERLEVEL9K_CHANGESET_HASH_LENGTH})
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+
+ assertEquals "%K{green} %F{black}${hash}  default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_SHOW_CHANGESET=false
+ local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4'
+
+ touch "file.txt"
+ hg add file.txt
+ hg commit -m "Add File" 1>/dev/null
+
+ # This test needs to call powerlevel9k_vcs_init, where
+ # the changeset is truncated.
+ powerlevel9k_vcs_init
+
+ assertEquals "%K{green} %F{black} default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testMercurialIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_HG_ICON='HG-Icon'
+
+ assertEquals "%K{green} %F{black%}HG-Icon %f%F{black} default %k%F{green}%f " "$(build_left_prompt)"
+}
+
+function testBookmarkIconWorks() {
+ local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ local POWERLEVEL9K_VCS_BOOKMARK_ICON='B'
+ hg bookmark "initial"
+
+ assertEquals "%K{green} %F{black} default Binitial %k%F{green}%f " "$(build_left_prompt)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/segments/vi_mode.spec b/test/segments/vi_mode.spec
new file mode 100755
index 00000000..205c38b7
--- /dev/null
+++ b/test/segments/vi_mode.spec
@@ -0,0 +1,38 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function testViInsertModeWorks() {
+ local KEYMAP='viins'
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViInsertModeWorksWhenLabeledAsMain() {
+ local KEYMAP='main'
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViCommandModeWorks() {
+ local KEYMAP='vicmd'
+
+ assertEquals "%K{black} %F{white}NORMAL " "$(prompt_vi_mode left 1 false)"
+}
+
+function testViInsertModeStringIsCustomizable() {
+ local KEYMAP='viins'
+
+ assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)"
+}
+
+source shunit2/source/2.1/src/shunit2 \ No newline at end of file
diff --git a/test/suite.spec b/test/suite.spec
new file mode 100755
index 00000000..0e51d322
--- /dev/null
+++ b/test/suite.spec
@@ -0,0 +1,17 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+local failed=false
+
+for test in **/*.spec; do
+ echo
+ echo "Now executing ${test}"
+ if [[ "${test}" == "test/suite.spec" ]]; then
+ continue;
+ fi
+ ./${test} || failed=true
+done
+
+if [[ "${failed}" == "true" ]]; then
+ exit 1
+fi \ No newline at end of file