From 69fe19ca74ce5b00fa6d120ee6d20707443e5cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 11:17:08 -0400 Subject: [PATCH 001/103] test-in-docker: fix in zsh > 5.3 The way I was filtering out entries in the frameworks array stopped working in newer versions of ZSH; it would convert the array into a string (you could see it with `typeset -p frameworks`) So I rewrote it. I don't see anything in the release notes for ZSH that would explain this and I didn't find any option that would restore this behavior. Related: #882 --- test-in-docker | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test-in-docker b/test-in-docker index 3c7255ec..d291402f 100755 --- a/test-in-docker +++ b/test-in-docker @@ -21,7 +21,10 @@ versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) ) # List of frameworks typeset -a frameworks frameworks=( docker/*/Dockerfile(N.on:h:t) ) -frameworks=${(@)frameworks:#base-*} +for i in {$#frameworks..1}; do + # Remove all base entries + [[ "${frameworks[$i]}" = base-* ]] && frameworks[$i]=() +done # Known Issues typeset -A known_issues From 645034f74c6daca97c06f3dc99ae00e98522af49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 11:21:01 -0400 Subject: [PATCH 002/103] test-in-docker: add additional warnings --- test-in-docker | 1 + 1 file changed, 1 insertion(+) diff --git a/test-in-docker b/test-in-docker index d291402f..89a223f1 100755 --- a/test-in-docker +++ b/test-in-docker @@ -6,6 +6,7 @@ set -eu default_version='4.3.11' setopt extended_glob glob_subst numeric_glob_sort +setopt warn_create_global warn_nested_var 2> /dev/null cd "${${(%):-%x}:A:h}" # TODO: Crazy Logic to munge TERM to something supported in Ubuntu 14.04 From 89863209fc81a70f6affa96ebd7df950cc3f8575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 11:21:23 -0400 Subject: [PATCH 003/103] test-in-docker: make vars sorted and readonly Marking variables as readonly is helpful for debugging and preventing problems. --- test-in-docker | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test-in-docker b/test-in-docker index 89a223f1..f4e8e1c8 100755 --- a/test-in-docker +++ b/test-in-docker @@ -16,16 +16,18 @@ term=screen-256color # ...see Modifiers in zshexpn(1) for details. # List of ZSH versions -typeset -a versions +typeset -aU versions versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) ) +typeset -r versions # List of frameworks -typeset -a frameworks +typeset -aU frameworks frameworks=( docker/*/Dockerfile(N.on:h:t) ) for i in {$#frameworks..1}; do # Remove all base entries [[ "${frameworks[$i]}" = base-* ]] && frameworks[$i]=() done +typeset -r frameworks # Known Issues typeset -A known_issues @@ -34,6 +36,7 @@ known_issues["4.3.11-zim"]="BROKEN: Zim wants ZSH 5.2 or newer." known_issues["5.0.3-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer." known_issues["5.1.1-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer." known_issues["4.3.11-zulu"]="Zulu doesn't work; it needs a newer version of git." +typeset -r known_issues err() { @@ -178,6 +181,8 @@ while (( $# > 0 )); do shift done +typeset -r use_version use_framework + build_and_run "$use_version" "$use_framework" # EOF From 83abdf742c04eae76b64a6fd22540373bd12f456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 11:25:12 -0400 Subject: [PATCH 004/103] test-in-docker: add dry-run mode --- test-in-docker | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test-in-docker b/test-in-docker index f4e8e1c8..98257fc3 100755 --- a/test-in-docker +++ b/test-in-docker @@ -72,6 +72,14 @@ check_for_known_issues() { fi } +cmd() { + if (( dry_run )); then + echo "${(@q)*}" 1>&2 + else + "${(@)*}" + fi +} + build_and_run() { local version="$1" local framework="$2" @@ -82,14 +90,14 @@ build_and_run() { print -P "%F{green}Preparing containers...%f" echo -n "p9k:base-${version}: " - docker build \ + cmd docker build \ --quiet \ --tag "p9k:base-${version}" \ --file "docker/base-${version}/Dockerfile" \ . echo -n "p9k:${version}-${framework}: " - docker build \ + cmd docker build \ --quiet \ --build-arg="base=base-${version}" \ --tag "p9k:${version}-${framework}" \ @@ -97,7 +105,7 @@ build_and_run() { . print -P "%F{green}Starting ${name} container...%f" - exec docker run \ + cmd docker run \ --rm \ --interactive \ --tty \ @@ -112,9 +120,10 @@ show_help() { echo echo "Loads up a docker image with powershell9k configured in " echo - echo " --frameworks Lists all available frameworks, newline separated." - echo " --versions Lists all available ZSH versions, newline separated." - echo " --zsh VER Uses ZSH with version VER." + echo " -f --frameworks Lists all available frameworks, newline separated." + echo " -v --versions Lists all available ZSH versions, newline separated." + echo " -z --zsh VER Uses ZSH with version VER." + echo " -n --dry-run Just prints the docker commands that would be run." echo " --help You're soaking in it." echo echo "ZSH versions:" @@ -137,6 +146,7 @@ fi # Parse flags and such. use_version=$default_version use_framework= +dry_run=0 while (( $# > 0 )); do case "$1" in -f | --frameworks ) @@ -156,6 +166,7 @@ while (( $# > 0 )); do err "No such ZSH version '${1}'" fi ;; + -n | --dry-run ) dry_run=1 ;; -h | --help ) show_help exit @@ -181,7 +192,7 @@ while (( $# > 0 )); do shift done -typeset -r use_version use_framework +typeset -r use_version use_framework dry_run build_and_run "$use_version" "$use_framework" From 3c27414e7e985536a8b286d09b2248e7dee8263e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 16:52:16 -0400 Subject: [PATCH 005/103] test-in-docker: lint from @dritter --- test-in-docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-in-docker b/test-in-docker index 98257fc3..e55c9422 100755 --- a/test-in-docker +++ b/test-in-docker @@ -25,7 +25,7 @@ typeset -aU frameworks frameworks=( docker/*/Dockerfile(N.on:h:t) ) for i in {$#frameworks..1}; do # Remove all base entries - [[ "${frameworks[$i]}" = base-* ]] && frameworks[$i]=() + [[ "${frameworks[$i]}" == base-* ]] && frameworks[$i]=() done typeset -r frameworks From a94df3ddcb027d88717f854cd5f610a771c1c71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 27 Jun 2018 16:52:38 -0400 Subject: [PATCH 006/103] test-in-docker: resolve version and framework late --- test-in-docker | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/test-in-docker b/test-in-docker index e55c9422..0ed1254f 100755 --- a/test-in-docker +++ b/test-in-docker @@ -2,8 +2,9 @@ set -eu -# The default ZSH to use. -default_version='4.3.11' +# The default ZSH to use; it can just be the first few characters. +# This should be the oldest version we support. +default_version='4.' setopt extended_glob glob_subst numeric_glob_sort setopt warn_create_global warn_nested_var 2> /dev/null @@ -144,8 +145,8 @@ if (( $# == 0 )); then fi # Parse flags and such. -use_version=$default_version -use_framework= +asked_for_version=$default_version +asked_for_framework= dry_run=0 while (( $# > 0 )); do case "$1" in @@ -159,12 +160,7 @@ while (( $# > 0 )); do ;; -z | --zsh ) shift - local v="$(resolve_version "$1")" - if [[ -n "$v" ]]; then - use_version=$v - else - err "No such ZSH version '${1}'" - fi + asked_for_version=$1 ;; -n | --dry-run ) dry_run=1 ;; -h | --help ) @@ -177,22 +173,27 @@ while (( $# > 0 )); do exit 1 ;; * ) - if [[ -z "$use_framework" ]]; then - local f="$(resolve_framework "$1")" - if [[ -n "$f" ]]; then - use_framework=$f - else - err "No such framework '${1}'" - fi + if [[ -z "$asked_for_framework" ]]; then + asked_for_framework=$1 else - err "You can only specify one framework at a time; you already specified '${use_framework}'" + err "You can only specify one framework at a time; you already specified '${asked_for_framework}'" fi ;; esac shift done -typeset -r use_version use_framework dry_run +typeset -r asked_for_version asked_for_framework + +typeset -r use_version="$(resolve_version "${asked_for_version}")" +if [[ -z "$use_version" ]]; then + err "No such ZSH version '${asked_for_version}'" +fi + +typeset -r use_framework="$(resolve_framework "${asked_for_framework}")" +if [[ -z "$use_framework" ]]; then + err "No such framework '${asked_for_framework}'" +fi build_and_run "$use_version" "$use_framework" From 20fdf0517c2b626540eb6783d4aa99350efe3c7f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 26 Jun 2018 23:06:05 +0200 Subject: [PATCH 007/103] Add Dockerfiles for ZSH 5.3.1, 5.4.2, 5.5.1 --- docker/base-5.3.1/Dockerfile | 40 ++++++++++++++++++++++++++++++++++++ docker/base-5.4.2/Dockerfile | 35 +++++++++++++++++++++++++++++++ docker/base-5.5.1/Dockerfile | 35 +++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 docker/base-5.3.1/Dockerfile create mode 100644 docker/base-5.4.2/Dockerfile create mode 100644 docker/base-5.5.1/Dockerfile diff --git a/docker/base-5.3.1/Dockerfile b/docker/base-5.3.1/Dockerfile new file mode 100644 index 00000000..0294cf25 --- /dev/null +++ b/docker/base-5.3.1/Dockerfile @@ -0,0 +1,40 @@ +FROM debian:stretch + +# We switched here to debian, as there seems no ZSH 5.3 in ubuntu. + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.3.1-4+b2 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +# Locale generation is different in debian. We need to enable en_US +# locale and then regenerate locales. +RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/docker/base-5.4.2/Dockerfile b/docker/base-5.4.2/Dockerfile new file mode 100644 index 00000000..8984c105 --- /dev/null +++ b/docker/base-5.4.2/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:18.04 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.4.2-3ubuntu3 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] diff --git a/docker/base-5.5.1/Dockerfile b/docker/base-5.5.1/Dockerfile new file mode 100644 index 00000000..85fc570c --- /dev/null +++ b/docker/base-5.5.1/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:18.10 + +RUN \ + apt-get update && \ + echo 'golang-go golang-go/dashboard boolean false' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + curl \ + git \ + zsh=5.5.1-1ubuntu1 \ + mercurial \ + subversion \ + golang \ + jq \ + nodejs \ + ruby \ + python \ + python-virtualenv \ + sudo \ + locales + +RUN adduser --shell /bin/zsh --gecos 'fred' --disabled-password fred +RUN locale-gen "en_US.UTF-8" + +COPY docker/fred-sudoers /etc/sudoers.d/fred + +USER fred +WORKDIR /home/fred +ENV LANG=en_US.UTF-8 +ENV TERM=xterm-256color +ENV DEFAULT_USER=fred +ENV POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + +RUN touch .zshrc + +CMD ["/bin/zsh", "-l"] From 74051e59fd8cb85b77136981a5dbbaa5e1c7530e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 26 Jun 2018 23:04:46 +0200 Subject: [PATCH 008/103] Force creation of symlink in prezto --- docker/prezto/install.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/prezto/install.zsh b/docker/prezto/install.zsh index 9cca57ed..2b2e878c 100644 --- a/docker/prezto/install.zsh +++ b/docker/prezto/install.zsh @@ -9,7 +9,7 @@ for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -nsf "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" done -ln -s "${HOME}/p9k/powerlevel9k.zsh-theme" \ +ln -snf "${HOME}/p9k/powerlevel9k.zsh-theme" \ "${HOME}/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup" echo "zstyle ':prezto:module:prompt' theme 'powerlevel9k'" \ From b9e6e6f32a74f6a177c1367a262411afaf893a20 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 27 Jun 2018 23:26:50 +0200 Subject: [PATCH 009/103] Fixate ZSH versions in docker --- docker/base-5.0.3/Dockerfile | 2 +- docker/base-5.1.1/Dockerfile | 2 +- docker/base-5.2/Dockerfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/base-5.0.3/Dockerfile b/docker/base-5.0.3/Dockerfile index e0b6c6c3..b1b85fcb 100644 --- a/docker/base-5.0.3/Dockerfile +++ b/docker/base-5.0.3/Dockerfile @@ -6,7 +6,7 @@ RUN \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ curl \ git \ - zsh \ + zsh=5.0.2-3ubuntu6.2 \ mercurial \ subversion \ golang \ diff --git a/docker/base-5.1.1/Dockerfile b/docker/base-5.1.1/Dockerfile index a7f644bf..c4fb6424 100644 --- a/docker/base-5.1.1/Dockerfile +++ b/docker/base-5.1.1/Dockerfile @@ -6,7 +6,7 @@ RUN \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ curl \ git \ - zsh \ + zsh=5.1.1-1ubuntu2.2 \ mercurial \ subversion \ golang \ diff --git a/docker/base-5.2/Dockerfile b/docker/base-5.2/Dockerfile index 62a10074..1898592c 100644 --- a/docker/base-5.2/Dockerfile +++ b/docker/base-5.2/Dockerfile @@ -6,7 +6,7 @@ RUN \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ curl \ git \ - zsh \ + zsh=5.2-5ubuntu1.2 \ mercurial \ subversion \ golang \ From 0b92e915c49a80a670307e84a828c5b89885928d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 27 Jun 2018 23:27:17 +0200 Subject: [PATCH 010/103] Use ubuntu 17.10, as the sources for 17.04 seem to be down --- docker/base-5.2/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/base-5.2/Dockerfile b/docker/base-5.2/Dockerfile index 1898592c..2ec096fc 100644 --- a/docker/base-5.2/Dockerfile +++ b/docker/base-5.2/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:17.04 +FROM ubuntu:17.10 RUN \ apt-get update && \ From 4178240b2493115641c8cd204266e6d3d593af6b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 12 Jul 2018 00:16:10 +0200 Subject: [PATCH 011/103] Add Dockerfile for zshing framework --- docker/zshing/Dockerfile | 7 +++++++ docker/zshing/install.zsh | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 docker/zshing/Dockerfile create mode 100644 docker/zshing/install.zsh diff --git a/docker/zshing/Dockerfile b/docker/zshing/Dockerfile new file mode 100644 index 00000000..a51a3067 --- /dev/null +++ b/docker/zshing/Dockerfile @@ -0,0 +1,7 @@ +ARG base +FROM p9k:${base} + +COPY docker/zshing/install.zsh /tmp/ +RUN zsh /tmp/install.zsh + +COPY ./ p9k/ diff --git a/docker/zshing/install.zsh b/docker/zshing/install.zsh new file mode 100644 index 00000000..8f926992 --- /dev/null +++ b/docker/zshing/install.zsh @@ -0,0 +1,16 @@ +#!zsh + +# install zshing https://github.com/zakariaGatter/zshing +git clone https://github.com/zakariaGatter/zshing.git ~/.zshing/zshing + +# Link P9K in zshing directory +ln -nsf ~/p9k ~/.zshing/powerlevel9k + +{ + echo + echo 'ZSHING_PLUGINS=( + "bhilburn/powerlevel9k" + )' + echo + echo "source ~/.zshing/zshing/zshing.zsh" +} >> ~/.zshrc From 6c4a3e8a1b2ef2f9227594a4198e8588032926d7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 13 Jul 2018 01:18:07 +0200 Subject: [PATCH 012/103] Execute tests on various ZSH versions --- .travis.yml | 73 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 648499ab..ab330f9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,78 @@ -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 @@ -29,4 +84,4 @@ script: - test/segments/go_version.spec - test/segments/vcs.spec - test/segments/kubecontext.spec - - test/segments/laravel_version.spec + - test/segments/laravel_version.spec \ No newline at end of file From 21f2d1a377294c5adea3a8a225e04cabc4cc4797 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 15 Jul 2018 22:23:24 +0200 Subject: [PATCH 013/103] Test all *.spec files on travis --- .travis.yml | 12 +----------- test/suite.spec | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100755 test/suite.spec diff --git a/.travis.yml b/.travis.yml index ab330f9c..ac94f261 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,14 +74,4 @@ before_script: - "zsh --version" 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 \ No newline at end of file + - test/suite.spec \ No newline at end of file diff --git a/test/suite.spec b/test/suite.spec new file mode 100755 index 00000000..7e139889 --- /dev/null +++ b/test/suite.spec @@ -0,0 +1,15 @@ +#!/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 + 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 From b996ca911e96b5b0fb5b60ea9c6e266404b01c8b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 08:17:28 +0200 Subject: [PATCH 014/103] Output running test --- test/suite.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/suite.spec b/test/suite.spec index 7e139889..0e51d322 100755 --- a/test/suite.spec +++ b/test/suite.spec @@ -4,6 +4,8 @@ local failed=false for test in **/*.spec; do + echo + echo "Now executing ${test}" if [[ "${test}" == "test/suite.spec" ]]; then continue; fi From 0e4e9e4256b286213843f4e83a46c7ecb68a8bc1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 20:46:00 +0200 Subject: [PATCH 015/103] Add tests for anaconda segment --- test/segments/anaconda.spec | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/segments/anaconda.spec 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 From 8c44fa68a25c12748fd4f031c691c54b76d0e290 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 20:46:23 +0200 Subject: [PATCH 016/103] Add tests for aws_eb_env segment --- test/segments/aws_eb_env.spec | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 test/segments/aws_eb_env.spec 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 From 74a3d2d6e2b88e9d4c89995373e0d176b47450d7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 20:47:15 +0200 Subject: [PATCH 017/103] Add tests for background_jobs segment --- test/segments/background_jobs.spec | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 test/segments/background_jobs.spec 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 From 802af322ff3c0541cb89dac30362e576ff1f81a2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 20:48:27 +0200 Subject: [PATCH 018/103] Add tests for battery segment Additionally - Add a fourth parameter to prompt_battery for better testability. This parameter is the root prefix, so we can use our own test batteries. --- powerlevel9k.zsh-theme | 11 ++- test/segments/battery.spec | 184 +++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 5 deletions(-) create mode 100755 test/segments/battery.spec diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c1ea754f..eefcedde 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 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 From d9b3edf0e856adc958758583066ca5c7383b041d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 16 Jul 2018 22:16:41 +0200 Subject: [PATCH 019/103] Fix go_version test --- test/segments/go_version.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 743ddc1253f49195b2e2483d66e97eb5d78b3712 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:11:51 +0200 Subject: [PATCH 020/103] Add tests for context segment --- test/segments/context.spec | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 test/segments/context.spec 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 From 629d52a7d548f055b27e79d60651f21a19aed684 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:13:25 +0200 Subject: [PATCH 021/103] Add visual identifier to custom segments --- powerlevel9k.zsh-theme | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index eefcedde..144b4df4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -703,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 } From 829c7ceaae4f8bb72420c65afc0e2c011a359d71 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:13:52 +0200 Subject: [PATCH 022/103] Add tests for custom segment --- test/segments/custom.spec | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 test/segments/custom.spec 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 From b61d021abdf0987960022ca6999549ef33ce9681 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:15:35 +0200 Subject: [PATCH 023/103] Simplify detect_virt segment --- powerlevel9k.zsh-theme | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 144b4df4..2e645f0a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1046,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 } From edfd4732f21ddae72bdcca4191487c545e0a08d3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:15:57 +0200 Subject: [PATCH 024/103] Add tests for detect_virt segment --- test/segments/detect_virt.spec | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 test/segments/detect_virt.spec 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 From a7576074760eb773b2f7bbdfdad56f7dadae296c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:16:40 +0200 Subject: [PATCH 025/103] Add tests for disk_usage segment --- test/segments/disk_usage.spec | 112 ++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 test/segments/disk_usage.spec 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 From 43272410c90e41affd20afa3110c519e1bd8bada Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:17:54 +0200 Subject: [PATCH 026/103] Change ip segment so that the tests can be executed on OSX as well Change regular expressions to a more compatible format. --- powerlevel9k.zsh-theme | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2e645f0a..1c9194f7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1088,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 } ################################################################ From 1cf68e418c184023c717b8a6a71d30168936adf4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:19:14 +0200 Subject: [PATCH 027/103] Add tests for ip segment --- test/segments/ip.spec | 202 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100755 test/segments/ip.spec 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 From 04168cc5c012f9ca5759bf277a2e0d44a145c520 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:20:16 +0200 Subject: [PATCH 028/103] Change load segment to accept an optional root prefix for testability --- powerlevel9k.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1c9194f7..1983b031 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1132,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 @@ -1167,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 From 2efbd7e1880f62801db2d3739e3d33b2dfc1b154 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:20:50 +0200 Subject: [PATCH 029/103] Add tests for load segment --- test/segments/load.spec | 137 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100755 test/segments/load.spec 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 From 85cc62b72b3ab10fffe03b1446f1403e7c42b21d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:21:27 +0200 Subject: [PATCH 030/103] Add tests for node_version segment --- test/segments/node_version.spec | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 test/segments/node_version.spec 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 From 44ec267dfbff5ede95c46c5bd01e684a259df3cf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:21:48 +0200 Subject: [PATCH 031/103] Add tests for nodeenv segment --- test/segments/nodeenv.spec | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 test/segments/nodeenv.spec 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 From 084f992fab98b2d2902c60f3737e2526a4f58649 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:22:17 +0200 Subject: [PATCH 032/103] Add tests for nvm segment --- test/segments/nvm.spec | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 test/segments/nvm.spec diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec new file mode 100755 index 00000000..fe40b067 --- /dev/null +++ b/test/segments/nvm.spec @@ -0,0 +1,66 @@ +#!/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}" + 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 testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias nvm=nonvm + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_CUSTOM_WORLD + unalias nvm +} + +function testNvmSegmentWorksWithoutHavingADefaultAlias() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm) + nvm() { echo 'v4.6.0'; } + + assertEquals "%K{green} %F{011%}⬢ %f%F{011}4.6.0 %k%F{green}%f " "$(build_left_prompt)" + + unfunction nvm +} + +function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + nvm() { echo 'v4.6.0'; } + + export NVM_DIR="${FOLDER}" + mkdir alias + echo 'v4.6.0' > alias/default + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unfunction nvm + unset POWERLEVEL9K_CUSTOM_WORLD + unset NVM_DIR +} + +source shunit2/source/2.1/src/shunit2 \ No newline at end of file From e95f84a55df716d45dc3609538a8fa89f3c6c219 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:23:12 +0200 Subject: [PATCH 033/103] Add tests for php_version segment --- test/segments/php_version.spec | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 test/segments/php_version.spec 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 From 1e71d452e1f20568ed83f9d86fda63ba58643bad Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:23:32 +0200 Subject: [PATCH 034/103] Add tests for public_ip segment --- test/segments/public_ip.spec | 188 +++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100755 test/segments/public_ip.spec 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 From e99c7549fb330aa36f2912e1f0ace0081c26efd7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:24:25 +0200 Subject: [PATCH 035/103] Change ram segment to take an optional root prefix for testability --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1983b031..2b68b6a4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1241,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 @@ -1252,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 From cc31a05c526ab7160ab675fa590f206a76b0380c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:25:06 +0200 Subject: [PATCH 036/103] Add test for ram segment --- test/segments/ram.spec | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 test/segments/ram.spec 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 From e51faa0af176638fce3da3bf03f4127d4f190438 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:25:35 +0200 Subject: [PATCH 037/103] Add tests for ssh segment --- test/segments/ssh.spec | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 test/segments/ssh.spec 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 From 7a3aa9d3d1955f6a884705a690647cc8aaf96255 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:26:08 +0200 Subject: [PATCH 038/103] Change swap segment to take an optional root prefix for testability --- powerlevel9k.zsh-theme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2b68b6a4..16051839 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1422,6 +1422,7 @@ prompt_status() { ################################################################ # Segment to display Swap information prompt_swap() { + local ROOT_PREFIX="${4}" local swap_used=0 local base='' @@ -1436,8 +1437,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 From af31b2de9b62134298d06540f70bc80e84e65f32 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:26:39 +0200 Subject: [PATCH 039/103] Add tests for swap segment --- test/segments/swap.spec | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/segments/swap.spec 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 From 78e03a5fe6f7b8644164b65d62d057e13ef69e1b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:27:03 +0200 Subject: [PATCH 040/103] Add tests for swift segment --- test/segments/swift_version.spec | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/segments/swift_version.spec 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 From 84f327bd60956405b9644ef48f05221903311267 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:27:23 +0200 Subject: [PATCH 041/103] Add tests for symfony_version segment --- test/segments/symfony_version.spec | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 test/segments/symfony_version.spec 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 From 0d4004ef1926f0e0e79ec37390ce2840b7db6359 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:27:44 +0200 Subject: [PATCH 042/103] Add tests for todo segment --- test/segments/todo.spec | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/segments/todo.spec 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 From ad0c9a6802e8b22f851d52f03c1880f6b28b81ed Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:28:08 +0200 Subject: [PATCH 043/103] Add tests for vcs (git) segment --- test/segments/vcs-git.spec | 309 +++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100755 test/segments/vcs-git.spec 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 From aa5e9ccc3b089291c8653e5259725a61e4c749ba Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 18 Jul 2018 22:28:28 +0200 Subject: [PATCH 044/103] Add tests for vcs (hg) segment --- test/segments/vcs-hg.spec | 169 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 test/segments/vcs-hg.spec 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 " + + 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 From d13410d38c12e23f0a61c63625d5ad7889f86730 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 07:40:58 +0200 Subject: [PATCH 045/103] Fix tests for nvm segment --- test/segments/nvm.spec | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index fe40b067..8f3b3c26 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -14,11 +14,15 @@ function setUp() { ### Test specific # Create default folder and git init it. FOLDER=/tmp/powerlevel9k-test/nvm-test - mkdir -p "${FOLDER}" + 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 @@ -30,37 +34,29 @@ function tearDown() { function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' - alias nvm=nonvm assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_CUSTOM_WORLD - unalias nvm } function testNvmSegmentWorksWithoutHavingADefaultAlias() { local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm) - nvm() { echo 'v4.6.0'; } - assertEquals "%K{green} %F{011%}⬢ %f%F{011}4.6.0 %k%F{green}%f " "$(build_left_prompt)" + function nvm_version() { + [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' + } - unfunction nvm + 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' - nvm() { echo 'v4.6.0'; } - export NVM_DIR="${FOLDER}" - mkdir alias - echo 'v4.6.0' > alias/default + 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)" - - unfunction nvm - unset POWERLEVEL9K_CUSTOM_WORLD - unset NVM_DIR } source shunit2/source/2.1/src/shunit2 \ No newline at end of file From 671f826a4087ee35a399475712fe9cea4d4fc337 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 07:42:09 +0200 Subject: [PATCH 046/103] Set background color of vi_mode segment to white in insert mode --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 16051839..ee744799 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1611,7 +1611,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 From a5d9227fcb9110bc50d28f6e70bc67c918991f0d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 07:42:47 +0200 Subject: [PATCH 047/103] Add tests for vi_mode segment --- test/segments/vi_mode.spec | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 test/segments/vi_mode.spec 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 From cf353f5660c6b11220032264a3e9635a12e5e451 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 08:15:50 +0200 Subject: [PATCH 048/103] Add tests for color overriding --- test/core/color_overriding.spec | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 test/core/color_overriding.spec diff --git a/test/core/color_overriding.spec b/test/core/color_overriding.spec new file mode 100755 index 00000000..ead890d7 --- /dev/null +++ b/test/core/color_overriding.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 +} + +function testDynamicColoringOfSegmentsWork() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_BACKGROUND='red' + + assertEquals "%K{red} %F{black%}date-icon %f%F{black}%D{%d.%m.%y} %k%F{red}%f " "$(build_left_prompt)" +} + +function testDynamicColoringOfVisualIdentifiersWork() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' + + assertEquals "%K{white} %F{green%}date-icon %f%F{black}%D{%d.%m.%y} %k%F{white}%f " "$(build_left_prompt)" +} + +function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(date) + local POWERLEVEL9K_DATE_ICON="date-icon" + local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_DATE_FOREGROUND='red' + local POWERLEVEL9K_DATE_BACKGROUND='yellow' + + assertEquals "%K{yellow} %F{green%}date-icon %f%F{red}%D{%d.%m.%y} %k%F{yellow}%f " "$(build_left_prompt)" +} + +function testColorOverridingOfStatefulSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(host) + local POWERLEVEL9K_SSH_ICON="ssh-icon" + local POWERLEVEL9K_HOST_REMOTE_BACKGROUND='red' + local POWERLEVEL9K_HOST_REMOTE_FOREGROUND='green' + # Provoke state + local SSH_CLIENT="x" + + assertEquals "%K{red} %F{green%}ssh-icon %f%F{green}%m %k%F{red}%f " "$(build_left_prompt)" +} + +function testColorOverridingOfCustomSegment() { + local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_CUSTOM_WORLD_ICON='CW' + local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red' + local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red' + + assertEquals "%K{red} %F{green%}CW %f%F{red}world %k%F{red}%f " "$(build_left_prompt)" +} + +source shunit2/source/2.1/src/shunit2 \ No newline at end of file From 7bfa471e41a225b858fcf43da255bc5962351fd9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 08:22:58 +0200 Subject: [PATCH 049/103] Fix tests for dir segment on OSX --- test/segments/dir.spec | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/segments/dir.spec b/test/segments/dir.spec index b5fce59f..3e66e918 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -22,7 +22,15 @@ function testDirPathAbsoluteWorks() { POWERLEVEL9K_DIR_PATH_ABSOLUTE=true cd ~ - assertEquals "%K{blue} %F{black}/home/travis %k%F{blue}%f " "$(build_left_prompt)" + + # Unfortunately, we cannot fake Linux or OSX here, because + # of /home or /Users path.. That is why we change the test + # according to the OS of the host. + if [[ "${OS}" == 'Linux' ]]; then + assertEquals "%K{blue} %F{black}/home/${USER} %k%F{blue}%f " "$(build_left_prompt)" + elif [[ "${OS}" == 'OSX' ]]; then + assertEquals "%K{blue} %F{black}/Users/${USER} %k%F{blue}%f " "$(build_left_prompt)" + fi cd - unset POWERLEVEL9K_DIR_PATH_ABSOLUTE From 2fa2e7560ff6f345fba26fd92c231b0847bd7906 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 21:49:06 +0200 Subject: [PATCH 050/103] Remove vcs.spec There are now specific tests for git and hg --- test/segments/vcs.spec | 161 ----------------------------------------- 1 file changed, 161 deletions(-) delete mode 100755 test/segments/vcs.spec diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec deleted file mode 100755 index f6474f61..00000000 --- a/test/segments/vcs.spec +++ /dev/null @@ -1,161 +0,0 @@ -#!/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 testColorOverridingForCleanStateWorks() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' - POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - - assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_CLEAN_FOREGROUND - unset POWERLEVEL9K_VCS_CLEAN_BACKGROUND -} - -function testColorOverridingForModifiedStateWorks() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' - POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - git config user.email "test@powerlevel9k.theme" - git config user.name "Testing Tester" - 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)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_MODIFIED_FOREGROUND - unset POWERLEVEL9K_VCS_MODIFIED_BACKGROUND -} - -function testColorOverridingForUntrackedStateWorks() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan' - POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow' - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - touch testfile - - assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND - unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND -} - -function testBranchNameTruncatingShortenLength() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_SHORTEN_LENGTH=6 - POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3 - POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - touch testfile - - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" - - POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 - assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_SHORTEN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY -} - -function testBranchNameTruncatingMinLength() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 - POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=6 - POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - touch testfile - - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" - - POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7 - - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_SHORTEN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY -} - -function testBranchNameTruncatingShortenStrategy() { - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) - POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 - POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3 - POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right" - - FOLDER=/tmp/powerlevel9k-test/vcs-test - mkdir -p $FOLDER - cd $FOLDER - git init 1>/dev/null - touch testfile - - assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" - - POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle" - - assertEquals "%K{green} %F{black} mas…ter ? %k%F{green}%f " "$(build_left_prompt)" - - cd - - rm -fr /tmp/powerlevel9k-test - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_VCS_SHORTEN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH - unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY -} - -source shunit2/source/2.1/src/shunit2 From 4b32b2c0b246e65529e8e055c63be8d58be15f95 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 22:25:15 +0200 Subject: [PATCH 051/103] Fix tests --- test/powerlevel9k.spec | 55 ++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 0ddf36c1..57f85c98 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -17,68 +17,66 @@ function setUp() { } function testJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined) cd /tmp assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - } function testTransitiveJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined) cd /tmp assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - } function testJoiningWithConditionalSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined) cd /tmp assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - } function testDynamicColoringOfSegmentsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' + local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' cd /tmp assertEquals "%K{red} %F{black}/tmp %k%F{red}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND cd - } function testDynamicColoringOfVisualIdentifiersWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' - POWERLEVEL9K_FOLDER_ICON="icon-here" + local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_FOLDER_ICON="icon-here" cd /tmp assertEquals "%K{blue} %F{green%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR - unset POWERLEVEL9K_FOLDER_ICON cd - } function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' - POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='red' - POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='yellow' - POWERLEVEL9K_FOLDER_ICON="icon-here" + local POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR='green' + local POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='red' + local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='yellow' + local POWERLEVEL9K_FOLDER_ICON="icon-here" # Re-Source the icons, as the POWERLEVEL9K_MODE is directly # evaluated there. @@ -88,17 +86,13 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { assertEquals "%K{yellow} %F{green%}icon-here %f%F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR - unset POWERLEVEL9K_DIR_DEFAULT_FOREGROUND - unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND - unset POWERLEVEL9K_FOLDER_ICON cd - } function testOverwritingIconsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_FOLDER_ICON='icon-here' + local POWERLEVEL9K_FOLDER_ICON='icon-here' #local testFolder=$(mktemp -d -p p9k) # Move testFolder under home folder #mv testFolder ~ @@ -108,29 +102,22 @@ function testOverwritingIconsWork() { cd /tmp assertEquals "%K{blue} %F{black%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_DIR_FOLDER_ICON cd - # rm -fr ~/$testFolder } function testNewlineOnRpromptCanBeDisabled() { - POWERLEVEL9K_PROMPT_ON_NEWLINE=true - POWERLEVEL9K_RPROMPT_ON_NEWLINE=false - POWERLEVEL9K_CUSTOM_WORLD='echo world' - POWERLEVEL9K_CUSTOM_RWORLD='echo rworld' + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_CUSTOM_RWORLD='echo rworld' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) powerlevel9k_prepare_prompts assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" - - unset POWERLEVEL9K_PROMPT_ON_NEWLINE - unset POWERLEVEL9K_RPROMPT_ON_NEWLINE - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD - unset POWERLEVEL9K_CUSTOM_RWORLD } source shunit2/source/2.1/src/shunit2 From 16e5e14af747bb310dabd367648b5566cd2edc6b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 19 Jul 2018 22:39:19 +0200 Subject: [PATCH 052/103] Fix tests on older ZSH versions --- test/segments/anaconda.spec | 12 ++++--- test/segments/aws_eb_env.spec | 5 +-- test/segments/background_jobs.spec | 12 ++++--- test/segments/battery.spec | 12 ------- test/segments/context.spec | 21 ++++++++---- test/segments/custom.spec | 18 +++++++---- test/segments/detect_virt.spec | 14 +++++--- test/segments/disk_usage.spec | 18 +++++++---- test/segments/ip.spec | 21 ++++++++---- test/segments/node_version.spec | 6 ++-- test/segments/nodeenv.spec | 15 ++++++--- test/segments/nvm.spec | 9 ++++-- test/segments/php_version.spec | 6 ++-- test/segments/public_ip.spec | 27 ++++++++++------ test/segments/ram.spec | 3 -- test/segments/ssh.spec | 12 ++++--- test/segments/status.spec | 34 ++++++++++++-------- test/segments/swap.spec | 6 ++-- test/segments/swift_version.spec | 6 ++-- test/segments/symfony_version.spec | 15 ++++++--- test/segments/todo.spec | 6 ++-- test/segments/vcs-git.spec | 51 ++++++++++++++++++++---------- test/segments/vcs-hg.spec | 30 ++++++++++++------ 23 files changed, 227 insertions(+), 132 deletions(-) diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec index 11add849..da87c096 100755 --- a/test/segments/anaconda.spec +++ b/test/segments/anaconda.spec @@ -13,7 +13,8 @@ function setUp() { function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world) # Unset anacona variables unset CONDA_ENV_PATH unset CONDA_PREFIX @@ -24,7 +25,8 @@ function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { CONDA_ENV_PATH=/tmp unset CONDA_PREFIX - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" @@ -33,7 +35,8 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { unset CONDA_ENV_PATH local CONDA_PREFIX="test" - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" @@ -42,7 +45,8 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { function testAnacondaSegmentWorks() { local CONDA_ENV_PATH=/tmp local CONDA_PREFIX="test" - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec index 530da6a1..56042027 100755 --- a/test/segments/aws_eb_env.spec +++ b/test/segments/aws_eb_env.spec @@ -23,7 +23,7 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() { echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml cd /tmp/powerlevel9k-test - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)" @@ -40,7 +40,8 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirec 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) assertEquals "%K{black} %F{green%}🌱 %f%F{green}test %k%F{black}%f " "$(build_left_prompt)" diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index 9f866ff0..5a000b66 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -13,7 +13,8 @@ function setUp() { function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" @@ -23,7 +24,8 @@ function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) jobs() { echo '[1] + 30444 suspended nvim xx' } @@ -35,7 +37,8 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) jobs() { echo "[1] 31190 suspended nvim xx" echo "[2] - 31194 suspended nvim xx2" @@ -49,7 +52,8 @@ function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { function testBackgroundJobsSegmentWithVerboseMode() { local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=true - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) jobs() { echo "[1] 31190 suspended nvim xx" echo "[2] - 31194 suspended nvim xx2" diff --git a/test/segments/battery.spec b/test/segments/battery.spec index 808ecc6a..e49c3b34 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -65,7 +65,6 @@ function makeBatterySay() { 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" @@ -74,7 +73,6 @@ function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() { 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" @@ -83,7 +81,6 @@ function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { 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" @@ -92,7 +89,6 @@ function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { 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" @@ -109,7 +105,6 @@ function testBatterySegmentIfBatteryIsFullOnOSX() { 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" @@ -118,7 +113,6 @@ function testBatterySegmentIfBatteryIsCalculatingOnOSX() { 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})" @@ -126,7 +120,6 @@ function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() { 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})" @@ -134,7 +127,6 @@ function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() { 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})" @@ -142,7 +134,6 @@ function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() { 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})" @@ -150,7 +141,6 @@ function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() { 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})" @@ -158,7 +148,6 @@ function testBatterySegmentIfBatteryIsFullOnLinux() { 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 @@ -172,7 +161,6 @@ function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { 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 diff --git a/test/segments/context.spec b/test/segments/context.spec index e86bc357..702280df 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -23,41 +23,47 @@ function tearDown() { function testContextSegmentDoesNotGetRenderedWithDefaultUser() { local DEFAULT_USER=$(whoami) local POWERLEVEL9K_CUSTOM_WORLD='echo world' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) local POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true local DEFAULT_USER=$(whoami) @@ -65,7 +71,8 @@ function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { } function testContextSegmentIsShownIfForced() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) local POWERLEVEL9K_ALWAYS_SHOW_USER=true local DEFAULT_USER=$(whoami) diff --git a/test/segments/custom.spec b/test/segments/custom.spec index dea1577f..261e2508 100755 --- a/test/segments/custom.spec +++ b/test/segments/custom.spec @@ -12,14 +12,16 @@ function setUp() { } function testCustomDirectOutputSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) function p9k_hello_world() { echo "world" } @@ -29,7 +31,8 @@ function testCustomClosureSegment() { } function testSettingBackgroundForCustomSegment() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND="yellow" @@ -37,7 +40,8 @@ function testSettingBackgroundForCustomSegment() { } function testSettingForegroundForCustomSegment() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND="red" @@ -45,7 +49,8 @@ function testSettingForegroundForCustomSegment() { } function testSettingVisualIdentifierForCustomSegment() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw" @@ -53,7 +58,8 @@ function testSettingVisualIdentifierForCustomSegment() { } function testSettingVisualIdentifierForegroundColorForCustomSegment() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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" diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec index efda6f43..f6cc2ee5 100755 --- a/test/segments/detect_virt.spec +++ b/test/segments/detect_virt.spec @@ -12,10 +12,11 @@ function setUp() { } function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt custom_world) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' 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)" @@ -23,7 +24,8 @@ function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { } function testDetectVirtSegmentIfSystemdReturnsPlainName() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" @@ -32,7 +34,8 @@ function testDetectVirtSegmentIfSystemdReturnsPlainName() { } function testDetectVirtSegmentIfRootFsIsOnExpectedInode() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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".. @@ -49,7 +52,8 @@ function testDetectVirtSegmentIfRootFsIsOnExpectedInode() { } function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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".. diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec index 574445d9..f6172c9f 100755 --- a/test/segments/disk_usage.spec +++ b/test/segments/disk_usage.spec @@ -32,11 +32,12 @@ function tearDown() { } function testDiskUsageSegmentWhenDiskIsAlmostFull() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) 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)" @@ -44,11 +45,12 @@ function testDiskUsageSegmentWhenDiskIsAlmostFull() { } function testDiskUsageSegmentWhenDiskIsVeryFull() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) 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)" @@ -56,11 +58,12 @@ function testDiskUsageSegmentWhenDiskIsVeryFull() { } function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) 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)" @@ -68,12 +71,13 @@ function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { } function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShouldBeDisplayed() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage custom_world) 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' @@ -83,11 +87,12 @@ function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShoul } function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) 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)" @@ -96,11 +101,12 @@ function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { } function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) 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 diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 3ae2d389..0d07b6ee 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -12,8 +12,9 @@ function setUp() { } function testIpSegmentPrintsNothingOnOsxIfNotConnected() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) alias networksetup='echo "not connected"' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) local OS="OSX" # Fake OSX local POWERLEVEL9K_CUSTOM_WORLD='echo world' @@ -23,8 +24,9 @@ function testIpSegmentPrintsNothingOnOsxIfNotConnected() { } function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) alias ip='echo "not connected"' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) local OS="Linux" # Fake Linux local POWERLEVEL9K_CUSTOM_WORLD='echo world' @@ -34,7 +36,8 @@ function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { } function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) local OS='OSX' # Fake OSX alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled. (1) Ethernet @@ -69,7 +72,8 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { # 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) local OS='OSX' # Fake OSX alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled. (1) Ethernet @@ -116,7 +120,8 @@ function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { } function testIpSegmentWorksOnOsxWithInterfaceSpecified() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) local OS='OSX' # Fake OSX local POWERLEVEL9K_IP_INTERFACE='xxx' alias ipconfig="_(){ echo '1.2.3.4'; };_" @@ -155,7 +160,8 @@ function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { setopt aliases - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 @@ -185,7 +191,8 @@ function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { } function testIpSegmentWorksOnLinuxWithInterfaceSpecified() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) local OS='Linux' # Fake Linux local POWERLEVEL9K_IP_INTERFACE='xxx' ip(){ diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec index 2fe3594e..b516e5ff 100755 --- a/test/segments/node_version.spec +++ b/test/segments/node_version.spec @@ -12,7 +12,8 @@ function setUp() { } function testNodeVersionSegmentPrintsNothingWithoutNode() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias node="nonode 2>/dev/null" @@ -23,7 +24,8 @@ function testNodeVersionSegmentPrintsNothingWithoutNode() { } function testNodeVersionSegmentWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(node_version) node() { echo "v1.2.3" } diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index bfa1d7fa..511a1a19 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -17,7 +17,8 @@ function setUp() { } function testNodeenvSegmentPrintsNothingWithoutNode() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias node="nonode 2>/dev/null" @@ -27,7 +28,8 @@ function testNodeenvSegmentPrintsNothingWithoutNode() { } function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' node() { echo "v1.2.3" @@ -39,7 +41,8 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { } function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' node() { echo "v1.2.3" @@ -55,7 +58,8 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { } function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) alias node="nonode 2>/dev/null" NODE_VIRTUAL_ENV="node-env" @@ -66,7 +70,8 @@ function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { } function testNodeenvSegmentWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) node() { echo "v1.2.3" } diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index 8f3b3c26..f4a4812a 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -32,14 +32,16 @@ function tearDown() { } function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm) function nvm_version() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' @@ -49,7 +51,8 @@ function testNvmSegmentWorksWithoutHavingADefaultAlias() { } function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' function nvm_version() { diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec index ccf157c9..51fb398f 100755 --- a/test/segments/php_version.spec +++ b/test/segments/php_version.spec @@ -12,7 +12,8 @@ function setUp() { } function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias php="nophp" @@ -22,7 +23,8 @@ function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { } function testPhpVersionSegmentWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index a9c0a770..80dff215 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -36,7 +36,8 @@ function tearDown() { } function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 @@ -49,7 +50,8 @@ function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { } function testPublicIpSegmentPrintsNoticeIfNotConnected() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 @@ -62,7 +64,8 @@ function testPublicIpSegmentPrintsNoticeIfNotConnected() { } function testPublicIpSegmentWorksWithWget() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) alias dig='nodig' alias curl='nocurl' wget() { @@ -77,7 +80,8 @@ function testPublicIpSegmentWorksWithWget() { } function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) alias dig='nodig' alias wget='nowget' curl() { @@ -92,7 +96,8 @@ function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() { } function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) alias curl='nocurl' alias wget='nowget' dig() { @@ -107,7 +112,8 @@ function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable( } function testPublicIpSegmentCachesFile() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) dig() { echo "first" } @@ -125,7 +131,8 @@ function testPublicIpSegmentCachesFile() { } function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) local POWERLEVEL9K_PUBLIC_IP_TIMEOUT=2 dig() { echo "first" @@ -145,7 +152,8 @@ function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { } function testPublicIpSegmentRefreshesCachesFileIfEmpty() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) dig() { echo "first" } @@ -166,7 +174,8 @@ function testPublicIpSegmentRefreshesCachesFileIfEmpty() { } function testPublicIpSegmentWhenGoingOnline() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) local POWERLEVEL9K_PUBLIC_IP_METHODS="dig" local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected" alias dig="nodig" diff --git a/test/segments/ram.spec b/test/segments/ram.spec index 104b8c82..0deaacf9 100755 --- a/test/segments/ram.spec +++ b/test/segments/ram.spec @@ -28,7 +28,6 @@ function tearDown() { } 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. @@ -42,7 +41,6 @@ Pages inactive: 1313411. } 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 @@ -51,7 +49,6 @@ function testRamSegmentWorksOnBsd() { } function testRamSegmentWorksOnLinux() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ram) local OS="Linux" # Fake Linux mkdir proc echo "MemAvailable: 299687" > proc/meminfo diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec index 2ad4341e..a5360072 100755 --- a/test/segments/ssh.spec +++ b/test/segments/ssh.spec @@ -16,7 +16,8 @@ function mockRust() { } function testSshSegmentPrintsNothingIfNoSshConnection() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 @@ -28,7 +29,8 @@ function testSshSegmentPrintsNothingIfNoSshConnection() { } function testSshSegmentWorksIfOnlySshClientIsSet() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) local POWERLEVEL9K_SSH_ICON="ssh-icon" # Weak test: Emulate No SSH connection by unsetting # $SSH_CLIENT and $SSH_TTY @@ -41,7 +43,8 @@ function testSshSegmentWorksIfOnlySshClientIsSet() { } function testSshSegmentWorksIfOnlySshTtyIsSet() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) local POWERLEVEL9K_SSH_ICON="ssh-icon" # Weak test: Emulate No SSH connection by unsetting # $SSH_CLIENT and $SSH_TTY @@ -54,7 +57,8 @@ function testSshSegmentWorksIfOnlySshTtyIsSet() { } function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh) local POWERLEVEL9K_SSH_ICON="ssh-icon" # Weak test: Emulate No SSH connection by unsetting # $SSH_CLIENT and $SSH_TTY diff --git a/test/segments/status.spec b/test/segments/status.spec index 21bd65bb..d921111b 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -17,8 +17,9 @@ function setUp() { } function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status custom_world) local POWERLEVEL9K_STATUS_VERBOSE=false local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false @@ -26,56 +27,63 @@ function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { } function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) assertEquals "%K{black} %F{green%}✔%f %k%F{black}%f " "$(build_left_prompt)" } function testStatusInGeneralErrorCase() { - local RETVAL=1 - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + local RETVAL=1 assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}1 %k%F{red}%f " "$(build_left_prompt)" } function testPipestatusInErrorCase() { - local -a RETVALS - RETVALS=(0 0 1 0) - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true + local -a RETVALS + RETVALS=(0 0 1 0) assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}0|0|1|0 %k%F{red}%f " "$(build_left_prompt)" } function testStatusCrossWinsOverVerbose() { - local RETVAL=1 - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_CROSS=true + local RETVAL=1 assertEquals "%K{black} %F{red%}✘%f %k%F{black}%f " "$(build_left_prompt)" } function testStatusShowsSignalNameInErrorCase() { - local RETVAL=132 - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false + local RETVAL=132 assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}SIGILL(4) %k%F{red}%f " "$(build_left_prompt)" } function testStatusSegmentIntegrated() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) - local POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=() + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=() false; powerlevel9k_prepare_prompts diff --git a/test/segments/swap.spec b/test/segments/swap.spec index 52719395..58f35c0a 100755 --- a/test/segments/swap.spec +++ b/test/segments/swap.spec @@ -28,7 +28,8 @@ function tearDown() { } function testSwapSegmentWorksOnOsx() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) local OS="OSX" # Fake OSX sysctl() { echo "vm.swapusage: total = 3072,00M used = 1620,50M free = 1451,50M (encrypted)" @@ -40,7 +41,8 @@ function testSwapSegmentWorksOnOsx() { } function testSwapSegmentWorksOnLinux() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) local OS="Linux" # Fake Linux mkdir proc echo "SwapTotal: 1000000" > proc/meminfo diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec index e58cc817..5634de11 100755 --- a/test/segments/swift_version.spec +++ b/test/segments/swift_version.spec @@ -28,7 +28,8 @@ function tearDown() { } function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias swift="noswift" @@ -39,7 +40,8 @@ function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() { } function testSwiftSegmentWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swift_version) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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" } diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec index ba0bf96a..65d193b0 100755 --- a/test/segments/symfony_version.spec +++ b/test/segments/symfony_version.spec @@ -28,7 +28,8 @@ function tearDown() { } function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias php="nophp" @@ -38,7 +39,8 @@ function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() { } function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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. @@ -48,7 +50,8 @@ function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() { } function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' mkdir app touch app/AppKernel.php @@ -65,7 +68,8 @@ function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { function testSymfonyVersionSegmentWorks() { startSkipping # Skip test - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) mkdir app touch app/AppKernel.php @@ -80,7 +84,8 @@ function testSymfonyVersionSegmentWorks() { function testSymfonyVersionSegmentWorksInNestedFolder() { startSkipping # Skip test - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(symfony2_version) mkdir app touch app/AppKernel.php diff --git a/test/segments/todo.spec b/test/segments/todo.spec index 0d2d8203..1dae9a68 100755 --- a/test/segments/todo.spec +++ b/test/segments/todo.spec @@ -33,7 +33,8 @@ function tearDown() { } function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo custom_world) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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)" @@ -41,7 +42,8 @@ function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() { function testTodoSegmentWorksAsExpected() { # TODO: Skript in den PATH legen! - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index 9429589d..3ae4077e 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -70,7 +70,8 @@ function tearDown() { } function testColorOverridingForCleanStateWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' @@ -78,7 +79,8 @@ function testColorOverridingForCleanStateWorks() { } function testColorOverridingForModifiedStateWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' @@ -91,7 +93,8 @@ function testColorOverridingForModifiedStateWorks() { } function testColorOverridingForUntrackedStateWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan' local POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow' @@ -108,7 +111,8 @@ function testGitIconWorks() { } function testGitlabIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_GIT_GITLAB_ICON='GL-Icon' # Add a GitLab project as remote origin. This is @@ -119,7 +123,8 @@ function testGitlabIconWorks() { } function testBitbucketIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_GIT_BITBUCKET_ICON='BB-Icon' # Add a BitBucket project as remote origin. This is @@ -130,7 +135,8 @@ function testBitbucketIconWorks() { } function testGitHubIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_GIT_GITHUB_ICON='GH-Icon' # Add a GitHub project as remote origin. This is @@ -141,7 +147,8 @@ function testGitHubIconWorks() { } function testUntrackedFilesIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_UNTRACKED_ICON='?' # Create untracked file @@ -151,7 +158,8 @@ function testUntrackedFilesIconWorks() { } function testStagedFilesIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_STAGED_ICON='+' # Create staged file @@ -165,7 +173,8 @@ function testStagedFilesIconWorks() { } function testUnstagedFilesIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_UNSTAGED_ICON='M' # Create unstaged (modified, but not added to index) file @@ -178,7 +187,8 @@ function testUnstagedFilesIconWorks() { } function testStashIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_STASH_ICON='S' # Create modified file @@ -192,7 +202,8 @@ function testStashIconWorks() { } function testTagIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_TAG_ICON='T' touch "file.txt" @@ -204,7 +215,8 @@ function testTagIconWorks() { } function testTagIconInDetachedHeadState() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_TAG_ICON='T' touch "file.txt" @@ -221,7 +233,8 @@ function testTagIconInDetachedHeadState() { } function testActionHintWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) touch "i-am-modified.txt" git add i-am-modified.txt @@ -240,7 +253,8 @@ function testActionHintWorks() { } function testIncomingHintWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='I' touch "i-am-modified.txt" @@ -258,7 +272,8 @@ function testIncomingHintWorks() { } function testOutgoingHintWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='o' touch "i-am-modified.txt" @@ -276,7 +291,8 @@ function testOutgoingHintWorks() { } function testShorteningCommitHashWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_SHOW_CHANGESET=true local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' @@ -292,7 +308,8 @@ function testShorteningCommitHashWorks() { } function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_SHOW_CHANGESET=false local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 6d8c6428..91d25ae6 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -34,7 +34,8 @@ function tearDown() { } function testColorOverridingForCleanStateWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' @@ -42,7 +43,8 @@ function testColorOverridingForCleanStateWorks() { } function testColorOverridingForModifiedStateWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red' local POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow' @@ -60,7 +62,8 @@ function testColorOverridingForModifiedStateWorks() { # 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) touch "myfile.txt" hg add myfile.txt @@ -70,7 +73,8 @@ function testAddedFilesIconWorks() { # We don't support tagging in mercurial right now.. function testTagIconWorks() { startSkipping # Skip test - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_TAG_ICON='T' touch "file.txt" @@ -83,7 +87,8 @@ function testTagIconWorks() { function testTagIconInDetachedHeadState() { startSkipping # Skip test - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_TAG_ICON='T' touch "file.txt" @@ -100,7 +105,8 @@ function testTagIconInDetachedHeadState() { } function testActionHintWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) touch "i-am-modified.txt" hg add i-am-modified.txt hg commit -m "Add File" &>/dev/null @@ -119,7 +125,8 @@ function testActionHintWorks() { } function testShorteningCommitHashWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_SHOW_CHANGESET=true local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' @@ -136,7 +143,8 @@ function testShorteningCommitHashWorks() { } function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_SHOW_CHANGESET=false local POWERLEVEL9K_CHANGESET_HASH_LENGTH='4' @@ -152,14 +160,16 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { } function testMercurialIconWorks() { - local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_BOOKMARK_ICON='B' hg bookmark "initial" From a8d7cee7867e302b0f256b1b004f693d22cfdc99 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 20 Jul 2018 19:15:40 +0200 Subject: [PATCH 053/103] Add tests for joining segments --- test/core/joining_segments.spec | 187 ++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100755 test/core/joining_segments.spec diff --git a/test/core/joining_segments.spec b/test/core/joining_segments.spec new file mode 100755 index 00000000..708e9bf1 --- /dev/null +++ b/test/core/joining_segments.spec @@ -0,0 +1,187 @@ +#!/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 testLeftNormalSegmentsShouldNotBeJoined() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4_joined custom_world5 custom_world6) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world2 %K{white}%F{black} %F{black}world4 %K{white}%F{black} %F{black}world6 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftTransitiveJoinedSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world3 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftTransitiveJoiningWithConditionalJoinedSegment() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world4 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world3 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %K{white}%F{black}%F{black}world6 %k%F{white}%f " "$(build_left_prompt)" +} + +function testLeftJoiningBuiltinSegmentWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version php_version_joined) + alias php="echo PHP 1.2.3" + + assertEquals "%K{013} %F{255}PHP 1.2.3 %K{013}%F{255}%F{255}PHP 1.2.3 %k%F{fuchsia}%f " "$(build_left_prompt)" + + unalias php +} + +function testRightNormalSegmentsShouldNotBeJoined() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4 custom_world5_joined custom_world6) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world2 %f%F{black}%f%K{white}%F{black} world4 %f%F{black}%f%K{white}%F{black} world6%E" "$(build_right_prompt)" +} + +function testRightJoinedSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2%E" "$(build_right_prompt)" +} + +function testRightTransitiveJoinedSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world3%E" "$(build_right_prompt)" +} + +function testRightTransitiveJoiningWithConditionalJoinedSegment() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world4%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world3%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4%E" "$(build_right_prompt)" +} + +function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined) + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" + local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions + local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" + + assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4 %f%K{white}%F{black}world6%E" "$(build_right_prompt)" +} + +function testRightJoiningBuiltinSegmentWorks() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(php_version php_version_joined) + alias php="echo PHP 1.2.3" + + assertEquals "%F{013}%f%K{013}%F{255} PHP 1.2.3 %f%K{013}%F{255}PHP 1.2.3%E" "$(build_right_prompt)" + + unalias php +} +source shunit2/source/2.1/src/shunit2 \ No newline at end of file From 84c8ddce70415c9c66f4b34e8168824fad284bd8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 20 Jul 2018 21:16:42 +0200 Subject: [PATCH 054/103] Drop support for ZSH < 5.1 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c526e54..0da3abe6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,8 +35,6 @@ env: - _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: From f6087199f96d143b4964d65fe8de5b24cbf03bf0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 20 Jul 2018 22:12:18 +0200 Subject: [PATCH 055/103] Add tests for visual identifier --- test/core/visual_identifier.spec | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 test/core/visual_identifier.spec diff --git a/test/core/visual_identifier.spec b/test/core/visual_identifier.spec new file mode 100755 index 00000000..db9896db --- /dev/null +++ b/test/core/visual_identifier.spec @@ -0,0 +1,50 @@ +#!/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 + source functions/* +} + +function testOverwritingIconsWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%K{white} %F{black%}icon-here %f%F{black}world1 %k%F{white}%f " "$(build_left_prompt)" +} + +function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%K{white} %F{black%}icon-here %f%F{black}world1 %k%F{white}%f " "$(build_left_prompt)" +} + +function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' + + assertEquals "%F{white}%f%K{white}%F{black} world1%F{black%} icon-here%f%E" "$(build_right_prompt)" +} + +function testVisualIdentifierPrintsNothingIfNotAvailable() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + assertEquals "%K{white} %F{black}world1 %k%F{white}%f " "$(build_left_prompt)" +} + +source shunit2/source/2.1/src/shunit2 \ No newline at end of file From 17229ddad762e18cede1c0f7338fec30851f7b9a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Jul 2018 00:01:21 +0200 Subject: [PATCH 056/103] Add tests for general prompt functionality --- test/core/prompt.spec | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 test/core/prompt.spec diff --git a/test/core/prompt.spec b/test/core/prompt.spec new file mode 100755 index 00000000..42518f06 --- /dev/null +++ b/test/core/prompt.spec @@ -0,0 +1,104 @@ +#!/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 testSegmentOnRightSide() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD2='echo world2' + + powerlevel9k_prepare_prompts + + local reset_attributes=$'\e[00m' + assertEquals "%f%b%k%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}" +} + +function testDisablingRightPrompt() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_CUSTOM_WORLD2='echo world2' + local POWERLEVEL9K_DISABLE_RPROMPT=true + + powerlevel9k_prepare_prompts + + assertEquals "" "${(e)RPROMPT}" +} + +function testLeftMultilinePrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "╭─%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}╰─ " "${(e)PROMPT}" +} + +function testRightPromptOnSameLine() { + # Reset RPROMPT, so a running P9K does not interfere with the test + local RPROMPT= + local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS + POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false # We want the RPROMPT on the same line as our left prompt + + # Skip test, as this cannot be tested properly. + # The "go one line up" instruction does not get + # printed as real characters in RPROMPT. + # On command line the assert statement produces + # a visually identical output as we expect, but + # it fails anyway. :( + startSkipping + + powerlevel9k_prepare_prompts + assertEquals "%{\e[1A%}%F{white}%f%K{white}%F{black} world1 %f%{\e[1B%}" "${(e)RPROMPT}" +} + +function testPrefixingFirstLineOnLeftPrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='XXX' + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "XXX%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}╰─ " "${(e)PROMPT}" +} + +function testPrefixingSecondLineOnLeftPrompt() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) + local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' + + local POWERLEVEL9K_PROMPT_ON_NEWLINE=true + local POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX='XXX' + + powerlevel9k_prepare_prompts + + local nl=$'\n' + assertEquals "╭─%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}XXX" "${(e)PROMPT}" +} + +source shunit2/source/2.1/src/shunit2 From 856071716e610967843478a3f7732e28cbd3a3a8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Jul 2018 00:37:06 +0200 Subject: [PATCH 057/103] Fix font issue debugging script --- debug/font-issues.zsh | 322 +++++++++++++++++++++++++++++++++++------- 1 file changed, 274 insertions(+), 48 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 166a6ac5..ea3c4d67 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -1,111 +1,221 @@ #!/usr/bin/env zsh #vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +get_ppid() { + # Get parent process ID of PID. + case "$os" in + "Windows") + ppid="$(ps -p "${1:-$PPID}" | awk '{printf $2}')" + ppid="${ppid/PPID}" + ;; + + "Linux") + ppid="$(grep -i -F "PPid:" "/proc/${1:-$PPID}/status")" + ppid="$(trim "${ppid/PPid:}")" + ;; + + *) + ppid="$(ps -p "${1:-$PPID}" -o ppid=)" + ;; + esac + + printf "%s" "$ppid" +} + +get_process_name() { + # Get PID name. + case "$os" in + "Windows") + name="$(ps -p "${1:-$PPID}" | awk '{printf $8}')" + name="${name/COMMAND}" + name="${name/*\/}" + ;; + + "Linux") + name="$(< "/proc/${1:-$PPID}/comm")" + ;; + + *) + name="$(ps -p "${1:-$PPID}" -o comm=)" + ;; + esac + + printf "%s" "$name" +} + # Taken from NeoFetch (slightly modified) get_term() { local term + # If function was run, stop here. - #((term_run == 1)) && return + # ((term_run == 1)) && return # Workaround for macOS systems that # don't support the block below. case "$TERM_PROGRAM" in - "iTerm.app") term="iTerm2" ;; + "iTerm.app") term="iTerm2" ;; "Terminal.app") term="Apple Terminal" ;; - "Hyper") term="HyperTerm" ;; - *) term="${TERM_PROGRAM/\.app}" ;; + "Hyper") term="HyperTerm" ;; + *) term="${TERM_PROGRAM/\.app}" ;; esac + # Most likely TosWin2 on FreeMiNT - quick check + [[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \ + term="TosWin2" + + [[ "$SSH_CONNECTION" ]] && \ + term="$SSH_TTY" + # Check $PPID for terminal emulator. while [[ -z "$term" ]]; do parent="$(get_ppid "$parent")" + [[ -z "$parent" ]] && break name="$(get_process_name "$parent")" case "${name// }" in - "${SHELL/*\/}" | *"sh" | "tmux"* | "screen" | "su"*) ;; - "login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;; - "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) break ;; + "${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;; + + "login"*|*"Login"*|"init"|"(init)") + term="$(tty)" + ;; + + "ruby"|"1"|"tmux"*|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*) + break + ;; + "gnome-terminal-") term="gnome-terminal" ;; - *) term="${name##*/}" ;; + "urxvtd") term="urxvt" ;; + *"nvim") term="Neovim Terminal" ;; + *"NeoVimServer"*) term="VimR Terminal" ;; + *) term="${name##*/}" ;; esac done # Log that the function was run. - #term_run=1 + # term_run=1 echo "${term}" } get_term_font() { local term="${1}" - #((term_run != 1)) && get_term + # ((term_run != 1)) && get_term case "$term" in "alacritty"*) - term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${XDG_CONFIG_HOME}/alacritty/alacritty.yml")" + shopt -s nullglob + confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?) + shopt -u nullglob + + [[ -f "${confs[0]}" ]] || return + + term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")" term_font="${term_font/*family:}" term_font="${term_font/$'\n'*}" term_font="${term_font/\#*}" ;; "Apple_Terminal") - term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')" + term_font="$(osascript </dev/null | grep -c "Guid") - for idx in $(seq 0 "${profilesCount}"); do - local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) - if [[ "${profileName}" == "${currentProfileName}" ]]; then + profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" | \ + grep -w -c "Guid")" + + for ((i=0; i Date: Sat, 21 Jul 2018 22:52:08 +0200 Subject: [PATCH 058/103] Resolve #918 Transparent background Now function getColorCode consider value 'none' like a good value. When it's use to set background the segment become transparent --- functions/colors.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/functions/colors.zsh b/functions/colors.zsh index e98bfd4f..81e96ae1 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -79,6 +79,10 @@ function getColorCode() { else echo -n "$1" fi + # Check if value is none with any case. + elif [[ $1 = [nN][oO][nN][eE] ]] + then + echo -n 'none' else typeset -A codes # https://jonasjacek.github.io/colors/ From 5ce384fb315528cefb33e76793f27c6b7936185a Mon Sep 17 00:00:00 2001 From: Ythildir Date: Sun, 22 Jul 2018 00:21:59 +0200 Subject: [PATCH 059/103] Test more readable --- functions/colors.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 81e96ae1..7befbb2c 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -80,7 +80,7 @@ function getColorCode() { echo -n "$1" fi # Check if value is none with any case. - elif [[ $1 = [nN][oO][nN][eE] ]] + elif [[ "${(L)1}" == "none" ]] then echo -n 'none' else From f89a5bb365abac051666f7f12ae7646f457caa72 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Jul 2018 17:15:43 +0200 Subject: [PATCH 060/103] Fix debug/font-issues.zsh - Add trim function - Make our $OS and neofetchs $os compatible --- debug/font-issues.zsh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index ea3c4d67..e73830f0 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -1,6 +1,21 @@ #!/usr/bin/env zsh #vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 +source functions/colors.zsh +source functions/icons.zsh +source functions/utilities.zsh +# Map our $OS to neofetch $os +os="$OS" + + +trim() { + set -f + # shellcheck disable=2048,2086 + set -- $* + printf '%s\n' "${*//[[:space:]]/ }" + set +f +} + get_ppid() { # Get parent process ID of PID. case "$os" in From ebd4414c29014b5cc46a8aee87337684fbcefb9f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Jul 2018 02:16:03 +0200 Subject: [PATCH 061/103] Fix trimming of whitespace in debug/font-issues.zsh --- debug/font-issues.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index e73830f0..82f8e60b 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -12,7 +12,7 @@ trim() { set -f # shellcheck disable=2048,2086 set -- $* - printf '%s\n' "${*//[[:space:]]/ }" + printf '%s\n' "${*//[[:space:]]/}" set +f } From acaf8c6087af4771a5084fef854491c6ec50adca Mon Sep 17 00:00:00 2001 From: xufab Date: Tue, 24 Jul 2018 00:37:24 +0200 Subject: [PATCH 062/103] Missing `etc` state for the `dir` segment in docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9989d9cc..51c68d70 100644 --- a/README.md +++ b/README.md @@ -386,12 +386,14 @@ Powerline" fonts, there are additional glyphs, as well: | None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183451/40ec4016-b58f-11e5-9b9e-74e2b2f0b8b3.png) | At the root of your home folder | | None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12369315/8a5d762c-bbf5-11e5-8a20-ca1179f48d6c.png) | Within a subfolder of your home directory | | None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder | +| None | None | ⚙ | Within the `/etc` directory | To turn off these icons you could set these variables to an empty string. ```zsh POWERLEVEL9K_HOME_ICON='' POWERLEVEL9K_HOME_SUB_ICON='' POWERLEVEL9K_FOLDER_ICON='' +POWERLEVEL9K_ETC_ICON='' ``` You can limit the output to a certain length by truncating long paths. Customizations available are: From 345cf87b8f1f1c9b7e1396b7ab2fd9c4400a8cd0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Jul 2018 00:51:37 +0200 Subject: [PATCH 063/103] Add missing colors to fix color comparison Added magenta and cyan that were only present with their alternative names (fuchsia and aqua). See https://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors_in_the_CSS_color_scheme --- functions/colors.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/colors.zsh b/functions/colors.zsh index e98bfd4f..9309a225 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -97,7 +97,9 @@ function getColorCode() { codes[yellow]=011 codes[blue]=012 codes[fuchsia]=013 + codes[magenta]=013 codes[aqua]=014 + codes[cyan]=014 codes[white]=015 codes[grey0]=016 codes[navyblue]=017 From 822b820a6e0d7cec4ec60de23faecec6b77712b6 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Jul 2018 01:22:19 +0200 Subject: [PATCH 064/103] Improve guide for testing --- TESTS.md | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/TESTS.md b/TESTS.md index eb5db704..b57c4d6d 100644 --- a/TESTS.md +++ b/TESTS.md @@ -1,25 +1,45 @@ -# Structure +# Tests -The Unit-Tests do not follow exactly the file structure of Powerlevel9k itself. +## Automated Tests -## Basic Tests +The Unit-Tests do not follow exactly the file structure of Powerlevel9k itself, +but we try to reflect the structure as much as possible. All tests are located +under `test/`. Segment specific tests under `test/segments/` (one file per +segment). -Basic Tests belong in `test/powerlevel9k.spec` if they test basic functionality of -Powerlevel9k itself. Basic functions from the `functions` directory have their -Tests in separate files under `test/functions`. +### Installation -## Segment Tests +In order to execute the tests you need to install `shunit2`, which is a +submodule. To install the submodule, you can execute +`git submodule init && git submodule update`. -These Tests tend to be more complex in setup than the basic tests. To avoid ending -up in a huge single file, there is one file per segment in `test/segments`. +### Executing tests -# Manual Testing +The tests are shell scripts on their own. So you can execute them right away. +To execute all tests you could just execute `./test/suite.spec`. + +### General Test Structure + +The tests usually have a `setUp()` function which is executed before every +test function. Speaking of, test functions must be prefixed with `test`. In +the tests, you can do [different Assertions](https://github.com/kward/shunit2#-asserts). +It is always a good idea to mock the program you want to test (just have a +look at other tests), so that the testrunner does not have to have all +programs installed. + +### Travis + +We use [Travis](https://travis-ci.org/) for Continuous Integration. This +service executes our tests after every push. For now, we need to tell travis +where to find the tests, which is what happens in the `.travis.yml` file. + +## Manual Testing If unit tests are not sufficient (e.g. you have an issue with your prompt that occurs only in a specific ZSH framework) then you can use either Docker or or our Vagrant. -## Docker +### Docker This is the easiest to use _if_ you have Docker already installed and running. @@ -42,7 +62,7 @@ You can get Docker at . **Note:** Not all frameworks work with all versions of ZSH (or the underlying OS). -## Vagrant +### Vagrant Currently there are two test VMs. `test-vm` is an Ubuntu machine with several pre-installed ZSH frameworks. And there is `test-bsd-vm` which is a FreeBSD! From 4972f0b8eba711f0dafc46cdbb4e191d550da091 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Jul 2018 16:24:33 +0200 Subject: [PATCH 065/103] Improve tests by making use of local variables --- test/functions/icons.spec | 26 +- test/segments/command_execution_time.spec | 60 ++-- test/segments/detect_virt.spec | 1 - test/segments/dir.spec | 316 ++++++++++------------ test/segments/go_version.spec | 32 +-- test/segments/kubecontext.spec | 15 +- test/segments/laravel_version.spec | 27 +- test/segments/rust_version.spec | 11 +- 8 files changed, 207 insertions(+), 281 deletions(-) diff --git a/test/functions/icons.spec b/test/functions/icons.spec index c8d88644..068062e6 100755 --- a/test/functions/icons.spec +++ b/test/functions/icons.spec @@ -10,21 +10,15 @@ function setUp() { _OLD_LC_CTYPE="${LC_CTYPE}" # Reset actual LC_CTYPE unset LC_CTYPE - - # Store old P9K mode - _OLD_P9K_MODE="${POWERLEVEL9K_MODE}" } function tearDown() { # Restore LC_CTYPE LC_CTYPE="${_OLD_LC_CTYPE}" - - # Restore old P9K mode - POWERLEVEL9K_MODE="${_OLD_P9K_MODE}" } function testLcCtypeIsSetCorrectlyInDefaultMode() { - POWERLEVEL9K_MODE="default" + local POWERLEVEL9K_MODE="default" # Load Powerlevel9k source functions/icons.zsh @@ -32,7 +26,7 @@ function testLcCtypeIsSetCorrectlyInDefaultMode() { } function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { - POWERLEVEL9K_MODE="awesome-patched" + local POWERLEVEL9K_MODE="awesome-patched" # Load Powerlevel9k source functions/icons.zsh @@ -40,7 +34,7 @@ function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { } function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { - POWERLEVEL9K_MODE="awesome-fontconfig" + local POWERLEVEL9K_MODE="awesome-fontconfig" # Load Powerlevel9k source functions/icons.zsh @@ -48,7 +42,7 @@ function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { } function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { - POWERLEVEL9K_MODE="nerdfont-fontconfig" + local POWERLEVEL9K_MODE="nerdfont-fontconfig" # Load Powerlevel9k source functions/icons.zsh @@ -56,7 +50,7 @@ function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { } function testLcCtypeIsSetCorrectlyInFlatMode() { - POWERLEVEL9K_MODE="flat" + local POWERLEVEL9K_MODE="flat" # Load Powerlevel9k source functions/icons.zsh @@ -64,7 +58,7 @@ function testLcCtypeIsSetCorrectlyInFlatMode() { } function testLcCtypeIsSetCorrectlyInCompatibleMode() { - POWERLEVEL9K_MODE="compatible" + local POWERLEVEL9K_MODE="compatible" # Load Powerlevel9k source functions/icons.zsh @@ -76,7 +70,7 @@ function testLcCtypeIsSetCorrectlyInCompatibleMode() { function testAllIconsAreDefinedLikeInDefaultMode() { # Always compare against this mode local _P9K_TEST_MODE="default" - POWERLEVEL9K_MODE="${_P9K_TEST_MODE}" + local POWERLEVEL9K_MODE="${_P9K_TEST_MODE}" source functions/icons.zsh # _ICONS_UNDER_TEST is an array of just the keys of $icons. # We later check via (r) "subscript" flag that our key @@ -148,7 +142,7 @@ function testAllIconsAreDefinedLikeInDefaultMode() { function testAllIconsAreDefinedLikeInAwesomePatchedMode() { # Always compare against this mode local _P9K_TEST_MODE="awesome-patched" - POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" source functions/icons.zsh # _ICONS_UNDER_TEST is an array of just the keys of $icons. # We later check via (r) "subscript" flag that our key @@ -220,7 +214,7 @@ function testAllIconsAreDefinedLikeInAwesomePatchedMode() { function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { # Always compare against this mode local _P9K_TEST_MODE="awesome-fontconfig" - POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" source functions/icons.zsh # _ICONS_UNDER_TEST is an array of just the keys of $icons. # We later check via (r) "subscript" flag that our key @@ -292,7 +286,7 @@ function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() { # Always compare against this mode local _P9K_TEST_MODE="nerdfont-fontconfig" - POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" source functions/icons.zsh # _ICONS_UNDER_TEST is an array of just the keys of $icons. # We later check via (r) "subscript" flag that our key diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index d3588d83..7700aaa1 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -12,85 +12,65 @@ function setUp() { } function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time) - POWERLEVEL9K_CUSTOM_WORLD='echo world' - _P9K_COMMAND_DURATION=2 + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local _P9K_COMMAND_DURATION=2 assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD - unset _P9K_COMMAND_DURATION } function testCommandExecutionTimeThresholdCouldBeChanged() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 - _P9K_COMMAND_DURATION=2.03 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 + local _P9K_COMMAND_DURATION=2.03 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION - unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD } function testCommandExecutionTimeThresholdCouldBeSetToZero() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 - _P9K_COMMAND_DURATION=0.03 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 + local _P9K_COMMAND_DURATION=0.03 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION - unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD } function testCommandExecutionTimePrecisionCouldBeChanged() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 - POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 - _P9K_COMMAND_DURATION=0.0001 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 + local _P9K_COMMAND_DURATION=0.0001 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION - unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION - unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD } function testCommandExecutionTimePrecisionCouldBeSetToZero() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 - _P9K_COMMAND_DURATION=23.5001 + local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 + local _P9K_COMMAND_DURATION=23.5001 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION - unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION } function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - _P9K_COMMAND_DURATION=180 + local _P9K_COMMAND_DURATION=180 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION } function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) - _P9K_COMMAND_DURATION=7200 + local _P9K_COMMAND_DURATION=7200 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset _P9K_COMMAND_DURATION } 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 index f6cc2ee5..2dad6af0 100755 --- a/test/segments/detect_virt.spec +++ b/test/segments/detect_virt.spec @@ -17,7 +17,6 @@ function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias systemd-detect-virt="novirt" - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias systemd-detect-virt diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 3e66e918..df80b23c 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -9,17 +9,12 @@ function setUp() { export TERM="xterm-256color" # Load Powerlevel9k source powerlevel9k.zsh-theme - - # Every test should at least use the dir segment - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) -} - -function tearDown() { - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testDirPathAbsoluteWorks() { - POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true cd ~ @@ -33,14 +28,15 @@ function testDirPathAbsoluteWorks() { fi cd - - unset POWERLEVEL9K_DIR_PATH_ABSOLUTE } function testTruncateFoldersWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -48,18 +44,16 @@ function testTruncateFoldersWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateFolderWithHomeDirWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - CURRENT_DIR=$(pwd) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + local CURRENT_DIR=$(pwd) cd ~ - FOLDER="powerlevel9k-test-${RANDOM}" + local FOLDER="powerlevel9k-test-${RANDOM}" mkdir -p $FOLDER cd $FOLDER # Switch back to home folder as this causes the problem. @@ -69,17 +63,15 @@ function testTruncateFolderWithHomeDirWorks() { rmdir $FOLDER cd ${CURRENT_DIR} - - unset CURRENT_DIR - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH } function testTruncateMiddleWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -87,17 +79,15 @@ function testTruncateMiddleWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncationFromRightWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -105,17 +95,15 @@ function testTruncationFromRightWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateToLastWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -123,17 +111,15 @@ function testTruncateToLastWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateToFirstAndLastWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -141,17 +127,15 @@ function testTruncateToFirstAndLastWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateAbsoluteWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -159,18 +143,16 @@ function testTruncateAbsoluteWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncationFromRightWithEmptyDelimiter() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_DELIMITER="" - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_DELIMITER="" + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -178,16 +160,12 @@ function testTruncationFromRightWithEmptyDelimiter() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_DELIMITER - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateWithFolderMarkerWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 @@ -199,16 +177,13 @@ function testTruncateWithFolderMarkerWorks() { cd - rm -fr $BASEFOLDER - unset BASEFOLDER - unset FOLDER - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testTruncateWithFolderMarkerWithChangedFolderMarker() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" - POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 @@ -220,11 +195,6 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { cd - rm -fr $BASEFOLDER - unset BASEFOLDER - unset FOLDER - unset POWERLEVEL9K_SHORTEN_FOLDER_MARKER - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testTruncateWithPackageNameWorks() { @@ -245,18 +215,16 @@ function testTruncateWithPackageNameWorks() { # Go back to deeper folder cd "${FOLDER}" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder rm -fr $BASEFOLDER - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH } function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { @@ -284,18 +252,16 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { # Go to deep folder inside linked repo cd linked-repo/asdfasdf/qwerqwer + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder rm -fr $BASEFOLDER - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH } function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { @@ -319,60 +285,61 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { cd linked-repo/.git/refs/heads + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" # Go back cd $p9kFolder rm -fr $BASEFOLDER - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH } function testHomeFolderDetectionWorks() { - POWERLEVEL9K_HOME_ICON='home-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_ICON='home-icon' cd ~ assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_HOME_ICON } function testHomeSubfolderDetectionWorks() { - POWERLEVEL9K_HOME_SUB_ICON='sub-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_SUB_ICON='sub-icon' - FOLDER=~/powerlevel9k-test + local FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER - unset FOLDER - unset POWERLEVEL9K_HOME_SUB_ICON } function testOtherFolderDetectionWorks() { - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_FOLDER_ICON='folder-icon' - FOLDER=/tmp/powerlevel9k-test + local FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER - unset FOLDER - unset POWERLEVEL9K_FOLDER_ICON } function testChangingDirPathSeparator() { - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local FOLDER="/tmp/powerlevel9k-test/1/2" mkdir -p $FOLDER cd $FOLDER @@ -380,12 +347,12 @@ function testChangingDirPathSeparator() { assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - - unset FOLDER rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR } function testHomeFolderAbbreviation() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION local dir=$PWD @@ -411,21 +378,23 @@ function testHomeFolderAbbreviation() { } function testOmittingFirstCharacterWorks() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_FOLDER_ICON - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER } function testOmittingFirstCharacterWorksWithChangingPathSeparator() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_FOLDER_ICON='folder-icon' mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -433,9 +402,6 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_FOLDER_ICON - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER } # This test makes it obvious that combining a truncation strategy @@ -446,10 +412,12 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { # But it does more sense in combination with other truncation # strategies. function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -457,17 +425,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -475,17 +441,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -493,17 +457,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateToUniqueWorks() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' mkdir -p /tmp/powerlevel9k-test/adam/devl mkdir -p /tmp/powerlevel9k-test/alice/devl mkdir -p /tmp/powerlevel9k-test/alice/docs @@ -514,24 +476,23 @@ function testTruncateToUniqueWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testBoldHomeDirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd ~ assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -539,31 +500,34 @@ function testBoldHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootDirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd / assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd /tmp assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -571,21 +535,23 @@ function testBoldRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testHighlightHomeWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd ~ assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -593,31 +559,34 @@ function testHighlightHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd / assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd /tmp assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -625,11 +594,12 @@ function testHighlightRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testDirSeparatorColorHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -637,11 +607,12 @@ function testDirSeparatorColorHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND } function testDirSeparatorColorRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -649,7 +620,6 @@ function testDirSeparatorColorRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND } source shunit2/source/2.1/src/shunit2 diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 3ff0b0e6..1be2e8c8 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -35,51 +35,43 @@ function mockGoEmptyGopath() { function testGo() { alias go=mockGo - POWERLEVEL9K_GO_ICON="" + local POWERLEVEL9K_GO_ICON="" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version) - PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" + local PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_GO_ICON - unset PWD - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias go } function testGoSegmentPrintsNothingIfEmptyGopath() { - alias go=mockGoEmptyGopath - POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=mockGoEmptyGopath assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD - } function testGoSegmentPrintsNothingIfNotInGopath() { - alias go=mockGo - POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=mockGo assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD } function testGoSegmentPrintsNothingIfGoIsNotAvailable() { - alias go=noGo - POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias go=noGo assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD unalias go } diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 63810378..46fe8724 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -66,32 +66,31 @@ function mockKubectlOtherNamespace() { } function testKubeContext() { - alias kubectl=mockKubectl + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + alias kubectl=mockKubectl assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl } function testKubeContextOtherNamespace() { - alias kubectl=mockKubectlOtherNamespace + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + alias kubectl=mockKubectlOtherNamespace assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl } function testKubeContextPrintsNothingIfKubectlNotAvailable() { - alias kubectl=noKubectl - POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + alias kubectl=noKubectl assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD unalias kubectl } diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index 40b130d2..9d3de2d4 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -27,42 +27,37 @@ function mockNoLaravelVersion() { } function testLaravelVersionSegment() { - alias php=mockLaravelVersion - POWERLEVEL9K_LARAVEL_ICON='x' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=mockLaravelVersion assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_LARAVEL_ICON unalias php } function testLaravelVersionSegmentIfArtisanIsNotAvailable() { - alias php=mockNoLaravelVersion - POWERLEVEL9K_CUSTOM_WORLD='echo world' - POWERLEVEL9K_LARAVEL_ICON='x' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=mockNoLaravelVersion assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_LARAVEL_ICON - unset POWERLEVEL9K_CUSTOM_WORLD unalias php } function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { - alias php=noPhp - POWERLEVEL9K_CUSTOM_WORLD='echo world' - POWERLEVEL9K_LARAVEL_ICON='x' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' + local POWERLEVEL9K_LARAVEL_ICON='x' + alias php=noPhp assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_LARAVEL_ICON - unset POWERLEVEL9K_CUSTOM_WORLD unalias php } diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 34883a10..3d627498 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -29,22 +29,19 @@ function mockRust() { } function testRust() { - mockRust + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) + mockRust assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testRustPrintsNothingIfRustIsNotAvailable() { - POWERLEVEL9K_CUSTOM_WORLD='echo world' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) + local POWERLEVEL9K_CUSTOM_WORLD='echo world' assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_CUSTOM_WORLD } source shunit2/source/2.1/src/shunit2 From 99f0eddd62806f99b8116e3f327689bc32529d5d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 24 Jul 2018 16:34:10 +0200 Subject: [PATCH 066/103] Add tests for nerdfont-complete icons --- test/functions/icons.spec | 117 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/test/functions/icons.spec b/test/functions/icons.spec index 068062e6..d4ddc805 100755 --- a/test/functions/icons.spec +++ b/test/functions/icons.spec @@ -115,6 +115,15 @@ function testAllIconsAreDefinedLikeInDefaultMode() { assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" done + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + # Switch to "flat" mode POWERLEVEL9K_MODE="flat" source functions/icons.zsh @@ -187,6 +196,15 @@ function testAllIconsAreDefinedLikeInAwesomePatchedMode() { assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" done + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + # Switch to "flat" mode POWERLEVEL9K_MODE="flat" source functions/icons.zsh @@ -259,6 +277,15 @@ function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" done + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + # Switch to "flat" mode POWERLEVEL9K_MODE="flat" source functions/icons.zsh @@ -331,6 +358,96 @@ function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() { assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" done + # Switch to "nerdfont-complete" mode + POWERLEVEL9K_MODE="nerdfont-complete" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in nerdfont-complete mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInNerdfontCompleteMode() { + # Always compare against this mode + local _P9K_TEST_MODE="nerdfont-complete" + local POWERLEVEL9K_MODE="$_P9K_TEST_MODE" + source functions/icons.zsh + # _ICONS_UNDER_TEST is an array of just the keys of $icons. + # We later check via (r) "subscript" flag that our key + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + # Switch to "flat" mode POWERLEVEL9K_MODE="flat" source functions/icons.zsh From 06de83cc0f2282b2217c6151277dfd6789593c2e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Jul 2018 07:52:06 +0200 Subject: [PATCH 067/103] Prepare tests for performance optimizations --- test/segments/anaconda.spec | 31 +++-- test/segments/aws_eb_env.spec | 25 ++-- test/segments/background_jobs.spec | 14 +- test/segments/battery.spec | 1 + test/segments/command_execution_time.spec | 32 ++++- test/segments/context.spec | 25 +++- test/segments/custom.spec | 20 ++- test/segments/detect_virt.spec | 12 ++ test/segments/dir.spec | 160 +++++++++++++++++++++- test/segments/disk_usage.spec | 23 +++- test/segments/go_version.spec | 14 +- test/segments/ip.spec | 56 +++++--- test/segments/kubecontext.spec | 11 +- test/segments/laravel_version.spec | 11 +- test/segments/load.spec | 28 ++-- test/segments/node_version.spec | 9 +- test/segments/nodeenv.spec | 17 ++- test/segments/nvm.spec | 11 +- test/segments/php_version.spec | 8 +- test/segments/public_ip.spec | 29 +++- test/segments/ram.spec | 17 ++- test/segments/rust_version.spec | 8 +- test/segments/ssh.spec | 18 ++- test/segments/status.spec | 24 +++- test/segments/swap.spec | 12 +- test/segments/swift_version.spec | 7 +- test/segments/symfony_version.spec | 17 ++- test/segments/todo.spec | 8 +- test/segments/vcs-git.spec | 60 +++++++- test/segments/vcs-hg.spec | 32 ++++- test/segments/vi_mode.spec | 14 +- 31 files changed, 641 insertions(+), 113 deletions(-) diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec index da87c096..2aa8d272 100755 --- a/test/segments/anaconda.spec +++ b/test/segments/anaconda.spec @@ -7,14 +7,16 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda custom_world) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + # Unset anacona variables unset CONDA_ENV_PATH unset CONDA_PREFIX @@ -23,34 +25,45 @@ function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { } function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { - CONDA_ENV_PATH=/tmp - unset CONDA_PREFIX local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) local POWERLEVEL9K_PYTHON_ICON="icon-here" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + CONDA_ENV_PATH=/tmp + unset CONDA_PREFIX + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda) local POWERLEVEL9K_PYTHON_ICON="icon-here" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + unset CONDA_ENV_PATH + local CONDA_PREFIX="test" + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS 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)" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local CONDA_ENV_PATH=/tmp + local CONDA_PREFIX="test" + + 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 index 56042027..42740ea6 100755 --- a/test/segments/aws_eb_env.spec +++ b/test/segments/aws_eb_env.spec @@ -7,24 +7,30 @@ 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) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env custom_world) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/.elasticbeanstalk echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml cd /tmp/powerlevel9k-test - local -a 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 @@ -35,14 +41,17 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirec # Skip test, because currently we cannot detect # if the configuration is in a parent directory startSkipping # Skip test + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(aws_eb_env) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - 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 diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index 5a000b66..c38f2d17 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { @@ -17,6 +15,9 @@ function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs custom_world) alias jobs="nojobs 2>/dev/null" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias jobs @@ -30,6 +31,9 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { echo '[1] + 30444 suspended nvim xx' } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)" unfunction jobs @@ -45,6 +49,9 @@ function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { echo "[3] + 31206 suspended nvim xx3" } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{cyan%}⚙%f %k%F{black}%f " "$(build_left_prompt)" unfunction jobs @@ -60,6 +67,9 @@ function testBackgroundJobsSegmentWithVerboseMode() { echo "[3] + 31206 suspended nvim xx3" } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{cyan%}⚙ %f%F{cyan}3 %k%F{black}%f " "$(build_left_prompt)" unfunction jobs diff --git a/test/segments/battery.spec b/test/segments/battery.spec index e49c3b34..835e1468 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -37,6 +37,7 @@ function tearDown() { unset PMSET_PATH unset BATTERY_PATH unset FOLDER + unset P9K_HOME } # Mock Battery diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index 7700aaa1..65623a00 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -7,14 +7,17 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time) local POWERLEVEL9K_CUSTOM_WORLD='echo world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=2 assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" @@ -24,6 +27,11 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=2.03 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)" @@ -43,6 +51,11 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=0.0001 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)" @@ -52,6 +65,11 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=23.5001 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)" @@ -60,6 +78,11 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=180 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)" @@ -68,6 +91,11 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + + # Override payload local _P9K_COMMAND_DURATION=7200 assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" diff --git a/test/segments/context.spec b/test/segments/context.spec index 702280df..b350caf7 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme # Test specific settings OLD_DEFAULT_USER=$DEFAULT_USER @@ -26,6 +24,9 @@ function testContextSegmentDoesNotGetRenderedWithDefaultUser() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context custom_world) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -34,6 +35,9 @@ function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" } @@ -41,14 +45,20 @@ function testContextSegmentWithForeignUser() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" } # TODO: How to test root? function testContextSegmentWithRootUser() { + startSkipping # Skip test local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) - startSkipping # Skip test + + # Load Powerlevel9k + source powerlevel9k.zsh-theme assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" } @@ -58,6 +68,9 @@ function testOverridingContextTemplate() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) local POWERLEVEL9K_CONTEXT_TEMPLATE=xx + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}xx %k%F{black}%f " "$(build_left_prompt)" } @@ -67,6 +80,9 @@ function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { local POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true local DEFAULT_USER=$(whoami) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" } @@ -76,6 +92,9 @@ function testContextSegmentIsShownIfForced() { local POWERLEVEL9K_ALWAYS_SHOW_USER=true local DEFAULT_USER=$(whoami) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}$(whoami) %k%F{black}%f " "$(build_left_prompt)" } diff --git a/test/segments/custom.spec b/test/segments/custom.spec index 261e2508..b7719d1c 100755 --- a/test/segments/custom.spec +++ b/test/segments/custom.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testCustomDirectOutputSegment() { @@ -16,6 +14,9 @@ function testCustomDirectOutputSegment() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world) local POWERLEVEL9K_CUSTOM_WORLD="echo world" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -26,6 +27,9 @@ function testCustomClosureSegment() { echo "world" } local POWERLEVEL9K_CUSTOM_WORLD='p9k_hello_world' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -36,6 +40,9 @@ function testSettingBackgroundForCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND="yellow" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{black}world %k%F{yellow}%f " "$(build_left_prompt)" } @@ -45,6 +52,9 @@ function testSettingForegroundForCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND="red" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{red}world %k%F{white}%f " "$(build_left_prompt)" } @@ -54,6 +64,9 @@ function testSettingVisualIdentifierForCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD="echo world" local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -64,6 +77,9 @@ function testSettingVisualIdentifierForegroundColorForCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD_ICON="hw" local POWERLEVEL9K_CUSTOM_WORLD_VISUAL_IDENTIFIER_COLOR="red" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{red%}hw %f%F{black}world %k%F{white}%f " "$(build_left_prompt)" } diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec index 2dad6af0..7df92a24 100755 --- a/test/segments/detect_virt.spec +++ b/test/segments/detect_virt.spec @@ -17,6 +17,9 @@ function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias systemd-detect-virt="novirt" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias systemd-detect-virt @@ -27,6 +30,9 @@ function testDetectVirtSegmentIfSystemdReturnsPlainName() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(detect_virt) alias systemd-detect-virt="echo 'xxx'" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow}xxx %k%F{black}%f " "$(build_left_prompt)" unalias systemd-detect-virt @@ -40,6 +46,9 @@ function testDetectVirtSegmentIfRootFsIsOnExpectedInode() { # directory having the inode number "2".. alias systemd-detect-virt="echo 'none'" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + # 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'" @@ -58,6 +67,9 @@ function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() { # directory having the inode number "2".. alias systemd-detect-virt="echo 'none'" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + # 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'" diff --git a/test/segments/dir.spec b/test/segments/dir.spec index df80b23c..1f0440cd 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -7,8 +7,12 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme + + P9K_HOME="${PWD}" +} + +function tearDown() { + unset P9K_HOME } function testDirPathAbsoluteWorks() { @@ -16,6 +20,9 @@ function testDirPathAbsoluteWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ # Unfortunately, we cannot fake Linux or OSX here, because @@ -36,6 +43,9 @@ function testTruncateFoldersWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -52,6 +62,9 @@ function testTruncateFolderWithHomeDirWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 local CURRENT_DIR=$(pwd) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ local FOLDER="powerlevel9k-test-${RANDOM}" mkdir -p $FOLDER @@ -71,6 +84,9 @@ function testTruncateMiddleWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -87,6 +103,9 @@ function testTruncationFromRightWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -103,6 +122,9 @@ function testTruncateToLastWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -119,6 +141,9 @@ function testTruncateToFirstAndLastWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -135,6 +160,9 @@ function testTruncateAbsoluteWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -152,6 +180,9 @@ function testTruncationFromRightWithEmptyDelimiter() { local POWERLEVEL9K_SHORTEN_DELIMITER="" local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -167,6 +198,9 @@ function testTruncateWithFolderMarkerWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 mkdir -p $FOLDER @@ -185,6 +219,9 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 mkdir -p $FOLDER @@ -220,6 +257,9 @@ function testTruncateWithPackageNameWorks() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" # Go back @@ -257,6 +297,9 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" # Go back @@ -290,6 +333,9 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" # Go back @@ -302,6 +348,9 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_HOME_ICON='home-icon' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" @@ -313,6 +362,9 @@ function testHomeSubfolderDetectionWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_HOME_SUB_ICON='sub-icon' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER @@ -327,6 +379,9 @@ function testOtherFolderDetectionWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_FOLDER_ICON='folder-icon' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER @@ -340,6 +395,10 @@ function testChangingDirPathSeparator() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER="/tmp/powerlevel9k-test/1/2" mkdir -p $FOLDER cd $FOLDER @@ -353,25 +412,40 @@ function testChangingDirPathSeparator() { function testHomeFolderAbbreviation() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION local dir=$PWD cd ~/ # default - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" # substituted - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)" cd /tmp # default - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" # substituted - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" cd "$dir" @@ -382,6 +456,10 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" @@ -395,6 +473,10 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -418,6 +500,10 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -434,6 +520,10 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -450,6 +540,10 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -466,6 +560,10 @@ function testTruncateToUniqueWorks() { local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/adam/devl mkdir -p /tmp/powerlevel9k-test/alice/devl mkdir -p /tmp/powerlevel9k-test/alice/docs @@ -482,6 +580,10 @@ function testBoldHomeDirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" @@ -493,6 +595,10 @@ function testBoldHomeSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -506,6 +612,10 @@ function testBoldRootDirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd / assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)" @@ -517,6 +627,10 @@ function testBoldRootSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)" @@ -528,6 +642,10 @@ function testBoldRootSubSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -541,6 +659,10 @@ function testHighlightHomeWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)" @@ -552,6 +674,10 @@ function testHighlightHomeSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -565,6 +691,10 @@ function testHighlightRootWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd / assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)" @@ -576,6 +706,10 @@ function testHighlightRootSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)" @@ -587,6 +721,10 @@ function testHighlightRootSubSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -600,6 +738,10 @@ function testDirSeparatorColorHomeSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -613,6 +755,10 @@ function testDirSeparatorColorRootSubSubdirWorks() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec index f6172c9f..ece19bb5 100755 --- a/test/segments/disk_usage.spec +++ b/test/segments/disk_usage.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme # Test specific P9K_HOME=$(pwd) @@ -39,6 +37,9 @@ function testDiskUsageSegmentWhenDiskIsAlmostFull() { /dev/disk1 487219288 471466944 15496344 97% /" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{red} %F{white%}hdd %f%F{white}97%% %k%F{red}%f " "$(build_left_prompt)" unfunction df @@ -52,6 +53,9 @@ function testDiskUsageSegmentWhenDiskIsVeryFull() { /dev/disk1 487219288 471466944 15496344 94% /" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{black%}hdd %f%F{black}94%% %k%F{yellow}%f " "$(build_left_prompt)" unfunction df @@ -65,6 +69,9 @@ function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { /dev/disk1 487219288 471466944 15496344 4% /" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow%}hdd %f%F{yellow}4%% %k%F{black}%f " "$(build_left_prompt)" unfunction df @@ -89,11 +96,14 @@ function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShoul function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=10 df() { echo "Filesystem 1K-blocks Used Available Use% Mounted on /dev/disk1 487219288 471466944 15496344 11% /" } - local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=10 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{yellow} %F{black%}hdd %f%F{black}11%% %k%F{yellow}%f " "$(build_left_prompt)" @@ -103,12 +113,15 @@ function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(disk_usage) + local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=5 + local POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL=10 df() { echo "Filesystem 1K-blocks Used Available Use% Mounted on /dev/disk1 487219288 471466944 15496344 11% /" } - local POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL=5 - local POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL=10 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{red} %F{white%}hdd %f%F{white}11%% %k%F{red}%f " "$(build_left_prompt)" diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 1be2e8c8..6d8f13b9 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function mockGo() { @@ -39,6 +37,9 @@ function testGo() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version) + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" @@ -52,6 +53,9 @@ function testGoSegmentPrintsNothingIfEmptyGopath() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias go=mockGoEmptyGopath + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -61,6 +65,9 @@ function testGoSegmentPrintsNothingIfNotInGopath() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias go=mockGo + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -70,6 +77,9 @@ function testGoSegmentPrintsNothingIfGoIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias go=noGo + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias go diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 0d07b6ee..190953ad 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -7,17 +7,18 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testIpSegmentPrintsNothingOnOsxIfNotConnected() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) alias networksetup='echo "not connected"' - local OS="OSX" # Fake OSX local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias networksetup @@ -27,9 +28,12 @@ function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip custom_world) alias ip='echo "not connected"' - local OS="Linux" # Fake Linux local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias ip @@ -38,7 +42,6 @@ function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS 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) @@ -61,6 +64,10 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { alias ipconfig="_(){ echo '1.2.3.4'; };_" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)" unalias ipconfig @@ -74,7 +81,6 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS 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) @@ -113,6 +119,10 @@ function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { } } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)" unfunction ipconfig @@ -122,10 +132,13 @@ function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { function testIpSegmentWorksOnOsxWithInterfaceSpecified() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) - local OS='OSX' # Fake OSX local POWERLEVEL9K_IP_INTERFACE='xxx' alias ipconfig="_(){ echo '1.2.3.4'; };_" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + assertEquals "%K{cyan} %F{black%}IP %f%F{black}1.2.3.4 %k%F{cyan}%f " "$(build_left_prompt)" unalias ipconfig @@ -134,7 +147,6 @@ function testIpSegmentWorksOnOsxWithInterfaceSpecified() { 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.. @@ -151,18 +163,21 @@ function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { 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)" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux - unfunction ip + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS 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.. @@ -183,23 +198,30 @@ function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { 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)" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux - unfunction ip + 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 -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) - local OS='Linux' # Fake Linux local POWERLEVEL9K_IP_INTERFACE='xxx' ip(){ echo '2: eth0: 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'; - } + } + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux assertEquals "%K{cyan} %F{black%}IP %f%F{black}10.0.2.15 %k%F{cyan}%f " "$(build_left_prompt)" diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 46fe8724..746ab806 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function mockKubectl() { @@ -70,6 +68,9 @@ function testKubeContext() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) alias kubectl=mockKubectl + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" unalias kubectl @@ -79,6 +80,9 @@ function testKubeContextOtherNamespace() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) alias kubectl=mockKubectlOtherNamespace + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" unalias kubectl @@ -89,6 +93,9 @@ function testKubeContextPrintsNothingIfKubectlNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias kubectl=noKubectl + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias kubectl diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index 9d3de2d4..f4fd704d 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function mockLaravelVersion() { @@ -32,6 +30,9 @@ function testLaravelVersionSegment() { local POWERLEVEL9K_LARAVEL_ICON='x' alias php=mockLaravelVersion + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" unalias php @@ -44,6 +45,9 @@ function testLaravelVersionSegmentIfArtisanIsNotAvailable() { local POWERLEVEL9K_LARAVEL_ICON='x' alias php=mockNoLaravelVersion + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias php @@ -56,6 +60,9 @@ function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { local POWERLEVEL9K_LARAVEL_ICON='x' alias php=noPhp + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias php diff --git a/test/segments/load.spec b/test/segments/load.spec index 45e28db3..f7c1b9be 100755 --- a/test/segments/load.spec +++ b/test/segments/load.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -38,9 +36,12 @@ function testLoadSegmentWorksOnOsx() { fi } - local OS="OSX" # Fake OSX local POWERLEVEL9K_LOAD_WHICH=1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})" unfunction sysctl @@ -57,8 +58,11 @@ function testLoadSegmentWorksOnBsd() { fi } - local OS="BSD" # Fake BSD local POWERLEVEL9K_LOAD_WHICH=1 + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="BSD" # Fake BSD assertEquals "%K{green} %F{black%}L %f%F{black}1.38 " "$(prompt_load left 1 false ${FOLDER})" @@ -71,9 +75,11 @@ function testLoadSegmentWorksOnLinux() { echo "1.38 0.01 0.05 1/87 8641" > proc/loadavg alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme 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})" @@ -89,9 +95,11 @@ function testLoadSegmentNormalState() { echo "1.00 0.01 0.05 1/87 8641" > proc/loadavg alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme 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})" @@ -107,9 +115,11 @@ function testLoadSegmentWarningState() { echo "2.01 0.01 0.05 1/87 8641" > proc/loadavg alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme 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})" @@ -125,9 +135,11 @@ function testLoadSegmentCriticalState() { echo "2.81 0.01 0.05 1/87 8641" > proc/loadavg alias nproc="echo 4" + local POWERLEVEL9K_LOAD_WHICH=1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme 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})" diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec index b516e5ff..d003f5c3 100755 --- a/test/segments/node_version.spec +++ b/test/segments/node_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testNodeVersionSegmentPrintsNothingWithoutNode() { @@ -17,9 +15,11 @@ function testNodeVersionSegmentPrintsNothingWithoutNode() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias node="nonode 2>/dev/null" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" - unset POWERLEVEL9K_CUSTOM_WORLD unalias node } @@ -30,6 +30,9 @@ function testNodeVersionSegmentWorks() { echo "v1.2.3" } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{green} %F{white%}⬢ %f%F{white}1.2.3 %k%F{green}%f " "$(build_left_prompt)" unfunction node diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index 511a1a19..aff22586 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme # Test specfic # unset all possible user specified variables @@ -22,6 +20,9 @@ function testNodeenvSegmentPrintsNothingWithoutNode() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias node="nonode 2>/dev/null" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias node @@ -35,6 +36,9 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { echo "v1.2.3" } + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unfunction node @@ -50,6 +54,9 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { NODE_VIRTUAL_ENV="node-env" NODE_VIRTUAL_ENV_DISABLE_PROMPT=true + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unset NODE_VIRTUAL_ENV_DISABLE_PROMPT @@ -63,6 +70,9 @@ function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { alias node="nonode 2>/dev/null" NODE_VIRTUAL_ENV="node-env" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{green%}⬢ %f%F{green}[node-env] %k%F{black}%f " "$(build_left_prompt)" unset NODE_VIRTUAL_ENV @@ -77,6 +87,9 @@ function testNodeenvSegmentWorks() { } NODE_VIRTUAL_ENV="node-env" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{green%}⬢ %f%F{green}v1.2.3[node-env] %k%F{black}%f " "$(build_left_prompt)" unfunction node diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index f4a4812a..c8e99ea3 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -36,6 +34,9 @@ function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -43,6 +44,9 @@ function testNvmSegmentWorksWithoutHavingADefaultAlias() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + function nvm_version() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' } @@ -55,6 +59,9 @@ function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nvm custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + function nvm_version() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v4.6.0' } diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec index 51fb398f..4b9ab753 100755 --- a/test/segments/php_version.spec +++ b/test/segments/php_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { @@ -17,6 +15,9 @@ function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias php="nophp" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias php @@ -30,6 +31,9 @@ Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies '" + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{013} %F{255}PHP 5.6.27 %k%F{fuchsia}%f " "$(build_left_prompt)" unalias php diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 80dff215..c4b2ae88 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme # Test specific P9K_HOME=$(pwd) @@ -44,6 +42,9 @@ function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { # uses an alternative host. alias dig='nodig' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias dig @@ -58,6 +59,9 @@ function testPublicIpSegmentPrintsNoticeIfNotConnected() { # uses an alternative host. alias dig='nodig' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)" unalias dig @@ -72,6 +76,9 @@ function testPublicIpSegmentWorksWithWget() { echo "wget 1.2.3.4" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}wget 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)" unfunction wget @@ -88,6 +95,9 @@ function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() { echo "curl 1.2.3.4" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}curl 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)" unfunction curl @@ -104,6 +114,9 @@ function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable( echo "dig 1.2.3.4" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}dig 1.2.3.4 %k%F{black}%f " "$(build_left_prompt)" unfunction dig @@ -118,6 +131,9 @@ function testPublicIpSegmentCachesFile() { echo "first" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)" dig() { @@ -138,6 +154,9 @@ function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { echo "first" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)" sleep 3 @@ -158,6 +177,9 @@ function testPublicIpSegmentRefreshesCachesFileIfEmpty() { echo "first" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}first %k%F{black}%f " "$(build_left_prompt)" # Truncate cache file @@ -180,6 +202,9 @@ function testPublicIpSegmentWhenGoingOnline() { local POWERLEVEL9K_PUBLIC_IP_NONE="disconnected" alias dig="nodig" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}disconnected %k%F{black}%f " "$(build_left_prompt)" unalias dig diff --git a/test/segments/ram.spec b/test/segments/ram.spec index 0deaacf9..dc0b6c6b 100755 --- a/test/segments/ram.spec +++ b/test/segments/ram.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -28,31 +26,40 @@ function tearDown() { } function testRamSegmentWorksOnOsx() { - 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. '" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + assertEquals "%K{yellow} %F{black%}RAM %f%F{black}6.15G " "$(prompt_ram left 1 false ${FOLDER})" unalias vm_stat } function testRamSegmentWorksOnBsd() { - local OS="BSD" # Fake BSD mkdir -p var/run echo "avail memory 5678B 299687 4444G 299" > var/run/dmesg.boot + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="BSD" # Fake BSD + assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29M " "$(prompt_ram left 1 false ${FOLDER})" } function testRamSegmentWorksOnLinux() { - local OS="Linux" # Fake Linux mkdir proc echo "MemAvailable: 299687" > proc/meminfo + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + assertEquals "%K{yellow} %F{black%}RAM %f%F{black}0.29G " "$(prompt_ram left 1 false ${FOLDER})" } diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 3d627498..583807a6 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -14,8 +14,6 @@ function setUp() { PATH="${RUST_TEST_FOLDER}:${PATH}" export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function tearDown() { @@ -33,6 +31,9 @@ function testRust() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) mockRust + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" } @@ -41,6 +42,9 @@ function testRustPrintsNothingIfRustIsNotAvailable() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec index a5360072..a6701dcf 100755 --- a/test/segments/ssh.spec +++ b/test/segments/ssh.spec @@ -7,12 +7,6 @@ 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() { @@ -25,6 +19,9 @@ function testSshSegmentPrintsNothingIfNoSshConnection() { unset SSH_CLIENT unset SSH_TTY + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -37,6 +34,9 @@ function testSshSegmentWorksIfOnlySshClientIsSet() { SSH_CLIENT='ssh-client' unset SSH_TTY + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)" unset SSH_CLIENT @@ -51,6 +51,9 @@ function testSshSegmentWorksIfOnlySshTtyIsSet() { SSH_TTY='ssh-tty' unset SSH_CLIENT + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)" unset SSH_TTY @@ -65,6 +68,9 @@ function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { SSH_CLIENT='ssh-client' SSH_TTY='ssh-tty' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{yellow%}ssh-icon%f %k%F{black}%f " "$(build_left_prompt)" unset SSH_TTY diff --git a/test/segments/status.spec b/test/segments/status.spec index d921111b..b3ba3e36 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme ### Test specific # Resets if someone has set these in his/hers env @@ -23,6 +21,9 @@ function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { local POWERLEVEL9K_STATUS_VERBOSE=false local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -33,6 +34,9 @@ function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{green%}✔%f %k%F{black}%f " "$(build_left_prompt)" } @@ -41,6 +45,9 @@ function testStatusInGeneralErrorCase() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false + + # Load Powerlevel9k + source powerlevel9k.zsh-theme local RETVAL=1 assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}1 %k%F{red}%f " "$(build_left_prompt)" @@ -51,6 +58,9 @@ function testPipestatusInErrorCase() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme local -a RETVALS RETVALS=(0 0 1 0) @@ -63,6 +73,9 @@ function testStatusCrossWinsOverVerbose() { local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_CROSS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme local RETVAL=1 assertEquals "%K{black} %F{red%}✘%f %k%F{black}%f " "$(build_left_prompt)" @@ -74,6 +87,9 @@ function testStatusShowsSignalNameInErrorCase() { local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false + + # Load Powerlevel9k + source powerlevel9k.zsh-theme local RETVAL=132 assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}SIGILL(4) %k%F{red}%f " "$(build_left_prompt)" @@ -84,6 +100,10 @@ function testStatusSegmentIntegrated() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=() + local POWERLEVEL9K_STATUS_CROSS=true + + # Load Powerlevel9k + source powerlevel9k.zsh-theme false; powerlevel9k_prepare_prompts diff --git a/test/segments/swap.spec b/test/segments/swap.spec index 58f35c0a..20a2d40a 100755 --- a/test/segments/swap.spec +++ b/test/segments/swap.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -30,11 +28,14 @@ function tearDown() { function testSwapSegmentWorksOnOsx() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) - local OS="OSX" # Fake OSX sysctl() { echo "vm.swapusage: total = 3072,00M used = 1620,50M free = 1451,50M (encrypted)" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + assertEquals "%K{yellow} %F{black%}SWP %f%F{black}1.58G " "$(prompt_swap left 1 false ${FOLDER})" unfunction sysctl @@ -43,11 +44,14 @@ function testSwapSegmentWorksOnOsx() { function testSwapSegmentWorksOnLinux() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(swap) - local OS="Linux" # Fake Linux mkdir proc echo "SwapTotal: 1000000" > proc/meminfo echo "SwapFree: 1000" >> proc/meminfo + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + assertEquals "%K{yellow} %F{black%}SWP %f%F{black}0.95G " "$(prompt_swap left 1 false ${FOLDER})" } diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec index 5634de11..da9aaa92 100755 --- a/test/segments/swift_version.spec +++ b/test/segments/swift_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -33,6 +31,8 @@ function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias swift="noswift" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" @@ -46,6 +46,9 @@ function testSwiftSegmentWorks() { echo "Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)\nTarget: x86_64-apple-macosx10.9" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{magenta} %F{white%}Swift %f%F{white}3.0.1 %k%F{magenta}%f " "$(build_left_prompt)" unfunction swift diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec index 65d193b0..99dea476 100755 --- a/test/segments/symfony_version.spec +++ b/test/segments/symfony_version.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -33,6 +31,9 @@ function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() { local POWERLEVEL9K_CUSTOM_WORLD='echo world' alias php="nophp" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unalias php @@ -46,6 +47,9 @@ function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() { # navigate into a folder that does not contain symfony. local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -61,6 +65,9 @@ function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { Parse error: parse error, expecting `;´ or `{´ in /Users/dr/Privat/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 97" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" unfunction php @@ -77,6 +84,9 @@ function testSymfonyVersionSegmentWorks() { echo "Symfony version 3.1.4 - app/dev/debug" } + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)" unfunction php @@ -96,6 +106,9 @@ function testSymfonyVersionSegmentWorksInNestedFolder() { mkdir -p src/P9K/AppBundle cd src/P9K/AppBundle + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{240} %F{black%}SF %f%F{black}3.1.4 %k%F{240}%f " "$(build_left_prompt)" unfunction php diff --git a/test/segments/todo.spec b/test/segments/todo.spec index 1dae9a68..7f1d7fba 100755 --- a/test/segments/todo.spec +++ b/test/segments/todo.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -37,6 +35,9 @@ function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(todo custom_world) local POWERLEVEL9K_CUSTOM_WORLD='echo world' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } @@ -48,6 +49,9 @@ function testTodoSegmentWorksAsExpected() { echo 'echo "TODO: 34 of 100 tasks shown";' >> ${FOLDER}/bin/todo.sh chmod +x ${FOLDER}/bin/todo.sh + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{244} %F{black%}☑ %f%F{black}100 %k%F{grey50}%f " "$(build_left_prompt)" } diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index 3ae4077e..f78012dd 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -75,6 +73,9 @@ function testColorOverridingForCleanStateWorks() { local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" } @@ -88,6 +89,9 @@ function testColorOverridingForModifiedStateWorks() { git add testfile git commit -m "test" 1>/dev/null echo "test" > testfile + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)" } @@ -100,6 +104,9 @@ function testColorOverridingForUntrackedStateWorks() { touch testfile + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" } @@ -107,6 +114,9 @@ function testGitIconWorks() { local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_GIT_ICON='Git-Icon' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black%}Git-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)" } @@ -119,6 +129,9 @@ function testGitlabIconWorks() { # sufficient to show the GitLab-specific icon. git remote add origin https://gitlab.com/dritter/gitlab-test-project.git + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black%}GL-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)" } @@ -131,6 +144,9 @@ function testBitbucketIconWorks() { # sufficient to show the BitBucket-specific icon. git remote add origin https://dritter@bitbucket.org/dritter/dr-test.git + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black%}BB-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)" } @@ -143,6 +159,9 @@ function testGitHubIconWorks() { # sufficient to show the GitHub-specific icon. git remote add origin https://github.com/dritter/test.git + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black%}GH-Icon %f%F{black} master %k%F{green}%f " "$(build_left_prompt)" } @@ -154,6 +173,9 @@ function testUntrackedFilesIconWorks() { # Create untracked file touch "i-am-untracked.txt" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" } @@ -169,7 +191,10 @@ function testStagedFilesIconWorks() { 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)" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{yellow} %F{black} master + %k%F{yellow}%f " "$(build_left_prompt)" } function testUnstagedFilesIconWorks() { @@ -183,7 +208,10 @@ function testUnstagedFilesIconWorks() { 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)" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{yellow} %F{black} master M %k%F{yellow}%f " "$(build_left_prompt)" } function testStashIconWorks() { @@ -198,6 +226,9 @@ function testStashIconWorks() { echo "xx" > i-am-modified.txt git stash 1>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} master S1 %k%F{green}%f " "$(build_left_prompt)" } @@ -211,6 +242,9 @@ function testTagIconWorks() { git commit -m "Add File" 1>/dev/null git tag "v0.0.1" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} master Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)" } @@ -229,6 +263,9 @@ function testTagIconInDetachedHeadState() { git checkout v0.0.1 &>/dev/null local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=8 HEAD) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)" } @@ -249,6 +286,9 @@ function testActionHintWorks() { git commit -a -m "Provoke conflict" &>/dev/null git pull &>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{black} master %F{red}| merge%f %k%F{yellow}%f " "$(build_left_prompt)" } @@ -268,6 +308,9 @@ function testIncomingHintWorks() { cd ../vcs-test2 git fetch &>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} master I1 %k%F{green}%f " "$(build_left_prompt)" } @@ -287,6 +330,9 @@ function testOutgoingHintWorks() { echo "xx" >> i-am-modified.txt git commit -a -m "Modified file" &>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} master o1 %k%F{green}%f " "$(build_left_prompt)" } @@ -301,6 +347,9 @@ function testShorteningCommitHashWorks() { git commit -m "Add File" 1>/dev/null local hash=$(git rev-list -n 1 --abbrev-commit --abbrev=3 HEAD) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + # This test needs to call powerlevel9k_vcs_init, where # the changeset is truncated. powerlevel9k_vcs_init @@ -317,6 +366,9 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { git add file.txt git commit -m "Add File" 1>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + # This test needs to call powerlevel9k_vcs_init, where # the changeset is truncated. powerlevel9k_vcs_init diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 91d25ae6..3074952a 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -7,8 +7,6 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme P9K_HOME=$(pwd) ### Test specific @@ -39,6 +37,9 @@ function testColorOverridingForCleanStateWorks() { local POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan' local POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{white} %F{cyan} default %k%F{white}%f " "$(build_left_prompt)" } @@ -53,6 +54,9 @@ function testColorOverridingForModifiedStateWorks() { hg commit -m "test" 1>/dev/null echo "test" > testfile + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{red} default ● %k%F{yellow}%f " "$(build_left_prompt)" } @@ -67,6 +71,9 @@ function testAddedFilesIconWorks() { touch "myfile.txt" hg add myfile.txt + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{black} default ● %k%F{yellow}%f " "$(build_left_prompt)" } @@ -82,6 +89,9 @@ function testTagIconWorks() { hg commit -m "Add File" 1>/dev/null hg tag "v0.0.1" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} default Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)" } @@ -101,6 +111,9 @@ function testTagIconInDetachedHeadState() { hg checkout v0.0.1 &>/dev/null local hash=$(hg id) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} ${hash} Tv0.0.1 %k%F{green}%f " "$(build_left_prompt)" } @@ -121,6 +134,9 @@ function testActionHintWorks() { hg pull 1>/dev/null hg merge --tool internal:merge >/dev/null 2>&1 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{yellow} %F{black} default %F{red}| merging%f %k%F{yellow}%f " "$(build_left_prompt)" } @@ -135,6 +151,9 @@ function testShorteningCommitHashWorks() { hg commit -m "Add File" 1>/dev/null local hash=$(hg id | head -c ${POWERLEVEL9K_CHANGESET_HASH_LENGTH}) + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + # This test needs to call powerlevel9k_vcs_init, where # the changeset is truncated. powerlevel9k_vcs_init @@ -152,6 +171,9 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { hg add file.txt hg commit -m "Add File" 1>/dev/null + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + # This test needs to call powerlevel9k_vcs_init, where # the changeset is truncated. powerlevel9k_vcs_init @@ -164,6 +186,9 @@ function testMercurialIconWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) local POWERLEVEL9K_VCS_HG_ICON='HG-Icon' + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black%}HG-Icon %f%F{black} default %k%F{green}%f " "$(build_left_prompt)" } @@ -173,6 +198,9 @@ function testBookmarkIconWorks() { local POWERLEVEL9K_VCS_BOOKMARK_ICON='B' hg bookmark "initial" + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{green} %F{black} default Binitial %k%F{green}%f " "$(build_left_prompt)" } diff --git a/test/segments/vi_mode.spec b/test/segments/vi_mode.spec index 205c38b7..5bed38bd 100755 --- a/test/segments/vi_mode.spec +++ b/test/segments/vi_mode.spec @@ -7,31 +7,41 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme } function testViInsertModeWorks() { local KEYMAP='viins' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)" } function testViInsertModeWorksWhenLabeledAsMain() { local KEYMAP='main' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)" } function testViCommandModeWorks() { local KEYMAP='vicmd' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{white}NORMAL " "$(prompt_vi_mode left 1 false)" } function testViInsertModeStringIsCustomizable() { local KEYMAP='viins' + # Load Powerlevel9k + source powerlevel9k.zsh-theme + assertEquals "%K{black} %F{blue}INSERT " "$(prompt_vi_mode left 1 false)" } From 3b0397d1a6ce72516bb484197eceaf4498c1c2ab Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Jul 2018 07:58:38 +0200 Subject: [PATCH 068/103] Fix test for background_jobs segment --- test/segments/background_jobs.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index c38f2d17..0a61c3e1 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -40,7 +40,7 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { } function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { - unset POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE + local POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=false local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(background_jobs) jobs() { From 518148383ecebe2536bf9db7c316c4e646cb5f8a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 31 Jul 2018 00:48:12 +0200 Subject: [PATCH 069/103] Fix Test for context segment This fixes an error on travis, because there is no sudo allowed. We could allow it, but I think it is better to mock sudo anyway. --- test/segments/context.spec | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/segments/context.spec b/test/segments/context.spec index b350caf7..2cef90dd 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -31,6 +31,9 @@ function testContextSegmentDoesNotGetRenderedWithDefaultUser() { } function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { + function sudo() { + return 0 + } local SSH_CLIENT="putty" local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) @@ -39,6 +42,8 @@ function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { source powerlevel9k.zsh-theme assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" + + unfunction sudo } function testContextSegmentWithForeignUser() { From 7f6ac8dbaca1ff1139a1eb2bef1f234cf4a72099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Tue, 31 Jul 2018 16:22:26 -0400 Subject: [PATCH 070/103] Use SUDO_COMMAND to check for sudo `sudo -n true` only checks that we _could_ use `sudo`, not if we are in a sudo session. closes #852 --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3e425c48..0b9dc708 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -623,12 +623,12 @@ prompt_context() { if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then - if sudo -n true 2>/dev/null; then + if [[ -n "$SUDO_COMMAND" ]]; then current_state="REMOTE_SUDO" else current_state="REMOTE" fi - elif sudo -n true 2>/dev/null; then + elif [[ -n "$SUDO_COMMAND" ]]; then current_state="SUDO" fi From 81fd69ae98337c20cb3e530d4efe13bec2fb3b20 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 4 Aug 2018 17:34:52 +0200 Subject: [PATCH 071/103] Update shunit2 to newest version --- shunit2 | 2 +- test/core/color_overriding.spec | 2 +- test/core/joining_segments.spec | 2 +- test/core/prompt.spec | 2 +- test/core/visual_identifier.spec | 2 +- test/functions/colors.spec | 2 +- test/functions/icons.spec | 2 +- test/functions/utilities.spec | 2 +- test/powerlevel9k.spec | 2 +- test/segments/anaconda.spec | 2 +- test/segments/aws_eb_env.spec | 2 +- test/segments/background_jobs.spec | 2 +- test/segments/battery.spec | 2 +- test/segments/command_execution_time.spec | 2 +- test/segments/context.spec | 2 +- test/segments/custom.spec | 2 +- test/segments/detect_virt.spec | 2 +- test/segments/dir.spec | 2 +- test/segments/disk_usage.spec | 2 +- test/segments/go_version.spec | 2 +- test/segments/ip.spec | 2 +- test/segments/kubecontext.spec | 2 +- test/segments/laravel_version.spec | 2 +- test/segments/load.spec | 2 +- test/segments/node_version.spec | 2 +- test/segments/nodeenv.spec | 2 +- test/segments/nvm.spec | 2 +- test/segments/php_version.spec | 2 +- test/segments/public_ip.spec | 2 +- test/segments/ram.spec | 2 +- test/segments/rust_version.spec | 2 +- test/segments/ssh.spec | 2 +- test/segments/status.spec | 2 +- test/segments/swap.spec | 2 +- test/segments/swift_version.spec | 2 +- test/segments/symfony_version.spec | 2 +- test/segments/todo.spec | 2 +- test/segments/vcs-git.spec | 2 +- test/segments/vcs-hg.spec | 2 +- test/segments/vi_mode.spec | 2 +- 40 files changed, 40 insertions(+), 40 deletions(-) diff --git a/shunit2 b/shunit2 index 60dd60bc..07bb3292 160000 --- a/shunit2 +++ b/shunit2 @@ -1 +1 @@ -Subproject commit 60dd60bcd1573befe38465010263ab242e55811d +Subproject commit 07bb3292048a4982aad7247bdd7890f2bf532ece diff --git a/test/core/color_overriding.spec b/test/core/color_overriding.spec index ead890d7..48b30f00 100755 --- a/test/core/color_overriding.spec +++ b/test/core/color_overriding.spec @@ -59,4 +59,4 @@ function testColorOverridingOfCustomSegment() { assertEquals "%K{red} %F{green%}CW %f%F{red}world %k%F{red}%f " "$(build_left_prompt)" } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/core/joining_segments.spec b/test/core/joining_segments.spec index 708e9bf1..f224007e 100755 --- a/test/core/joining_segments.spec +++ b/test/core/joining_segments.spec @@ -184,4 +184,4 @@ function testRightJoiningBuiltinSegmentWorks() { unalias php } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/core/prompt.spec b/test/core/prompt.spec index 42518f06..dd5bba58 100755 --- a/test/core/prompt.spec +++ b/test/core/prompt.spec @@ -101,4 +101,4 @@ function testPrefixingSecondLineOnLeftPrompt() { assertEquals "╭─%f%b%k%K{white} %F{black}world1 %k%F{white}%f ${nl}XXX" "${(e)PROMPT}" } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/core/visual_identifier.spec b/test/core/visual_identifier.spec index db9896db..c6b1125b 100755 --- a/test/core/visual_identifier.spec +++ b/test/core/visual_identifier.spec @@ -47,4 +47,4 @@ function testVisualIdentifierPrintsNothingIfNotAvailable() { assertEquals "%K{white} %F{black}world1 %k%F{white}%f " "$(build_left_prompt)" } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/functions/colors.spec b/test/functions/colors.spec index 61a40087..bb06b719 100755 --- a/test/functions/colors.spec +++ b/test/functions/colors.spec @@ -39,4 +39,4 @@ function testIsSameColorDoesNotYieldNotEqualColorsTruthy() { } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/functions/icons.spec b/test/functions/icons.spec index d4ddc805..ec0cb1fa 100755 --- a/test/functions/icons.spec +++ b/test/functions/icons.spec @@ -470,4 +470,4 @@ function testAllIconsAreDefinedLikeInNerdfontCompleteMode() { unset _ICONS_UNDER_TEST } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/functions/utilities.spec b/test/functions/utilities.spec index a9bd67e3..b727c1f6 100755 --- a/test/functions/utilities.spec +++ b/test/functions/utilities.spec @@ -106,4 +106,4 @@ function testSegmentShouldNotBeJoinedIfPredecessingSegmentIsNotJoinedButConditio unset segments } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 57f85c98..8de0f1e2 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -120,4 +120,4 @@ function testNewlineOnRpromptCanBeDisabled() { assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec index 2aa8d272..c35f0494 100755 --- a/test/segments/anaconda.spec +++ b/test/segments/anaconda.spec @@ -66,4 +66,4 @@ function testAnacondaSegmentWorks() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec index 42740ea6..92240e42 100755 --- a/test/segments/aws_eb_env.spec +++ b/test/segments/aws_eb_env.spec @@ -58,4 +58,4 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirec cd - } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index 0a61c3e1..fa8d5ce6 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -75,4 +75,4 @@ function testBackgroundJobsSegmentWithVerboseMode() { unfunction jobs } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/battery.spec b/test/segments/battery.spec index 835e1468..4f81eaec 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -170,4 +170,4 @@ function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index 65623a00..b47d3fc9 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -101,4 +101,4 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/context.spec b/test/segments/context.spec index 2cef90dd..0805474f 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -103,4 +103,4 @@ function testContextSegmentIsShownIfForced() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/custom.spec b/test/segments/custom.spec index b7719d1c..3062d2e5 100755 --- a/test/segments/custom.spec +++ b/test/segments/custom.spec @@ -83,4 +83,4 @@ function testSettingVisualIdentifierForegroundColorForCustomSegment() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec index 7df92a24..f5c54198 100755 --- a/test/segments/detect_virt.spec +++ b/test/segments/detect_virt.spec @@ -80,4 +80,4 @@ function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() { unalias systemd-detect-virt } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 1f0440cd..09fa8505 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -768,4 +768,4 @@ function testDirSeparatorColorRootSubSubdirWorks() { rm -fr /tmp/powerlevel9k-test } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec index ece19bb5..80fc996f 100755 --- a/test/segments/disk_usage.spec +++ b/test/segments/disk_usage.spec @@ -128,4 +128,4 @@ function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { unfunction df } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 6d8f13b9..6260aaf5 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -85,4 +85,4 @@ function testGoSegmentPrintsNothingIfGoIsNotAvailable() { unalias go } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 190953ad..8ffb41eb 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -228,4 +228,4 @@ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 unfunction ip } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 746ab806..b954de4a 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -101,4 +101,4 @@ function testKubeContextPrintsNothingIfKubectlNotAvailable() { unalias kubectl } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index f4fd704d..88818c6a 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -68,4 +68,4 @@ function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { unalias php } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/load.spec b/test/segments/load.spec index f7c1b9be..9caa82c3 100755 --- a/test/segments/load.spec +++ b/test/segments/load.spec @@ -146,4 +146,4 @@ function testLoadSegmentCriticalState() { unalias nproc } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec index d003f5c3..1627f436 100755 --- a/test/segments/node_version.spec +++ b/test/segments/node_version.spec @@ -38,4 +38,4 @@ function testNodeVersionSegmentWorks() { unfunction node } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index aff22586..b72b426a 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -96,4 +96,4 @@ function testNodeenvSegmentWorks() { unset NODE_VIRTUAL_ENV } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index c8e99ea3..83d4c8f6 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -69,4 +69,4 @@ function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec index 4b9ab753..1a3ec91b 100755 --- a/test/segments/php_version.spec +++ b/test/segments/php_version.spec @@ -39,4 +39,4 @@ Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies unalias php } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index c4b2ae88..9a2dcdab 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -219,4 +219,4 @@ function testPublicIpSegmentWhenGoingOnline() { unfunction dig } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/ram.spec b/test/segments/ram.spec index dc0b6c6b..f1331427 100755 --- a/test/segments/ram.spec +++ b/test/segments/ram.spec @@ -63,4 +63,4 @@ function testRamSegmentWorksOnLinux() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 583807a6..9643125f 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -48,4 +48,4 @@ function testRustPrintsNothingIfRustIsNotAvailable() { assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec index a6701dcf..36971e13 100755 --- a/test/segments/ssh.spec +++ b/test/segments/ssh.spec @@ -77,4 +77,4 @@ function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { unset SSH_CLIENT } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/status.spec b/test/segments/status.spec index b3ba3e36..97dc6b31 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -110,4 +110,4 @@ function testStatusSegmentIntegrated() { assertEquals "%f%b%k%K{black} %F{red%}✘%f %k%F{black}%f " "${(e)PROMPT}" } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swap.spec b/test/segments/swap.spec index 20a2d40a..2f4fbbf1 100755 --- a/test/segments/swap.spec +++ b/test/segments/swap.spec @@ -55,4 +55,4 @@ function testSwapSegmentWorksOnLinux() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec index da9aaa92..4b7c6351 100755 --- a/test/segments/swift_version.spec +++ b/test/segments/swift_version.spec @@ -54,4 +54,4 @@ function testSwiftSegmentWorks() { unfunction swift } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec index 99dea476..89a2e0be 100755 --- a/test/segments/symfony_version.spec +++ b/test/segments/symfony_version.spec @@ -114,4 +114,4 @@ function testSymfonyVersionSegmentWorksInNestedFolder() { unfunction php } -source shunit2/source/2.1/src/shunit2 \ No newline at end of file +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/todo.spec b/test/segments/todo.spec index 7f1d7fba..488dc993 100755 --- a/test/segments/todo.spec +++ b/test/segments/todo.spec @@ -55,4 +55,4 @@ function testTodoSegmentWorksAsExpected() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index f78012dd..b84e08d9 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -375,4 +375,4 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 3074952a..ff84a3d6 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -204,4 +204,4 @@ function testBookmarkIconWorks() { 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 +source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vi_mode.spec b/test/segments/vi_mode.spec index 5bed38bd..8913dfea 100755 --- a/test/segments/vi_mode.spec +++ b/test/segments/vi_mode.spec @@ -45,4 +45,4 @@ function testViInsertModeStringIsCustomizable() { 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 +source shunit2/shunit2 \ No newline at end of file From e7cbcc5187c99e236192c1e3801bef54fd682c21 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 4 Aug 2018 22:57:06 +0200 Subject: [PATCH 072/103] Fix tests --- test/segments/battery.spec | 4 ++++ test/segments/context.spec | 2 ++ 2 files changed, 6 insertions(+) diff --git a/test/segments/battery.spec b/test/segments/battery.spec index 4f81eaec..754de3cf 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -158,6 +158,10 @@ function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { assertEquals "%K{black} %F{white%}🔋 %f%F{white}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" unalias date &>/dev/null + # unaliasing date fails where it was never aliased (e.g. on Linux). + # This causes the whole test to fail, because the return code is + # non-zero. + return 0 } function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() { diff --git a/test/segments/context.spec b/test/segments/context.spec index 0805474f..987c3899 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -16,6 +16,8 @@ function setUp() { function tearDown() { # Restore old variables [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER + + return 0 } function testContextSegmentDoesNotGetRenderedWithDefaultUser() { From 3c991f902c967f184e7933183b09b5cb96673bf7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 5 Aug 2018 22:26:17 +0200 Subject: [PATCH 073/103] Make Travis use XCode9.4 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0da3abe6..30631ea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ os: - linux - osx +osx_image: xcode9.4 + addons: apt: packages: From ba353caa989463204ad18498da854a9702112e70 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 5 Aug 2018 22:40:39 +0200 Subject: [PATCH 074/103] Fix tests for context segment --- test/segments/context.spec | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/segments/context.spec b/test/segments/context.spec index 987c3899..49795668 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -49,6 +49,9 @@ function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { } function testContextSegmentWithForeignUser() { + function sudo() { + return 0 + } local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) @@ -56,6 +59,8 @@ function testContextSegmentWithForeignUser() { source powerlevel9k.zsh-theme assertEquals "%K{black} %F{yellow}%n@%m %k%F{black}%f " "$(build_left_prompt)" + + unfunction sudo } # TODO: How to test root? From ebbdb3c1c011a1f024e80b50c6b8b4a4fa5c46e2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:21:15 +0200 Subject: [PATCH 075/103] Make purpose clear of backgroundColor and foregroundColor functions The functions just start the colors, they do not end them. It seems too much to have a function that terminates a color. --- functions/colors.zsh | 16 ++++------------ powerlevel9k.zsh-theme | 8 ++++---- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 9309a225..b94258a5 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -50,20 +50,12 @@ function getColor() { # empty paramenter resets (stops) background color function backgroundColor() { - if [[ -z $1 ]]; then - echo -n "%k" - else - echo -n "%K{$(getColor $1)}" - fi + echo -n "%K{$(getColor $1)}" } # empty paramenter resets (stops) foreground color function foregroundColor() { - if [[ -z $1 ]]; then - echo -n "%f" - else - echo -n "%F{$(getColor $1)}" - fi + echo -n "%F{$(getColor $1)}" } # Get numerical color codes. That way we translate ANSI codes @@ -346,12 +338,12 @@ function getColorCode() { if [[ "$1" == "foreground" ]]; then # call via `getColorCode foreground` for i in "${(k@)codes}"; do - print -P "$(foregroundColor $i)$(getColor $i) - $i$(foregroundColor)" + print -P "$(foregroundColor $i)$(getColor $i) - $i%f" done elif [[ "$1" == "background" ]]; then # call via `getColorCode background` for i in "${(k@)codes}"; do - print -P "$(backgroundColor $i)$(getColor $i) - $i$(backgroundColor)" + print -P "$(backgroundColor $i)$(getColor $i) - $i%k" done else #[[ -n "$1" ]] bg="%K{$1}" || bg="%k" diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3e425c48..97bddc30 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -127,8 +127,8 @@ left_prompt_segment() { [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" local bg fg - [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="$(backgroundColor)" - [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="$(foregroundColor)" + [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="%k" + [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="%f" if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then echo -n "$bg%F{$CURRENT_BG}" @@ -220,8 +220,8 @@ right_prompt_segment() { [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" local bg fg - [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="$(backgroundColor)" - [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="$(foregroundColor)" + [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="%k" + [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="%f" # If CURRENT_RIGHT_BG is "NONE", we are the first right segment. From bf9082bea9f8912a028b660db5084e659d9973a8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:25:06 +0200 Subject: [PATCH 076/103] Fix bug so that the segment separator of left middle has the right color In short: the current background color was the unfiltered color and is used to print the next segment separator. If the user set a color like "purple3" that would result in a white segment separator as Terminal Emulators do not understand the color "purple3". --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 97bddc30..92917345 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -173,7 +173,7 @@ left_prompt_segment() { [[ -n "$5" ]] && echo -n "${fg}${5}" echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" - CURRENT_BG=$3 + CURRENT_BG="$(getColorCode ${3})" last_left_element_index=$current_index } From 9cf76f99a548a9c51c2a9cc65ecadfd5353afa23 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:33:09 +0200 Subject: [PATCH 077/103] Fix bright colors Remove old code that set bright colors equal to normal colors. This code was ancient and led to bright colors being unusable. The code originates from 0e37d8ef865daddd6af02ba78b4a3bb86fd5917e. --- functions/colors.zsh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index b94258a5..41223dd2 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -28,12 +28,8 @@ function termColors() { # get the proper color code if it does not exist as a name. function getColor() { - # no need to check numerical values - if [[ "$1" = <-> ]]; then - if [[ "$1" = <8-15> ]]; then - 1=$(($1 - 8)) - fi - else + # If Color is not numerical, try to get the color code. + if [[ "$1" != <-> ]]; then # named color added to parameter expansion print -P to test if the name exists in terminal local named="%K{$1}" # https://misc.flogisoft.com/bash/tip_colors_and_formatting From eadbd09368f011d29893ea05c3bec7a1d2fbfebc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:35:29 +0200 Subject: [PATCH 078/103] Write comparisons with double equals --- functions/colors.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 41223dd2..1788bbfc 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -36,7 +36,7 @@ function getColor() { local default="$'\033'\[49m" # http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html local quoted=$(printf "%q" $(print -P "$named")) - if [[ $quoted = "$'\033'\[49m" && $1 != "black" ]]; then + if [[ $quoted == "$'\033'\[49m" && $1 != "black" ]]; then # color not found, so try to get the code 1=$(getColorCode $1) fi From 0acede2fdc32bd39d7d53e0d9927a3856cfe4527 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:36:49 +0200 Subject: [PATCH 079/103] Make colors a global array That way it must not be defined in every function call. --- functions/colors.zsh | 532 ++++++++++++++++++++++--------------------- 1 file changed, 267 insertions(+), 265 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 1788bbfc..17caa201 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -6,6 +6,270 @@ # https://github.com/bhilburn/powerlevel9k ################################################################ +typeset -gAh __P9K_COLORS +# https://jonasjacek.github.io/colors/ +# use color names by default to allow dark/light themes to adjust colors based on names +__P9K_COLORS=( + black 000 + maroon 001 + green 002 + olive 003 + navy 004 + purple 005 + teal 006 + silver 007 + grey 008 + red 009 + lime 010 + yellow 011 + blue 012 + fuchsia 013 + magenta 013 + aqua 014 + cyan 014 + white 015 + grey0 016 + navyblue 017 + darkblue 018 + blue3 019 + blue3 020 + blue1 021 + darkgreen 022 + deepskyblue4 023 + deepskyblue4 024 + deepskyblue4 025 + dodgerblue3 026 + dodgerblue2 027 + green4 028 + springgreen4 029 + turquoise4 030 + deepskyblue3 031 + deepskyblue3 032 + dodgerblue1 033 + green3 034 + springgreen3 035 + darkcyan 036 + lightseagreen 037 + deepskyblue2 038 + deepskyblue1 039 + green3 040 + springgreen3 041 + springgreen2 042 + cyan3 043 + darkturquoise 044 + turquoise2 045 + green1 046 + springgreen2 047 + springgreen1 048 + mediumspringgreen 049 + cyan2 050 + cyan1 051 + darkred 052 + deeppink4 053 + purple4 054 + purple4 055 + purple3 056 + blueviolet 057 + orange4 058 + grey37 059 + mediumpurple4 060 + slateblue3 061 + slateblue3 062 + royalblue1 063 + chartreuse4 064 + darkseagreen4 065 + paleturquoise4 066 + steelblue 067 + steelblue3 068 + cornflowerblue 069 + chartreuse3 070 + darkseagreen4 071 + cadetblue 072 + cadetblue 073 + skyblue3 074 + steelblue1 075 + chartreuse3 076 + palegreen3 077 + seagreen3 078 + aquamarine3 079 + mediumturquoise 080 + steelblue1 081 + chartreuse2 082 + seagreen2 083 + seagreen1 084 + seagreen1 085 + aquamarine1 086 + darkslategray2 087 + darkred 088 + deeppink4 089 + darkmagenta 090 + darkmagenta 091 + darkviolet 092 + purple 093 + orange4 094 + lightpink4 095 + plum4 096 + mediumpurple3 097 + mediumpurple3 098 + slateblue1 099 + yellow4 100 + wheat4 101 + grey53 102 + lightslategrey 103 + mediumpurple 104 + lightslateblue 105 + yellow4 106 + darkolivegreen3 107 + darkseagreen 108 + lightskyblue3 109 + lightskyblue3 110 + skyblue2 111 + chartreuse2 112 + darkolivegreen3 113 + palegreen3 114 + darkseagreen3 115 + darkslategray3 116 + skyblue1 117 + chartreuse1 118 + lightgreen 119 + lightgreen 120 + palegreen1 121 + aquamarine1 122 + darkslategray1 123 + red3 124 + deeppink4 125 + mediumvioletred 126 + magenta3 127 + darkviolet 128 + purple 129 + darkorange3 130 + indianred 131 + hotpink3 132 + mediumorchid3 133 + mediumorchid 134 + mediumpurple2 135 + darkgoldenrod 136 + lightsalmon3 137 + rosybrown 138 + grey63 139 + mediumpurple2 140 + mediumpurple1 141 + gold3 142 + darkkhaki 143 + navajowhite3 144 + grey69 145 + lightsteelblue3 146 + lightsteelblue 147 + yellow3 148 + darkolivegreen3 149 + darkseagreen3 150 + darkseagreen2 151 + lightcyan3 152 + lightskyblue1 153 + greenyellow 154 + darkolivegreen2 155 + palegreen1 156 + darkseagreen2 157 + darkseagreen1 158 + paleturquoise1 159 + red3 160 + deeppink3 161 + deeppink3 162 + magenta3 163 + magenta3 164 + magenta2 165 + darkorange3 166 + indianred 167 + hotpink3 168 + hotpink2 169 + orchid 170 + mediumorchid1 171 + orange3 172 + lightsalmon3 173 + lightpink3 174 + pink3 175 + plum3 176 + violet 177 + gold3 178 + lightgoldenrod3 179 + tan 180 + mistyrose3 181 + thistle3 182 + plum2 183 + yellow3 184 + khaki3 185 + lightgoldenrod2 186 + lightyellow3 187 + grey84 188 + lightsteelblue1 189 + yellow2 190 + darkolivegreen1 191 + darkolivegreen1 192 + darkseagreen1 193 + honeydew2 194 + lightcyan1 195 + red1 196 + deeppink2 197 + deeppink1 198 + deeppink1 199 + magenta2 200 + magenta1 201 + orangered1 202 + indianred1 203 + indianred1 204 + hotpink 205 + hotpink 206 + mediumorchid1 207 + darkorange 208 + salmon1 209 + lightcoral 210 + palevioletred1 211 + orchid2 212 + orchid1 213 + orange1 214 + sandybrown 215 + lightsalmon1 216 + lightpink1 217 + pink1 218 + plum1 219 + gold1 220 + lightgoldenrod2 221 + lightgoldenrod2 222 + navajowhite1 223 + mistyrose1 224 + thistle1 225 + yellow1 226 + lightgoldenrod1 227 + khaki1 228 + wheat1 229 + cornsilk1 230 + grey100 231 + grey3 232 + grey7 233 + grey11 234 + grey15 235 + grey19 236 + grey23 237 + grey27 238 + grey30 239 + grey35 240 + grey39 241 + grey42 242 + grey46 243 + grey50 244 + grey54 245 + grey58 246 + grey62 247 + grey66 248 + grey70 249 + grey74 250 + grey78 251 + grey82 252 + grey85 253 + grey89 254 + grey93 255 +) + function termColors() { if [[ $POWERLEVEL9K_IGNORE_TERM_COLORS == true ]]; then return @@ -68,277 +332,15 @@ function getColorCode() { echo -n "$1" fi else - typeset -A codes - # https://jonasjacek.github.io/colors/ - # use color names by default to allow dark/light themes to adjust colors based on names - codes[black]=000 - codes[maroon]=001 - codes[green]=002 - codes[olive]=003 - codes[navy]=004 - codes[purple]=005 - codes[teal]=006 - codes[silver]=007 - codes[grey]=008 - codes[red]=009 - codes[lime]=010 - codes[yellow]=011 - codes[blue]=012 - codes[fuchsia]=013 - codes[magenta]=013 - codes[aqua]=014 - codes[cyan]=014 - codes[white]=015 - codes[grey0]=016 - codes[navyblue]=017 - codes[darkblue]=018 - codes[blue3]=019 - codes[blue3]=020 - codes[blue1]=021 - codes[darkgreen]=022 - codes[deepskyblue4]=023 - codes[deepskyblue4]=024 - codes[deepskyblue4]=025 - codes[dodgerblue3]=026 - codes[dodgerblue2]=027 - codes[green4]=028 - codes[springgreen4]=029 - codes[turquoise4]=030 - codes[deepskyblue3]=031 - codes[deepskyblue3]=032 - codes[dodgerblue1]=033 - codes[green3]=034 - codes[springgreen3]=035 - codes[darkcyan]=036 - codes[lightseagreen]=037 - codes[deepskyblue2]=038 - codes[deepskyblue1]=039 - codes[green3]=040 - codes[springgreen3]=041 - codes[springgreen2]=042 - codes[cyan3]=043 - codes[darkturquoise]=044 - codes[turquoise2]=045 - codes[green1]=046 - codes[springgreen2]=047 - codes[springgreen1]=048 - codes[mediumspringgreen]=049 - codes[cyan2]=050 - codes[cyan1]=051 - codes[darkred]=052 - codes[deeppink4]=053 - codes[purple4]=054 - codes[purple4]=055 - codes[purple3]=056 - codes[blueviolet]=057 - codes[orange4]=058 - codes[grey37]=059 - codes[mediumpurple4]=060 - codes[slateblue3]=061 - codes[slateblue3]=062 - codes[royalblue1]=063 - codes[chartreuse4]=064 - codes[darkseagreen4]=065 - codes[paleturquoise4]=066 - codes[steelblue]=067 - codes[steelblue3]=068 - codes[cornflowerblue]=069 - codes[chartreuse3]=070 - codes[darkseagreen4]=071 - codes[cadetblue]=072 - codes[cadetblue]=073 - codes[skyblue3]=074 - codes[steelblue1]=075 - codes[chartreuse3]=076 - codes[palegreen3]=077 - codes[seagreen3]=078 - codes[aquamarine3]=079 - codes[mediumturquoise]=080 - codes[steelblue1]=081 - codes[chartreuse2]=082 - codes[seagreen2]=083 - codes[seagreen1]=084 - codes[seagreen1]=085 - codes[aquamarine1]=086 - codes[darkslategray2]=087 - codes[darkred]=088 - codes[deeppink4]=089 - codes[darkmagenta]=090 - codes[darkmagenta]=091 - codes[darkviolet]=092 - codes[purple]=093 - codes[orange4]=094 - codes[lightpink4]=095 - codes[plum4]=096 - codes[mediumpurple3]=097 - codes[mediumpurple3]=098 - codes[slateblue1]=099 - codes[yellow4]=100 - codes[wheat4]=101 - codes[grey53]=102 - codes[lightslategrey]=103 - codes[mediumpurple]=104 - codes[lightslateblue]=105 - codes[yellow4]=106 - codes[darkolivegreen3]=107 - codes[darkseagreen]=108 - codes[lightskyblue3]=109 - codes[lightskyblue3]=110 - codes[skyblue2]=111 - codes[chartreuse2]=112 - codes[darkolivegreen3]=113 - codes[palegreen3]=114 - codes[darkseagreen3]=115 - codes[darkslategray3]=116 - codes[skyblue1]=117 - codes[chartreuse1]=118 - codes[lightgreen]=119 - codes[lightgreen]=120 - codes[palegreen1]=121 - codes[aquamarine1]=122 - codes[darkslategray1]=123 - codes[red3]=124 - codes[deeppink4]=125 - codes[mediumvioletred]=126 - codes[magenta3]=127 - codes[darkviolet]=128 - codes[purple]=129 - codes[darkorange3]=130 - codes[indianred]=131 - codes[hotpink3]=132 - codes[mediumorchid3]=133 - codes[mediumorchid]=134 - codes[mediumpurple2]=135 - codes[darkgoldenrod]=136 - codes[lightsalmon3]=137 - codes[rosybrown]=138 - codes[grey63]=139 - codes[mediumpurple2]=140 - codes[mediumpurple1]=141 - codes[gold3]=142 - codes[darkkhaki]=143 - codes[navajowhite3]=144 - codes[grey69]=145 - codes[lightsteelblue3]=146 - codes[lightsteelblue]=147 - codes[yellow3]=148 - codes[darkolivegreen3]=149 - codes[darkseagreen3]=150 - codes[darkseagreen2]=151 - codes[lightcyan3]=152 - codes[lightskyblue1]=153 - codes[greenyellow]=154 - codes[darkolivegreen2]=155 - codes[palegreen1]=156 - codes[darkseagreen2]=157 - codes[darkseagreen1]=158 - codes[paleturquoise1]=159 - codes[red3]=160 - codes[deeppink3]=161 - codes[deeppink3]=162 - codes[magenta3]=163 - codes[magenta3]=164 - codes[magenta2]=165 - codes[darkorange3]=166 - codes[indianred]=167 - codes[hotpink3]=168 - codes[hotpink2]=169 - codes[orchid]=170 - codes[mediumorchid1]=171 - codes[orange3]=172 - codes[lightsalmon3]=173 - codes[lightpink3]=174 - codes[pink3]=175 - codes[plum3]=176 - codes[violet]=177 - codes[gold3]=178 - codes[lightgoldenrod3]=179 - codes[tan]=180 - codes[mistyrose3]=181 - codes[thistle3]=182 - codes[plum2]=183 - codes[yellow3]=184 - codes[khaki3]=185 - codes[lightgoldenrod2]=186 - codes[lightyellow3]=187 - codes[grey84]=188 - codes[lightsteelblue1]=189 - codes[yellow2]=190 - codes[darkolivegreen1]=191 - codes[darkolivegreen1]=192 - codes[darkseagreen1]=193 - codes[honeydew2]=194 - codes[lightcyan1]=195 - codes[red1]=196 - codes[deeppink2]=197 - codes[deeppink1]=198 - codes[deeppink1]=199 - codes[magenta2]=200 - codes[magenta1]=201 - codes[orangered1]=202 - codes[indianred1]=203 - codes[indianred1]=204 - codes[hotpink]=205 - codes[hotpink]=206 - codes[mediumorchid1]=207 - codes[darkorange]=208 - codes[salmon1]=209 - codes[lightcoral]=210 - codes[palevioletred1]=211 - codes[orchid2]=212 - codes[orchid1]=213 - codes[orange1]=214 - codes[sandybrown]=215 - codes[lightsalmon1]=216 - codes[lightpink1]=217 - codes[pink1]=218 - codes[plum1]=219 - codes[gold1]=220 - codes[lightgoldenrod2]=221 - codes[lightgoldenrod2]=222 - codes[navajowhite1]=223 - codes[mistyrose1]=224 - codes[thistle1]=225 - codes[yellow1]=226 - codes[lightgoldenrod1]=227 - codes[khaki1]=228 - codes[wheat1]=229 - codes[cornsilk1]=230 - codes[grey100]=231 - codes[grey3]=232 - codes[grey7]=233 - codes[grey11]=234 - codes[grey15]=235 - codes[grey19]=236 - codes[grey23]=237 - codes[grey27]=238 - codes[grey30]=239 - codes[grey35]=240 - codes[grey39]=241 - codes[grey42]=242 - codes[grey46]=243 - codes[grey50]=244 - codes[grey54]=245 - codes[grey58]=246 - codes[grey62]=247 - codes[grey66]=248 - codes[grey70]=249 - codes[grey74]=250 - codes[grey78]=251 - codes[grey82]=252 - codes[grey85]=253 - codes[grey89]=254 - codes[grey93]=255 - # for testing purposes in terminal if [[ "$1" == "foreground" ]]; then # call via `getColorCode foreground` - for i in "${(k@)codes}"; do + for i in "${(k@)__P9K_COLORS}"; do print -P "$(foregroundColor $i)$(getColor $i) - $i%f" done elif [[ "$1" == "background" ]]; then # call via `getColorCode background` - for i in "${(k@)codes}"; do + for i in "${(k@)__P9K_COLORS}"; do print -P "$(backgroundColor $i)$(getColor $i) - $i%k" done else @@ -349,7 +351,7 @@ function getColorCode() { 1=${1#fg-} # Strip eventual "br" prefixes ("bright" colors) 1=${1#br} - echo -n $codes[$1] + echo -n $__P9K_COLORS[$1] fi fi } From 02506893a92f3861c3f62e5aedf4876dd1b9672f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 21:58:32 +0200 Subject: [PATCH 080/103] Remove duplicate variable --- powerlevel9k.zsh-theme | 5 ----- 1 file changed, 5 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 92917345..27f5dc4e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -278,11 +278,6 @@ right_prompt_segment() { # Prompt Segment Definitions ################################################################ -# The `CURRENT_BG` variable is used to remember what the last BG color used was -# when building the left-hand prompt. Because the RPROMPT is created from -# right-left but reads the opposite, this isn't necessary for the other side. -CURRENT_BG='NONE' - ################################################################ # Anaconda Environment prompt_anaconda() { From 93324c0600e57e5c3b6b4c10be972e83f3c88526 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 7 Aug 2018 22:00:11 +0200 Subject: [PATCH 081/103] Improve naming of variables As a side effect this should improve the performance slightly, as we get the fore- and background color codes as early as possible, and store the result, so that we don't have to recalculate the color code all over. --- powerlevel9k.zsh-theme | 80 ++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 27f5dc4e..6fef6a26 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -111,45 +111,54 @@ CURRENT_BG='NONE' set_default last_left_element_index 1 set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { + local segment_name="${1}" local current_index=$2 # Check if the segment should be joined with the previous one local joined segmentShouldBeJoined $current_index $last_left_element_index "$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS" && joined=true || joined=false + # Colors + local backgroundColor="${3}" + local foregroundColor="${4}" + # Overwrite given background-color by user defined variable for this segment. - local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND + local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_BACKGROUND local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} - [[ -n $BG_COLOR_MODIFIER ]] && 3="$BG_COLOR_MODIFIER" + [[ -n $BG_COLOR_MODIFIER ]] && backgroundColor="$BG_COLOR_MODIFIER" # Overwrite given foreground-color by user defined variable for this segment. - local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_FOREGROUND + local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_FOREGROUND local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} - [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" + [[ -n $FG_COLOR_MODIFIER ]] && foregroundColor="$FG_COLOR_MODIFIER" + + # Get color codes here to save some calls later on + backgroundColor="$(getColorCode ${backgroundColor})" + foregroundColor="$(getColorCode ${foregroundColor})" - local bg fg - [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="%k" - [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="%f" + local background foreground + [[ -n "${backgroundColor}" ]] && background="$(backgroundColor ${backgroundColor})" || background="%k" + [[ -n "${foregroundColor}" ]] && foreground="$(foregroundColor ${foregroundColor})" || foreground="%f" - if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then - echo -n "$bg%F{$CURRENT_BG}" + if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "${backgroundColor}" "$CURRENT_BG"; then + echo -n "${background}%F{$CURRENT_BG}" if [[ $joined == false ]]; then # Middle segment echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi - elif isSameColor "$CURRENT_BG" "$3"; then + elif isSameColor "$CURRENT_BG" "${backgroundColor}"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our # subsegment (or the default color). This should have # enough contrast. local complement - [[ -n "$4" ]] && complement="$fg" || complement="$(foregroundColor $DEFAULT_COLOR)" - echo -n "${bg}${complement}" + [[ -n "${foregroundColor}" ]] && complement="${foreground}" || complement="$(foregroundColor $DEFAULT_COLOR)" + echo -n "${background}${complement}" if [[ $joined == false ]]; then echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi else # First segment - echo -n "${bg}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "${background}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi local visual_identifier @@ -161,8 +170,8 @@ left_prompt_segment() { # we need to color both the visual identifier and the whitespace. [[ -n "$5" ]] && visual_identifier="$visual_identifier " # Allow users to overwrite the color for the visual identifier only. - local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR - set_default $visual_identifier_color_variable $4 + local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable "${foregroundColor}" visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" fi fi @@ -170,10 +179,10 @@ left_prompt_segment() { # Print the visual identifier echo -n "${visual_identifier}" # Print the content of the segment, if there is any - [[ -n "$5" ]] && echo -n "${fg}${5}" + [[ -n "$5" ]] && echo -n "${foreground}${5}" echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" - CURRENT_BG="$(getColorCode ${3})" + CURRENT_BG="${backgroundColor}" last_left_element_index=$current_index } @@ -203,25 +212,34 @@ CURRENT_RIGHT_BG='NONE' set_default last_right_element_index 1 set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { + local segment_name="${1}" local current_index=$2 # Check if the segment should be joined with the previous one local joined segmentShouldBeJoined $current_index $last_right_element_index "$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS" && joined=true || joined=false + # Colors + local backgroundColor="${3}" + local foregroundColor="${4}" + # Overwrite given background-color by user defined variable for this segment. - local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND + local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_BACKGROUND local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE} - [[ -n $BG_COLOR_MODIFIER ]] && 3="$BG_COLOR_MODIFIER" + [[ -n $BG_COLOR_MODIFIER ]] && backgroundColor="$BG_COLOR_MODIFIER" # Overwrite given foreground-color by user defined variable for this segment. - local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_FOREGROUND + local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_FOREGROUND local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" - local bg fg - [[ -n "$3" ]] && bg="$(backgroundColor $3)" || bg="%k" - [[ -n "$4" ]] && fg="$(foregroundColor $4)" || fg="%f" + # Get color codes here to save some calls later on + backgroundColor="$(getColorCode ${backgroundColor})" + foregroundColor="$(getColorCode ${foregroundColor})" + + local background foreground + [[ -n "${backgroundColor}" ]] && background="$(backgroundColor ${backgroundColor})" || background="%k" + [[ -n "${foregroundColor}" ]] && foreground="$(foregroundColor ${foregroundColor})" || foreground="%f" # If CURRENT_RIGHT_BG is "NONE", we are the first right segment. @@ -231,17 +249,17 @@ right_prompt_segment() { fi if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then - if isSameColor "$CURRENT_RIGHT_BG" "$3"; then + if isSameColor "$CURRENT_RIGHT_BG" "${backgroundColor}"; then # Middle segment with same color as previous segment # We take the current foreground color as color for our # subsegment (or the default color). This should have # enough contrast. local complement - [[ -n "$4" ]] && complement="$fg" || complement="$(foregroundColor $DEFAULT_COLOR)" + [[ -n "${foregroundColor}" ]] && complement="${foreground}" || complement="$(foregroundColor $DEFAULT_COLOR)" echo -n "$complement$(print_icon 'RIGHT_SUBSEGMENT_SEPARATOR')%f" else - # Use the new BG color for the foreground with separator - echo -n "$(foregroundColor $3)$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f" + # Use the new Background Color as the foreground of the segment separator + echo -n "$(foregroundColor ${backgroundColor})$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f" fi fi @@ -254,13 +272,13 @@ right_prompt_segment() { # we need to color both the visual identifier and the whitespace. [[ -n "$5" ]] && visual_identifier=" $visual_identifier" # Allow users to overwrite the color for the visual identifier only. - local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR - set_default $visual_identifier_color_variable $4 + local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable "${foregroundColor}" visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" fi fi - echo -n "${bg}${fg}" + echo -n "${background}${foreground}" # Print whitespace only if segment is not joined or first right segment [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" @@ -270,7 +288,7 @@ right_prompt_segment() { # Print the visual identifier echo -n "${visual_identifier}" - CURRENT_RIGHT_BG=$3 + CURRENT_RIGHT_BG="${backgroundColor}" last_right_element_index=$current_index } From beacb0ad35250e66bb04f00d1dcb4f1d4574cb81 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 00:40:05 +0200 Subject: [PATCH 082/103] Fix bright colors Remove old code that set bright colors equal to normal colors. This code was ancient and led to bright colors being unusable. The code originates from 0e37d8ef865daddd6af02ba78b4a3bb86fd5917e. --- functions/colors.zsh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 17caa201..9ab8c18b 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -323,12 +323,6 @@ function foregroundColor() { function getColorCode() { # Check if given value is already numerical if [[ "$1" = <-> ]]; then - # ANSI color codes distinguish between "foreground" - # and "background" colors. We don't need to do that, - # as ZSH uses a 256 color space anyway. - if [[ "$1" = <8-15> ]]; then - echo -n $(($1 - 8)) - else echo -n "$1" fi else From 19235b2359ce9307a1672cc79cdcfe4a207658e5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 00:40:41 +0200 Subject: [PATCH 083/103] Always use color codes instead of named colors This Code was to check if the color is supported by the Terminal Emulator. This is not necessary, if we always use the numerical code. This makes the code much clearer. --- functions/colors.zsh | 59 +++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 9ab8c18b..758b3446 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -294,16 +294,7 @@ function termColors() { function getColor() { # If Color is not numerical, try to get the color code. if [[ "$1" != <-> ]]; then - # named color added to parameter expansion print -P to test if the name exists in terminal - local named="%K{$1}" - # https://misc.flogisoft.com/bash/tip_colors_and_formatting - local default="$'\033'\[49m" - # http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html - local quoted=$(printf "%q" $(print -P "$named")) - if [[ $quoted == "$'\033'\[49m" && $1 != "black" ]]; then - # color not found, so try to get the code - 1=$(getColorCode $1) - fi + 1=$(getColorCode $1) fi echo -n "$1" } @@ -321,32 +312,32 @@ function foregroundColor() { # Get numerical color codes. That way we translate ANSI codes # into ZSH-Style color codes. function getColorCode() { - # Check if given value is already numerical + # Early exit: Check if given value is already numerical if [[ "$1" = <-> ]]; then - echo -n "$1" - fi + echo -n "$1" + return + fi + + local colorName="${1}" + # for testing purposes in terminal + if [[ "${colorName}" == "foreground" ]]; then + # call via `getColorCode foreground` + for i in "${(k@)__P9K_COLORS}"; do + print -P "$(foregroundColor $i)$(getColor $i) - $i%f" + done + elif [[ "${colorName}" == "background" ]]; then + # call via `getColorCode background` + for i in "${(k@)__P9K_COLORS}"; do + print -P "$(backgroundColor $i)$(getColor $i) - $i%k" + done else - # for testing purposes in terminal - if [[ "$1" == "foreground" ]]; then - # call via `getColorCode foreground` - for i in "${(k@)__P9K_COLORS}"; do - print -P "$(foregroundColor $i)$(getColor $i) - $i%f" - done - elif [[ "$1" == "background" ]]; then - # call via `getColorCode background` - for i in "${(k@)__P9K_COLORS}"; do - print -P "$(backgroundColor $i)$(getColor $i) - $i%k" - done - else - #[[ -n "$1" ]] bg="%K{$1}" || bg="%k" - # Strip eventual "bg-" prefixes - 1=${1#bg-} - # Strip eventual "fg-" prefixes - 1=${1#fg-} - # Strip eventual "br" prefixes ("bright" colors) - 1=${1#br} - echo -n $__P9K_COLORS[$1] - fi + # Strip eventual "bg-" prefixes + colorName=${colorName#bg-} + # Strip eventual "fg-" prefixes + colorName=${colorName#fg-} + # Strip eventual "br" prefixes ("bright" colors) + colorName=${colorName#br} + echo -n $__P9K_COLORS[$colorName] fi } From e970a021c867976c52365c7d6b731b561539966e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 00:42:42 +0200 Subject: [PATCH 084/103] Fix tests --- test/powerlevel9k.spec | 16 ++--- test/segments/command_execution_time.spec | 14 ++-- test/segments/dir.spec | 80 +++++++++++------------ test/segments/go_version.spec | 8 +-- test/segments/kubecontext.spec | 6 +- test/segments/laravel_version.spec | 6 +- test/segments/rust_version.spec | 4 +- test/segments/status.spec | 14 ++-- test/segments/vcs.spec | 18 ++--- 9 files changed, 83 insertions(+), 83 deletions(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 0ddf36c1..2206a9d0 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -20,7 +20,7 @@ function testJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp %K{012}%F{000}%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -30,7 +30,7 @@ function testTransitiveJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black}%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp %K{012}%F{000}%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -40,7 +40,7 @@ function testJoiningWithConditionalSegment() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined) cd /tmp - assertEquals "%K{blue} %F{black}/tmp %K{blue}%F{black} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp %K{012}%F{000} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS cd - @@ -51,7 +51,7 @@ function testDynamicColoringOfSegmentsWork() { POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' cd /tmp - assertEquals "%K{red} %F{black}/tmp %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{000}/tmp %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_BACKGROUND @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{blue} %F{green%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{green%}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -86,7 +86,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{yellow} %F{green%}icon-here %f%F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{011} %F{green%}icon-here %f%F{009}/tmp %k%F{011}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -106,7 +106,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{blue} %F{black%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON @@ -123,7 +123,7 @@ function testNewlineOnRpromptCanBeDisabled() { POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) powerlevel9k_prepare_prompts - assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" + assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" unset POWERLEVEL9K_PROMPT_ON_NEWLINE unset POWERLEVEL9K_RPROMPT_ON_NEWLINE diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index d3588d83..7e060be7 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -16,7 +16,7 @@ function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { POWERLEVEL9K_CUSTOM_WORLD='echo world' _P9K_COMMAND_DURATION=2 - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD @@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 _P9K_COMMAND_DURATION=2.03 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}2.03 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 _P9K_COMMAND_DURATION=0.03 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}0.03 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 _P9K_COMMAND_DURATION=0.0001 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}0.0001 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 _P9K_COMMAND_DURATION=23.5001 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}23 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=180 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}03:00 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=7200 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}Dur %f%F{226}02:00:00 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION diff --git a/test/segments/dir.spec b/test/segments/dir.spec index b5fce59f..c16e32fc 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -22,7 +22,7 @@ function testDirPathAbsoluteWorks() { POWERLEVEL9K_DIR_PATH_ABSOLUTE=true cd ~ - assertEquals "%K{blue} %F{black}/home/travis %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/home/travis %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_ABSOLUTE @@ -36,7 +36,7 @@ function testTruncateFoldersWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}…/12345678/123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -57,7 +57,7 @@ function testTruncateFolderWithHomeDirWorks() { # Switch back to home folder as this causes the problem. cd .. - assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}~ %k%F{012}%f " "$(build_left_prompt)" rmdir $FOLDER cd ${CURRENT_DIR} @@ -75,7 +75,7 @@ function testTruncateMiddleWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -93,7 +93,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -111,7 +111,7 @@ function testTruncateToLastWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -129,7 +129,7 @@ function testTruncateToFirstAndLastWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -147,7 +147,7 @@ function testTruncateAbsoluteWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}…89 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}…89 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -166,7 +166,7 @@ function testTruncationFromRightWithEmptyDelimiter() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -187,7 +187,7 @@ function testTruncateWithFolderMarkerWorks() { # Setup folder marker touch $BASEFOLDER/1/12/.shorten_folder_marker cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -208,7 +208,7 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { # Setup folder marker touch $BASEFOLDER/1/12/.xxx cd $FOLDER - assertEquals "%K{blue} %F{black}/…/12/123/1234/12345/123456/1234567 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -241,7 +241,7 @@ function testTruncateWithPackageNameWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{012}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -280,7 +280,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}My_Package/as…/qwerqwer %k%F{012}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -315,7 +315,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' - assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}My_Package/.g…/re…/heads %k%F{012}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -329,7 +329,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}home-icon %f%F{000}~ %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -341,7 +341,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}sub-icon %f%F{000}~/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -355,7 +355,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -369,7 +369,7 @@ function testChangingDirPathSeparator() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - unset FOLDER @@ -384,20 +384,20 @@ function testHomeFolderAbbreviation() { cd ~/ # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}~ %k%F{012}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}qQq %k%F{012}%f " "$(build_left_prompt)" cd /tmp # default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' - assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" # substituted POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' - assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" cd "$dir" } @@ -407,7 +407,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}folder-icon %f%F{000}tmp %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -421,7 +421,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000%}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -445,7 +445,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}xXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -463,7 +463,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…stxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}tmpxXxpo…stxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -481,7 +481,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black}tmpxXxpo…xXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}tmpxXxpo…xXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -502,7 +502,7 @@ function testTruncateToUniqueWorks() { mkdir -p /tmp/powerlevel9k-test/bob/docs cd /tmp/powerlevel9k-test/alice/devl - assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}txXxpxXxalxXxde %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -516,7 +516,7 @@ function testBoldHomeDirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd ~ - assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}%B~%b %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD @@ -527,7 +527,7 @@ function testBoldHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{blue} %F{black}~/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}~/%Bpowerlevel9k-test%b %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -538,7 +538,7 @@ function testBoldRootDirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd / - assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}%B/%b %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD @@ -548,7 +548,7 @@ function testBoldRootSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true cd /tmp - assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/%Btmp%b %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD @@ -559,7 +559,7 @@ function testBoldRootSubSubdirWorks() { mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{blue} %F{black}/tmp/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/%Bpowerlevel9k-test%b %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -570,7 +570,7 @@ function testHighlightHomeWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd ~ - assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}%F{red}~ %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -581,7 +581,7 @@ function testHighlightHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{blue} %F{black}~/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}~/%F{red}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -592,7 +592,7 @@ function testHighlightRootWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd / - assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}%F{red}/ %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -602,7 +602,7 @@ function testHighlightRootSubdirWorks() { POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' cd /tmp - assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/%F{red}tmp %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND @@ -613,7 +613,7 @@ function testHighlightRootSubSubdirWorks() { mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{blue} %F{black}/tmp/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}/tmp/%F{red}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -625,7 +625,7 @@ function testDirSeparatorColorHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{blue} %F{black}~%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}~%F{red}/%F{black}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -637,7 +637,7 @@ function testDirSeparatorColorRootSubSubdirWorks() { mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{blue} %F{black}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 9104ac8b..30b157a5 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{002} %F{255%} %f%F{255}go1.5.3 %k%F{002}%f " "$(build_left_prompt)" unset POWERLEVEL9K_GO_ICON unset PWD @@ -53,7 +53,7 @@ function testGoSegmentPrintsNothingIfEmptyGopath() { POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD @@ -65,7 +65,7 @@ function testGoSegmentPrintsNothingIfNotInGopath() { POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD @@ -76,7 +76,7 @@ function testGoSegmentPrintsNothingIfGoIsNotAvailable() { POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 63810378..33853a3f 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -69,7 +69,7 @@ function testKubeContext() { alias kubectl=mockKubectl POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{013} %F{015%}⎈ %f%F{015}minikube/default %k%F{013}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl @@ -78,7 +78,7 @@ function testKubeContextOtherNamespace() { alias kubectl=mockKubectlOtherNamespace POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{013} %F{015%}⎈ %f%F{015}minikube/kube-system %k%F{013}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl @@ -88,7 +88,7 @@ function testKubeContextPrintsNothingIfKubectlNotAvailable() { POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index 40b130d2..ffc11786 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -31,7 +31,7 @@ function testLaravelVersionSegment() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) - assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{015%}x %f%F{015}5.4.23 %k%F{001}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON @@ -44,7 +44,7 @@ function testLaravelVersionSegmentIfArtisanIsNotAvailable() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON @@ -58,7 +58,7 @@ function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 34883a10..7031be87 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -32,7 +32,7 @@ function testRust() { mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{000%}Rust %f%F{000}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } @@ -41,7 +41,7 @@ function testRustPrintsNothingIfRustIsNotAvailable() { POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD diff --git a/test/segments/status.spec b/test/segments/status.spec index 21bd65bb..fc44275e 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -22,7 +22,7 @@ function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { local POWERLEVEL9K_STATUS_VERBOSE=false local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false - assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" } function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { @@ -31,7 +31,7 @@ function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) - assertEquals "%K{black} %F{green%}✔%f %k%F{black}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002%}✔%f %k%F{000}%f " "$(build_left_prompt)" } function testStatusInGeneralErrorCase() { @@ -40,7 +40,7 @@ function testStatusInGeneralErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false - assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}1 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}↵ %f%F{226}1 %k%F{009}%f " "$(build_left_prompt)" } function testPipestatusInErrorCase() { @@ -50,7 +50,7 @@ function testPipestatusInErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true - assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}0|0|1|0 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}↵ %f%F{226}0|0|1|0 %k%F{009}%f " "$(build_left_prompt)" } function testStatusCrossWinsOverVerbose() { @@ -60,7 +60,7 @@ function testStatusCrossWinsOverVerbose() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_CROSS=true - assertEquals "%K{black} %F{red%}✘%f %k%F{black}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{009%}✘%f %k%F{000}%f " "$(build_left_prompt)" } function testStatusShowsSignalNameInErrorCase() { @@ -70,7 +70,7 @@ function testStatusShowsSignalNameInErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false - assertEquals "%K{red} %F{yellow1%}↵ %f%F{yellow1}SIGILL(4) %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226%}↵ %f%F{226}SIGILL(4) %k%F{009}%f " "$(build_left_prompt)" } function testStatusSegmentIntegrated() { @@ -79,7 +79,7 @@ function testStatusSegmentIntegrated() { false; powerlevel9k_prepare_prompts - assertEquals "%f%b%k%K{black} %F{red%}✘%f %k%F{black}%f " "${(e)PROMPT}" + assertEquals "%f%b%k%K{000} %F{009%}✘%f %k%F{000}%f " "${(e)PROMPT}" } source shunit2/source/2.1/src/shunit2 \ No newline at end of file diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec index f6474f61..3be7aa0f 100755 --- a/test/segments/vcs.spec +++ b/test/segments/vcs.spec @@ -21,7 +21,7 @@ function testColorOverridingForCleanStateWorks() { cd $FOLDER git init 1>/dev/null - assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{015} %F{014} master %k%F{015}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -47,7 +47,7 @@ function testColorOverridingForModifiedStateWorks() { git commit -m "test" 1>/dev/null echo "test" > testfile - assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{011} %F{009} master ● %k%F{011}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -68,7 +68,7 @@ function testColorOverridingForUntrackedStateWorks() { git init 1>/dev/null touch testfile - assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{011} %F{014} master ? %k%F{011}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -90,10 +90,10 @@ function testBranchNameTruncatingShortenLength() { git init 1>/dev/null touch testfile - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" POWERLEVEL9K_VCS_SHORTEN_LENGTH=3 - assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} mas… ? %k%F{002}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -116,11 +116,11 @@ function testBranchNameTruncatingMinLength() { git init 1>/dev/null touch testfile - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7 - assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -143,11 +143,11 @@ function testBranchNameTruncatingShortenStrategy() { git init 1>/dev/null touch testfile - assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} mas… ? %k%F{002}%f " "$(build_left_prompt)" POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle" - assertEquals "%K{green} %F{black} mas…ter ? %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} mas…ter ? %k%F{002}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test From 39fe5217c6346297def6d811889fcde5c1e3fc30 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 01:00:43 +0200 Subject: [PATCH 085/103] Pad colors with zeroes --- functions/colors.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 758b3446..71ca7c9a 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -314,7 +314,8 @@ function foregroundColor() { function getColorCode() { # Early exit: Check if given value is already numerical if [[ "$1" = <-> ]]; then - echo -n "$1" + # Pad color with zeroes + echo -n "${(l:3::0:)1}" return fi From 057b07b214def74248628a841f95045e3e85028c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 01:01:14 +0200 Subject: [PATCH 086/103] Fix tests --- test/functions/colors.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functions/colors.spec b/test/functions/colors.spec index 61a40087..b8fa3ad5 100755 --- a/test/functions/colors.spec +++ b/test/functions/colors.spec @@ -30,8 +30,8 @@ function testIsSameColorComparesAnsiBackgroundAndNumericalColorCorrectly() { assertTrue "isSameColor 'bg-green' '002'" } -function testIsSameColorComparesNumericalBackgroundAndNumericalColorCorrectly() { - assertTrue "isSameColor '010' '2'" +function testIsSameColorComparesShortCodesCorrectly() { + assertTrue "isSameColor '002' '2'" } function testIsSameColorDoesNotYieldNotEqualColorsTruthy() { From 424d41761d819e127309af0c31837b91f2bb24a1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 01:11:44 +0200 Subject: [PATCH 087/103] Write comparison with double quotes --- functions/colors.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 71ca7c9a..f4f211ca 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -313,7 +313,7 @@ function foregroundColor() { # into ZSH-Style color codes. function getColorCode() { # Early exit: Check if given value is already numerical - if [[ "$1" = <-> ]]; then + if [[ "$1" == <-> ]]; then # Pad color with zeroes echo -n "${(l:3::0:)1}" return From 6f5827009fa3a39cc04ab205da2da44965d9a00c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 23:18:36 +0200 Subject: [PATCH 088/103] Fix colors for visual identifiers Make the visual identifier color use numerical color codes as well. This way colors like "purple3" work as visual identifier color. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6fef6a26..a9b2d1ff 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -172,7 +172,7 @@ left_prompt_segment() { # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable "${foregroundColor}" - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f" fi fi @@ -274,7 +274,7 @@ right_prompt_segment() { # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)${segment_name}#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable "${foregroundColor}" - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + visual_identifier="$(foregroundColor ${(P)visual_identifier_color_variable})${visual_identifier}%f" fi fi From 27fe2c65712a092c8e652fe2c58ac310f69a8e36 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 23:36:40 +0200 Subject: [PATCH 089/103] Make use of helper function in left_end_segment --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a9b2d1ff..781813e7 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -189,7 +189,7 @@ left_prompt_segment() { # End the left prompt, closes the final segment. left_prompt_end() { if [[ -n $CURRENT_BG ]]; then - echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" + echo -n "%k$(foregroundColor ${CURRENT_BG})$(print_icon 'LEFT_SEGMENT_SEPARATOR')" else echo -n "%k" fi From ef5f9bb1b494bcb1ceb81f7c833750d85701ca4a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 8 Aug 2018 23:47:01 +0200 Subject: [PATCH 090/103] Fix tests --- test/powerlevel9k.spec | 6 +++--- test/segments/command_execution_time.spec | 12 ++++++------ test/segments/dir.spec | 10 +++++----- test/segments/go_version.spec | 2 +- test/segments/kubecontext.spec | 4 ++-- test/segments/laravel_version.spec | 2 +- test/segments/rust_version.spec | 2 +- test/segments/status.spec | 12 ++++++------ 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 2206a9d0..b5b81fc4 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{012} %F{green%}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{002}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -86,7 +86,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{011} %F{green%}icon-here %f%F{009}/tmp %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{011} %F{002}icon-here %f%F{009}/tmp %k%F{011}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -106,7 +106,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{012} %F{000%}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index 7e060be7..fc6110e4 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 _P9K_COMMAND_DURATION=2.03 - assertEquals "%K{009} %F{226%}Dur %f%F{226}2.03 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}2.03 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 _P9K_COMMAND_DURATION=0.03 - assertEquals "%K{009} %F{226%}Dur %f%F{226}0.03 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}0.03 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 _P9K_COMMAND_DURATION=0.0001 - assertEquals "%K{009} %F{226%}Dur %f%F{226}0.0001 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}0.0001 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 _P9K_COMMAND_DURATION=23.5001 - assertEquals "%K{009} %F{226%}Dur %f%F{226}23 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}23 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=180 - assertEquals "%K{009} %F{226%}Dur %f%F{226}03:00 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}03:00 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=7200 - assertEquals "%K{009} %F{226%}Dur %f%F{226}02:00:00 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}Dur %f%F{226}02:00:00 %k%F{009}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION diff --git a/test/segments/dir.spec b/test/segments/dir.spec index c16e32fc..4e4022b1 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -329,7 +329,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{012} %F{000%}home-icon %f%F{000}~ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}home-icon %f%F{000}~ %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -341,7 +341,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000%}sub-icon %f%F{000}~/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}sub-icon %f%F{000}~/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -355,7 +355,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000%}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -407,7 +407,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{012} %F{000%}folder-icon %f%F{000}tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}folder-icon %f%F{000}tmp %k%F{012}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -421,7 +421,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{012} %F{000%}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{012} %F{000}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 30b157a5..39be4157 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{002} %F{255%} %f%F{255}go1.5.3 %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{255} %f%F{255}go1.5.3 %k%F{002}%f " "$(build_left_prompt)" unset POWERLEVEL9K_GO_ICON unset PWD diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 33853a3f..1457558f 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -69,7 +69,7 @@ function testKubeContext() { alias kubectl=mockKubectl POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{013} %F{015%}⎈ %f%F{015}minikube/default %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{013} %F{015}⎈ %f%F{015}minikube/default %k%F{013}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl @@ -78,7 +78,7 @@ function testKubeContextOtherNamespace() { alias kubectl=mockKubectlOtherNamespace POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{013} %F{015%}⎈ %f%F{015}minikube/kube-system %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{013} %F{015}⎈ %f%F{015}minikube/kube-system %k%F{013}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index ffc11786..b620ce8a 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -31,7 +31,7 @@ function testLaravelVersionSegment() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) - assertEquals "%K{001} %F{015%}x %f%F{015}5.4.23 %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{015}x %f%F{015}5.4.23 %k%F{001}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 7031be87..1317ba85 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -32,7 +32,7 @@ function testRust() { mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{000%}Rust %f%F{000}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{000}Rust %f%F{000}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } diff --git a/test/segments/status.spec b/test/segments/status.spec index fc44275e..8a9b6a1c 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -31,7 +31,7 @@ function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { local POWERLEVEL9K_STATUS_HIDE_SIGNAME=true local POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(status) - assertEquals "%K{000} %F{002%}✔%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}✔%f %k%F{000}%f " "$(build_left_prompt)" } function testStatusInGeneralErrorCase() { @@ -40,7 +40,7 @@ function testStatusInGeneralErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=false - assertEquals "%K{009} %F{226%}↵ %f%F{226}1 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}↵ %f%F{226}1 %k%F{009}%f " "$(build_left_prompt)" } function testPipestatusInErrorCase() { @@ -50,7 +50,7 @@ function testPipestatusInErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_SHOW_PIPESTATUS=true - assertEquals "%K{009} %F{226%}↵ %f%F{226}0|0|1|0 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}↵ %f%F{226}0|0|1|0 %k%F{009}%f " "$(build_left_prompt)" } function testStatusCrossWinsOverVerbose() { @@ -60,7 +60,7 @@ function testStatusCrossWinsOverVerbose() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_CROSS=true - assertEquals "%K{000} %F{009%}✘%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{009}✘%f %k%F{000}%f " "$(build_left_prompt)" } function testStatusShowsSignalNameInErrorCase() { @@ -70,7 +70,7 @@ function testStatusShowsSignalNameInErrorCase() { local POWERLEVEL9K_STATUS_VERBOSE=true local POWERLEVEL9K_STATUS_HIDE_SIGNAME=false - assertEquals "%K{009} %F{226%}↵ %f%F{226}SIGILL(4) %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{226}↵ %f%F{226}SIGILL(4) %k%F{009}%f " "$(build_left_prompt)" } function testStatusSegmentIntegrated() { @@ -79,7 +79,7 @@ function testStatusSegmentIntegrated() { false; powerlevel9k_prepare_prompts - assertEquals "%f%b%k%K{000} %F{009%}✘%f %k%F{000}%f " "${(e)PROMPT}" + assertEquals "%f%b%k%K{000} %F{009}✘%f %k%F{000}%f " "${(e)PROMPT}" } source shunit2/source/2.1/src/shunit2 \ No newline at end of file From a0d57bc455e654ba688d108219bd254863bca438 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 Aug 2018 08:11:19 +0200 Subject: [PATCH 091/103] Add test for bright colors --- test/functions/colors.spec | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/functions/colors.spec b/test/functions/colors.spec index d61923f5..e9ae9803 100755 --- a/test/functions/colors.spec +++ b/test/functions/colors.spec @@ -38,5 +38,14 @@ function testIsSameColorDoesNotYieldNotEqualColorsTruthy() { assertFalse "isSameColor 'green' '003'" } +function testBrightColorsWork() { + # We had some code in the past that equalized bright colors + # with normal ones. This code is now gone, and this test should + # ensure that all input channels for bright colors are handled + # correctly. + assertTrue "isSameColor 'cyan' '014'" + assertEquals '014' "$(getColorCode 'cyan')" + assertEquals '014' "$(getColor 'cyan')" +} source shunit2/shunit2 From 52ce9930bbb2971c7d3a20330928d3206f03c5ae Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 Aug 2018 23:20:48 +0200 Subject: [PATCH 092/103] Fix foreground colors in right prompt segments --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 781813e7..74caeb2d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -231,7 +231,7 @@ right_prompt_segment() { # Overwrite given foreground-color by user defined variable for this segment. local FOREGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)${segment_name}#prompt_}_FOREGROUND local FG_COLOR_MODIFIER=${(P)FOREGROUND_USER_VARIABLE} - [[ -n $FG_COLOR_MODIFIER ]] && 4="$FG_COLOR_MODIFIER" + [[ -n $FG_COLOR_MODIFIER ]] && foregroundColor="$FG_COLOR_MODIFIER" # Get color codes here to save some calls later on backgroundColor="$(getColorCode ${backgroundColor})" From 7a1319c2d98da16e0b2bd32dd43f9660a74ed8d7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 10 Aug 2018 00:47:20 +0200 Subject: [PATCH 093/103] Add tests for color comparisons with none colors --- test/functions/colors.spec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/functions/colors.spec b/test/functions/colors.spec index e9ae9803..ce777913 100755 --- a/test/functions/colors.spec +++ b/test/functions/colors.spec @@ -22,6 +22,10 @@ function testGetColorCodeWithNumericalColor() { assertEquals '002' "$(getColorCode '002')" } +function testGetColorCodeWithNoneColor() { + assertEquals 'none' "$(getColorCode 'NONE')" +} + function testIsSameColorComparesAnsiForegroundAndNumericalColorCorrectly() { assertTrue "isSameColor 'green' '002'" } @@ -38,6 +42,18 @@ function testIsSameColorDoesNotYieldNotEqualColorsTruthy() { assertFalse "isSameColor 'green' '003'" } +function testIsSameColorHandlesNoneCorrectly() { + assertTrue "isSameColor 'none' 'NOnE'" +} + +function testIsSameColorCompareTwoNoneColorsCorrectly() { + assertTrue "isSameColor 'none' 'none'" +} + +function testIsSameColorComparesColorWithNoneCorrectly() { + assertFalse "isSameColor 'green' 'none'" +} + function testBrightColorsWork() { # We had some code in the past that equalized bright colors # with normal ones. This code is now gone, and this test should From 3fb0383956d78d898520d58b99e1814a6670f140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Tue, 31 Jul 2018 16:22:26 -0400 Subject: [PATCH 094/103] Use SUDO_COMMAND to check for sudo `sudo -n true` only checks that we _could_ use `sudo`, not if we are in a sudo session. closes #852 --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0b2287ef..1cd49db0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -623,12 +623,12 @@ prompt_context() { if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then - if sudo -n true 2>/dev/null; then + if [[ -n "$SUDO_COMMAND" ]]; then current_state="REMOTE_SUDO" else current_state="REMOTE" fi - elif sudo -n true 2>/dev/null; then + elif [[ -n "$SUDO_COMMAND" ]]; then current_state="SUDO" fi @@ -651,7 +651,7 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) - elif sudo -n true 2>/dev/null; then + elif [[ -n "$SUDO_COMMAND" ]]; then user_state=( "STATE" "SUDO" "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" From 34bf8edc89f808a662c8ef8bea56cf1948d36cd7 Mon Sep 17 00:00:00 2001 From: Joseph Weigl <2631895+eloo@users.noreply.github.com> Date: Sat, 11 Aug 2018 16:18:23 +0200 Subject: [PATCH 095/103] Add fallback icon for linux distros --- functions/icons.zsh | 108 ++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index 358f9580..d8661e6f 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -48,24 +48,24 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 ANDROID_ICON $'\uE270' #  LINUX_ICON $'\uE271' #  - LINUX_ARCH_ICON 'Arc' - LINUX_DEBIAN_ICON 'Deb' - LINUX_UBUNTU_ICON 'Ubu' - LINUX_CENTOS_ICON 'Cen' - LINUX_COREOS_ICON 'Cor' - LINUX_ELEMENTARY_ICON 'Elm' - LINUX_MINT_ICON 'LMi' - LINUX_FEDORA_ICON 'Fed' - LINUX_GENTOO_ICON 'Gen' - LINUX_MAGEIA_ICON 'Mag' - LINUX_NIXOS_ICON 'Nix' - LINUX_MANJARO_ICON 'Man' - LINUX_DEVUAN_ICON 'Dev' - LINUX_ALPINE_ICON 'Alp' - LINUX_AOSC_ICON 'Aos' - LINUX_OPENSUSE_ICON 'OSu' - LINUX_SABAYON_ICON 'Sab' - LINUX_SLACKWARE_ICON 'Sla' + LINUX_ARCH_ICON $'\uE271' #  + LINUX_DEBIAN_ICON $'\uE271' #  + LINUX_UBUNTU_ICON $'\uE271' #  + LINUX_CENTOS_ICON $'\uE271' #  + LINUX_COREOS_ICON $'\uE271' #  + LINUX_ELEMENTARY_ICON $'\uE271' #  + LINUX_MINT_ICON $'\uE271' #  + LINUX_FEDORA_ICON $'\uE271' #  + LINUX_GENTOO_ICON $'\uE271' #  + LINUX_MAGEIA_ICON $'\uE271' #  + LINUX_NIXOS_ICON $'\uE271' #  + LINUX_MANJARO_ICON $'\uE271' #  + LINUX_DEVUAN_ICON $'\uE271' #  + LINUX_ALPINE_ICON $'\uE271' #  + LINUX_AOSC_ICON $'\uE271' #  + LINUX_OPENSUSE_ICON $'\uE271' #  + LINUX_SABAYON_ICON $'\uE271' #  + LINUX_SLACKWARE_ICON $'\uE271' #  SUNOS_ICON $'\U1F31E ' # 🌞 HOME_ICON $'\uE12C' #  HOME_SUB_ICON $'\uE18D' #  @@ -148,24 +148,24 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 ANDROID_ICON $'\uE17B' #  LINUX_ICON $'\uF17C' #  - LINUX_ARCH_ICON 'Arc' - LINUX_DEBIAN_ICON 'Deb' - LINUX_UBUNTU_ICON 'Ubu' - LINUX_CENTOS_ICON 'Cen' - LINUX_COREOS_ICON 'Cor' - LINUX_ELEMENTARY_ICON 'Elm' - LINUX_MINT_ICON 'LMi' - LINUX_FEDORA_ICON 'Fed' - LINUX_GENTOO_ICON 'Gen' - LINUX_MAGEIA_ICON 'Mag' - LINUX_NIXOS_ICON 'Nix' - LINUX_MANJARO_ICON 'Man' - LINUX_DEVUAN_ICON 'Dev' - LINUX_ALPINE_ICON 'Alp' - LINUX_AOSC_ICON 'Aos' - LINUX_OPENSUSE_ICON 'OSu' - LINUX_SABAYON_ICON 'Sab' - LINUX_SLACKWARE_ICON 'Sla' + LINUX_ARCH_ICON $'\uF17C' #  + LINUX_DEBIAN_ICON $'\uF17C' #  + LINUX_UBUNTU_ICON $'\uF17C' #  + LINUX_CENTOS_ICON $'\uF17C' #  + LINUX_COREOS_ICON $'\uF17C' #  + LINUX_ELEMENTARY_ICON $'\uF17C' #  + LINUX_MINT_ICON $'\uF17C' #  + LINUX_FEDORA_ICON $'\uF17C' #  + LINUX_GENTOO_ICON $'\uF17C' #  + LINUX_MAGEIA_ICON $'\uF17C' #  + LINUX_NIXOS_ICON $'\uF17C' #  + LINUX_MANJARO_ICON $'\uF17C' #  + LINUX_DEVUAN_ICON $'\uF17C' #  + LINUX_ALPINE_ICON $'\uF17C' #  + LINUX_AOSC_ICON $'\uF17C' #  + LINUX_OPENSUSE_ICON $'\uF17C' #  + LINUX_SABAYON_ICON $'\uF17C' #  + LINUX_SLACKWARE_ICON $'\uF17C' #  SUNOS_ICON $'\uF185 ' #  HOME_ICON $'\uF015' #  HOME_SUB_ICON $'\uF07C' #  @@ -250,24 +250,24 @@ case $POWERLEVEL9K_MODE in APPLE_ICON '\u'$CODEPOINT_OF_AWESOME_APPLE #  FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  - LINUX_ARCH_ICON 'Arc' - LINUX_DEBIAN_ICON 'Deb' - LINUX_UBUNTU_ICON 'Ubu' - LINUX_CENTOS_ICON 'Cen' - LINUX_COREOS_ICON 'Cor' - LINUX_ELEMENTARY_ICON 'Elm' - LINUX_MINT_ICON 'LMi' - LINUX_FEDORA_ICON 'Fed' - LINUX_GENTOO_ICON 'Gen' - LINUX_MAGEIA_ICON 'Mag' - LINUX_NIXOS_ICON 'Nix' - LINUX_MANJARO_ICON 'Man' - LINUX_DEVUAN_ICON 'Dev' - LINUX_ALPINE_ICON 'Alp' - LINUX_AOSC_ICON 'Aos' - LINUX_OPENSUSE_ICON 'OSu' - LINUX_SABAYON_ICON 'Sab' - LINUX_SLACKWARE_ICON 'Sla' + LINUX_ARCH_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEBIAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_UBUNTU_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_CENTOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_COREOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ELEMENTARY_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MINT_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_FEDORA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_GENTOO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MAGEIA_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_NIXOS_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_MANJARO_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_DEVUAN_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_ALPINE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_AOSC_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_OPENSUSE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SABAYON_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  + LINUX_SLACKWARE_ICON '\u'$CODEPOINT_OF_AWESOME_LINUX #  SUNOS_ICON '\u'$CODEPOINT_OF_AWESOME_SUN_O' ' #  HOME_ICON '\u'$CODEPOINT_OF_AWESOME_HOME #  HOME_SUB_ICON '\u'$CODEPOINT_OF_AWESOME_FOLDER_OPEN #  From cd723e779202d7b57b2d4cf6c8d31d5ea535723b Mon Sep 17 00:00:00 2001 From: Nina Zakharenko Date: Thu, 16 Aug 2018 22:33:47 -0700 Subject: [PATCH 096/103] Fix broken link in README referencing date and time configuration Fix broken link referencing zsh date and time configuration in prompt expansion. The current broken link points to `http://zsh.sourceforge.net/Doc/Release Prompt-Expansion.html`, while the correct link is http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Date-and-time --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9989d9cc..da72e918 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ The `date` segment shows the current system date. | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_DATE_FORMAT`|`%D{%d.%m.%y}`|[ZSH time format](http://zsh.sourceforge.net/Doc/Release Prompt-Expansion.html) to use in this segment.| +|`POWERLEVEL9K_DATE_FORMAT`|`%D{%d.%m.%y}`|[ZSH time format](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Date-and-time) to use in this segment.| ##### dir From 8e966e3636ce7c7162b60763088252b7111985e5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 17 Aug 2018 18:52:23 +0200 Subject: [PATCH 097/103] Change bright colors to old color codes Before this, there was no difference in that colors, as we always used the bright color codes. --- functions/colors.zsh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/functions/colors.zsh b/functions/colors.zsh index 8da5e481..80abb6be 100755 --- a/functions/colors.zsh +++ b/functions/colors.zsh @@ -11,23 +11,23 @@ typeset -gAh __P9K_COLORS # use color names by default to allow dark/light themes to adjust colors based on names __P9K_COLORS=( black 000 - maroon 001 + red 001 green 002 - olive 003 - navy 004 - purple 005 - teal 006 - silver 007 + yellow 003 + blue 004 + magenta 005 + cyan 006 + white 007 grey 008 - red 009 + maroon 009 lime 010 - yellow 011 - blue 012 + olive 011 + navy 012 fuchsia 013 - magenta 013 + purple 013 aqua 014 - cyan 014 - white 015 + teal 014 + silver 015 grey0 016 navyblue 017 darkblue 018 From df0c2198a0a7cb523c3d3428e1d70cb49018cd60 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 17 Aug 2018 18:53:26 +0200 Subject: [PATCH 098/103] Fix tests --- test/core/color_overriding.spec | 10 +-- test/core/joining_segments.spec | 28 ++++---- test/core/prompt.spec | 10 +-- test/core/visual_identifier.spec | 10 +-- test/functions/colors.spec | 6 +- test/powerlevel9k.spec | 14 ++-- test/segments/anaconda.spec | 8 +-- test/segments/aws_eb_env.spec | 2 +- test/segments/background_jobs.spec | 8 +-- test/segments/battery.spec | 22 +++--- test/segments/command_execution_time.spec | 14 ++-- test/segments/context.spec | 14 ++-- test/segments/custom.spec | 12 ++-- test/segments/detect_virt.spec | 8 +-- test/segments/dir.spec | 82 +++++++++++------------ test/segments/disk_usage.spec | 12 ++-- test/segments/go_version.spec | 6 +- test/segments/ip.spec | 16 ++--- test/segments/kubecontext.spec | 6 +- test/segments/laravel_version.spec | 6 +- test/segments/load.spec | 4 +- test/segments/node_version.spec | 4 +- test/segments/nodeenv.spec | 6 +- test/segments/nvm.spec | 6 +- test/segments/php_version.spec | 2 +- test/segments/public_ip.spec | 26 +++---- test/segments/ram.spec | 6 +- test/segments/rust_version.spec | 2 +- test/segments/ssh.spec | 8 +-- test/segments/status.spec | 12 ++-- test/segments/swap.spec | 4 +- test/segments/swift_version.spec | 4 +- test/segments/symfony_version.spec | 6 +- test/segments/todo.spec | 2 +- test/segments/vcs-git.spec | 12 ++-- test/segments/vcs-hg.spec | 8 +-- test/segments/vi_mode.spec | 8 +-- 37 files changed, 207 insertions(+), 207 deletions(-) diff --git a/test/core/color_overriding.spec b/test/core/color_overriding.spec index d3ed56ba..f2c3d891 100755 --- a/test/core/color_overriding.spec +++ b/test/core/color_overriding.spec @@ -16,7 +16,7 @@ function testDynamicColoringOfSegmentsWork() { local POWERLEVEL9K_DATE_ICON="date-icon" local POWERLEVEL9K_DATE_BACKGROUND='red' - assertEquals "%K{009} %F{000}date-icon %f%F{000}%D{%d.%m.%y} %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{000}date-icon %f%F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)" } function testDynamicColoringOfVisualIdentifiersWork() { @@ -24,7 +24,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { local POWERLEVEL9K_DATE_ICON="date-icon" local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' - assertEquals "%K{015} %F{002}date-icon %f%F{000}%D{%d.%m.%y} %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{002}date-icon %f%F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)" } function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { @@ -34,7 +34,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { local POWERLEVEL9K_DATE_FOREGROUND='red' local POWERLEVEL9K_DATE_BACKGROUND='yellow' - assertEquals "%K{011} %F{002}date-icon %f%F{009}%D{%d.%m.%y} %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{002}date-icon %f%F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)" } function testColorOverridingOfStatefulSegment() { @@ -45,7 +45,7 @@ function testColorOverridingOfStatefulSegment() { # Provoke state local SSH_CLIENT="x" - assertEquals "%K{009} %F{002}ssh-icon %f%F{002}%m %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{002}ssh-icon %f%F{002}%m %k%F{001}%f " "$(build_left_prompt)" } function testColorOverridingOfCustomSegment() { @@ -56,7 +56,7 @@ function testColorOverridingOfCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red' local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red' - assertEquals "%K{009} %F{002}CW %f%F{009}world %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{002}CW %f%F{001}world %k%F{001}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/core/joining_segments.spec b/test/core/joining_segments.spec index 42bf84dd..18213a52 100755 --- a/test/core/joining_segments.spec +++ b/test/core/joining_segments.spec @@ -21,7 +21,7 @@ function testLeftNormalSegmentsShouldNotBeJoined() { local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000} %F{000}world2 %K{015}%F{000} %F{000}world4 %K{015}%F{000} %F{000}world6 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world2 %K{007}%F{000} %F{000}world4 %K{007}%F{000} %F{000}world6 %k%F{007}%f " "$(build_left_prompt)" } function testLeftJoinedSegments() { @@ -30,7 +30,7 @@ function testLeftJoinedSegments() { local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000}%F{000}world2 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %k%F{007}%f " "$(build_left_prompt)" } function testLeftTransitiveJoinedSegments() { @@ -40,7 +40,7 @@ function testLeftTransitiveJoinedSegments() { local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000}%F{000}world2 %K{015}%F{000}%F{000}world3 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %K{007}%F{000}%F{000}world3 %k%F{007}%f " "$(build_left_prompt)" } function testLeftTransitiveJoiningWithConditionalJoinedSegment() { @@ -51,7 +51,7 @@ function testLeftTransitiveJoiningWithConditionalJoinedSegment() { local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000}%F{000}world2 %K{015}%F{000}%F{000}world4 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000}%F{000}world2 %K{007}%F{000}%F{000}world4 %k%F{007}%f " "$(build_left_prompt)" } function testLeftPromotingSegmentWithConditionalPredecessor() { @@ -61,7 +61,7 @@ function testLeftPromotingSegmentWithConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000} %F{000}world3 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world3 %k%F{007}%f " "$(build_left_prompt)" } function testLeftPromotingSegmentWithJoinedConditionalPredecessor() { @@ -72,7 +72,7 @@ function testLeftPromotingSegmentWithJoinedConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000} %F{000}world4 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world4 %k%F{007}%f " "$(build_left_prompt)" } function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() { @@ -85,7 +85,7 @@ function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" - assertEquals "%K{015} %F{000}world1 %K{015}%F{000} %F{000}world4 %K{015}%F{000}%F{000}world6 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %K{007}%F{000} %F{000}world4 %K{007}%F{000}%F{000}world6 %k%F{007}%f " "$(build_left_prompt)" } function testLeftJoiningBuiltinSegmentWorks() { @@ -108,7 +108,7 @@ function testRightNormalSegmentsShouldNotBeJoined() { local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%F{000}%f%K{015}%F{000} world2 %f%F{000}%f%K{015}%F{000} world4 %f%F{000}%f%K{015}%F{000} world6%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world2 %f%F{000}%f%K{007}%F{000} world4 %f%F{000}%f%K{007}%F{000} world6%E" "$(build_right_prompt)" } function testRightJoinedSegments() { @@ -117,7 +117,7 @@ function testRightJoinedSegments() { local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%K{015}%F{000}world2%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2%E" "$(build_right_prompt)" } function testRightTransitiveJoinedSegments() { @@ -127,7 +127,7 @@ function testRightTransitiveJoinedSegments() { local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%K{015}%F{000}world2 %f%K{015}%F{000}world3%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2 %f%K{007}%F{000}world3%E" "$(build_right_prompt)" } function testRightTransitiveJoiningWithConditionalJoinedSegment() { @@ -138,7 +138,7 @@ function testRightTransitiveJoiningWithConditionalJoinedSegment() { local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%K{015}%F{000}world2 %f%K{015}%F{000}world4%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%K{007}%F{000}world2 %f%K{007}%F{000}world4%E" "$(build_right_prompt)" } function testRightPromotingSegmentWithConditionalPredecessor() { @@ -148,7 +148,7 @@ function testRightPromotingSegmentWithConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD3="echo world3" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%F{000}%f%K{015}%F{000} world3%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world3%E" "$(build_right_prompt)" } function testRightPromotingSegmentWithJoinedConditionalPredecessor() { @@ -159,7 +159,7 @@ function testRightPromotingSegmentWithJoinedConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD4="echo world4" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%F{000}%f%K{015}%F{000} world4%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world4%E" "$(build_right_prompt)" } function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() { @@ -172,7 +172,7 @@ function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() { local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions local POWERLEVEL9K_CUSTOM_WORLD6="echo world6" - assertEquals "%F{015}%f%K{015}%F{000} world1 %f%F{000}%f%K{015}%F{000} world4 %f%K{015}%F{000}world6%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world4 %f%K{007}%F{000}world6%E" "$(build_right_prompt)" } function testRightJoiningBuiltinSegmentWorks() { diff --git a/test/core/prompt.spec b/test/core/prompt.spec index b0d63cbb..47d3ac7b 100755 --- a/test/core/prompt.spec +++ b/test/core/prompt.spec @@ -22,7 +22,7 @@ function testSegmentOnRightSide() { powerlevel9k_prepare_prompts local reset_attributes=$'\e[00m' - assertEquals "%f%b%k%F{015}%f%K{015}%F{000} world1 %f%F{000}%f%K{015}%F{000} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}" + assertEquals "%f%b%k%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}" } function testDisablingRightPrompt() { @@ -48,7 +48,7 @@ function testLeftMultilinePrompt() { powerlevel9k_prepare_prompts local nl=$'\n' - assertEquals "╭─%f%b%k%K{015} %F{000}world1 %k%F{015}%f ${nl}╰─ " "${(e)PROMPT}" + assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}" } function testRightPromptOnSameLine() { @@ -70,7 +70,7 @@ function testRightPromptOnSameLine() { startSkipping powerlevel9k_prepare_prompts - assertEquals "%{\e[1A%}%F{015}%f%K{015}%F{000} world1 %f%{\e[1B%}" "${(e)RPROMPT}" + assertEquals "%{\e[1A%}%F{007}%f%K{007}%F{000} world1 %f%{\e[1B%}" "${(e)RPROMPT}" } function testPrefixingFirstLineOnLeftPrompt() { @@ -84,7 +84,7 @@ function testPrefixingFirstLineOnLeftPrompt() { powerlevel9k_prepare_prompts local nl=$'\n' - assertEquals "XXX%f%b%k%K{015} %F{000}world1 %k%F{015}%f ${nl}╰─ " "${(e)PROMPT}" + assertEquals "XXX%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}" } function testPrefixingSecondLineOnLeftPrompt() { @@ -98,7 +98,7 @@ function testPrefixingSecondLineOnLeftPrompt() { powerlevel9k_prepare_prompts local nl=$'\n' - assertEquals "╭─%f%b%k%K{015} %F{000}world1 %k%F{015}%f ${nl}XXX" "${(e)PROMPT}" + assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}XXX" "${(e)PROMPT}" } source shunit2/shunit2 diff --git a/test/core/visual_identifier.spec b/test/core/visual_identifier.spec index c31f8dac..c6c6bef5 100755 --- a/test/core/visual_identifier.spec +++ b/test/core/visual_identifier.spec @@ -18,7 +18,7 @@ function testOverwritingIconsWork() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%K{015} %F{000}icon-here %f%F{000}world1 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { @@ -27,7 +27,7 @@ function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%K{015} %F{000}icon-here %f%F{000}world1 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { @@ -36,7 +36,7 @@ function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%F{015}%f%K{015}%F{000} world1%F{000} icon-here%f%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%f%E" "$(build_right_prompt)" } function testVisualIdentifierPrintsNothingIfNotAvailable() { @@ -44,7 +44,7 @@ function testVisualIdentifierPrintsNothingIfNotAvailable() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1) local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' - assertEquals "%K{015} %F{000}world1 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } function testVisualIdentifierIsPrintedInNumericalColorCode() { @@ -54,7 +54,7 @@ function testVisualIdentifierIsPrintedInNumericalColorCode() { local POWERLEVEL9K_CUSTOM_WORLD1_ICON="xxx" local POWERLEVEL9K_CUSTOM_WORLD1_VISUAL_IDENTIFIER_COLOR="purple3" - assertEquals "%K{015} %F{056}xxx %f%F{000}world1 %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{056}xxx %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/functions/colors.spec b/test/functions/colors.spec index ce777913..4ee71205 100755 --- a/test/functions/colors.spec +++ b/test/functions/colors.spec @@ -59,9 +59,9 @@ function testBrightColorsWork() { # with normal ones. This code is now gone, and this test should # ensure that all input channels for bright colors are handled # correctly. - assertTrue "isSameColor 'cyan' '014'" - assertEquals '014' "$(getColorCode 'cyan')" - assertEquals '014' "$(getColor 'cyan')" + assertTrue "isSameColor 'cyan' '006'" + assertEquals '006' "$(getColorCode 'cyan')" + assertEquals '006' "$(getColor 'cyan')" } source shunit2/shunit2 diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 40fd17ca..37aa2704 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -21,7 +21,7 @@ function testJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_joined) cd /tmp - assertEquals "%K{012} %F{000}/tmp %K{012}%F{000}%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000}%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -31,7 +31,7 @@ function testTransitiveJoinedSegments() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir root_indicator_joined dir_joined) cd /tmp - assertEquals "%K{012} %F{000}/tmp %K{012}%F{000}%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000}%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -41,7 +41,7 @@ function testJoiningWithConditionalSegment() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir background_jobs dir_joined) cd /tmp - assertEquals "%K{012} %F{000}/tmp %K{012}%F{000} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp %K{004}%F{000} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -52,7 +52,7 @@ function testDynamicColoringOfSegmentsWork() { local POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='red' cd /tmp - assertEquals "%K{009} %F{000}/tmp %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{000}/tmp %k%F{001}%f " "$(build_left_prompt)" cd - } @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{012} %F{002}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{002}icon-here %f%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -84,7 +84,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{011} %F{002}icon-here %f%F{009}/tmp %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{002}icon-here %f%F{001}/tmp %k%F{003}%f " "$(build_left_prompt)" cd - } @@ -100,7 +100,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{012} %F{000}icon-here %f%F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %f%F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd - # rm -fr ~/$testFolder diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec index 92e1ea64..efcfc030 100755 --- a/test/segments/anaconda.spec +++ b/test/segments/anaconda.spec @@ -21,7 +21,7 @@ function testAnacondaSegmentPrintsNothingIfNoAnacondaPathIsSet() { unset CONDA_ENV_PATH unset CONDA_PREFIX - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { @@ -35,7 +35,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { CONDA_ENV_PATH=/tmp unset CONDA_PREFIX - assertEquals "%K{012} %F{000}icon-here %f%F{000}(tmp) %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmp) %k%F{004}%f " "$(build_left_prompt)" } function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { @@ -49,7 +49,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { unset CONDA_ENV_PATH local CONDA_PREFIX="test" - assertEquals "%K{012} %F{000}icon-here %f%F{000}(test) %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %f%F{000}(test) %k%F{004}%f " "$(build_left_prompt)" } function testAnacondaSegmentWorks() { @@ -63,7 +63,7 @@ function testAnacondaSegmentWorks() { local CONDA_ENV_PATH=/tmp local CONDA_PREFIX="test" - assertEquals "%K{012} %F{000}icon-here %f%F{000}(tmptest) %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmptest) %k%F{004}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec index 8aaf9cc6..99b418e0 100755 --- a/test/segments/aws_eb_env.spec +++ b/test/segments/aws_eb_env.spec @@ -17,7 +17,7 @@ function testAwsEbEnvSegmentPrintsNothingIfNoElasticBeanstalkEnvironmentIsSet() # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() { diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index 56f8b4d8..3d83e171 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -18,7 +18,7 @@ function testBackgroundJobsSegmentPrintsNothingWithoutBackgroundJobs() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias jobs } @@ -34,7 +34,7 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{014}⚙%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } @@ -52,7 +52,7 @@ function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{014}⚙%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } @@ -70,7 +70,7 @@ function testBackgroundJobsSegmentWithVerboseMode() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{014}⚙ %f%F{014}3 %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙ %f%F{006}3 %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } diff --git a/test/segments/battery.spec b/test/segments/battery.spec index 201f4a79..79e25d6f 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -69,7 +69,7 @@ function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true" - assertEquals "%K{000} %F{009}🔋 %f%F{009}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { @@ -77,7 +77,7 @@ function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true" - assertEquals "%K{000} %F{011}🔋 %f%F{011}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { @@ -85,7 +85,7 @@ function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true" - assertEquals "%K{000} %F{015}🔋 %f%F{015}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %f%F{007}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() { @@ -93,7 +93,7 @@ function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true" - assertEquals "%K{000} %F{011}🔋 %f%F{011}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %f%F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsFullOnOSX() { @@ -109,35 +109,35 @@ function testBatterySegmentIfBatteryIsCalculatingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true" - assertEquals "%K{000} %F{015}🔋 %f%F{015}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %f%F{007}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "4" "Discharging" - assertEquals "%K{000} %F{009}🔋 %f%F{009}4%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "4" "Charging" - assertEquals "%K{000} %F{011}🔋 %f%F{011}4%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "10" "Discharging" - assertEquals "%K{000} %F{015}🔋 %f%F{015}10%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %f%F{007}10%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "10" "Charging" - assertEquals "%K{000} %F{011}🔋 %f%F{011}10%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %f%F{003}10%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsFullOnLinux() { @@ -155,7 +155,7 @@ function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { # For running on Mac, we need to mock date :( [[ -f /usr/local/bin/gdate ]] && alias date=gdate - assertEquals "%K{000} %F{015}🔋 %f%F{015}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" unalias date &>/dev/null # unaliasing date fails where it was never aliased (e.g. on Linux). @@ -171,7 +171,7 @@ function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() { echo "echo 'Batter 0: Discharging, 50%, rate remaining'" > ${FOLDER}/usr/bin/acpi chmod +x ${FOLDER}/usr/bin/acpi - assertEquals "%K{000} %F{015}🔋 %f%F{015}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index 2a782859..b7c3fae0 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -20,7 +20,7 @@ function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { # Override payload local _P9K_COMMAND_DURATION=2 - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testCommandExecutionTimeThresholdCouldBeChanged() { @@ -34,7 +34,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { # Override payload local _P9K_COMMAND_DURATION=2.03 - assertEquals "%K{009} %F{226}Dur %f%F{226}2.03 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}2.03 %k%F{001}%f " "$(build_left_prompt)" } function testCommandExecutionTimeThresholdCouldBeSetToZero() { @@ -43,7 +43,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() { local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 local _P9K_COMMAND_DURATION=0.03 - assertEquals "%K{009} %F{226}Dur %f%F{226}0.03 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}0.03 %k%F{001}%f " "$(build_left_prompt)" } function testCommandExecutionTimePrecisionCouldBeChanged() { @@ -58,7 +58,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { # Override payload local _P9K_COMMAND_DURATION=0.0001 - assertEquals "%K{009} %F{226}Dur %f%F{226}0.0001 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}0.0001 %k%F{001}%f " "$(build_left_prompt)" } function testCommandExecutionTimePrecisionCouldBeSetToZero() { @@ -72,7 +72,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { # Override payload local _P9K_COMMAND_DURATION=23.5001 - assertEquals "%K{009} %F{226}Dur %f%F{226}23 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}23 %k%F{001}%f " "$(build_left_prompt)" } function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() { @@ -85,7 +85,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() # Override payload local _P9K_COMMAND_DURATION=180 - assertEquals "%K{009} %F{226}Dur %f%F{226}03:00 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}03:00 %k%F{001}%f " "$(build_left_prompt)" } function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { @@ -98,7 +98,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { # Override payload local _P9K_COMMAND_DURATION=7200 - assertEquals "%K{009} %F{226}Dur %f%F{226}02:00:00 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}Dur %f%F{226}02:00:00 %k%F{001}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/context.spec b/test/segments/context.spec index 23da0f2d..07300370 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -29,7 +29,7 @@ function testContextSegmentDoesNotGetRenderedWithDefaultUser() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { @@ -43,7 +43,7 @@ function testContextSegmentDoesGetRenderedWhenSshConnectionIsOpen() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}%n@%m %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" unfunction sudo } @@ -58,7 +58,7 @@ function testContextSegmentWithForeignUser() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}%n@%m %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" unfunction sudo } @@ -72,7 +72,7 @@ function testContextSegmentWithRootUser() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}%n@%m %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" } function testOverridingContextTemplate() { @@ -83,7 +83,7 @@ function testOverridingContextTemplate() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}xx %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}xx %k%F{000}%f " "$(build_left_prompt)" } function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { @@ -95,7 +95,7 @@ function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}%n@%m %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}%n@%m %k%F{000}%f " "$(build_left_prompt)" } function testContextSegmentIsShownIfForced() { @@ -107,7 +107,7 @@ function testContextSegmentIsShownIfForced() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}$(whoami) %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}$(whoami) %k%F{000}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/custom.spec b/test/segments/custom.spec index 4dbb11be..0f66c82f 100755 --- a/test/segments/custom.spec +++ b/test/segments/custom.spec @@ -17,7 +17,7 @@ function testCustomDirectOutputSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testCustomClosureSegment() { @@ -31,7 +31,7 @@ function testCustomClosureSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testSettingBackgroundForCustomSegment() { @@ -43,7 +43,7 @@ function testSettingBackgroundForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000}world %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000}world %k%F{003}%f " "$(build_left_prompt)" } function testSettingForegroundForCustomSegment() { @@ -55,7 +55,7 @@ function testSettingForegroundForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{009}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{001}world %k%F{007}%f " "$(build_left_prompt)" } function testSettingVisualIdentifierForCustomSegment() { @@ -67,7 +67,7 @@ function testSettingVisualIdentifierForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}hw %f%F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testSettingVisualIdentifierForegroundColorForCustomSegment() { @@ -80,7 +80,7 @@ function testSettingVisualIdentifierForegroundColorForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{009}hw %f%F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{001}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/detect_virt.spec b/test/segments/detect_virt.spec index e0ca80e7..910f52eb 100755 --- a/test/segments/detect_virt.spec +++ b/test/segments/detect_virt.spec @@ -20,7 +20,7 @@ function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias systemd-detect-virt } @@ -33,7 +33,7 @@ function testDetectVirtSegmentIfSystemdReturnsPlainName() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}xxx %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}xxx %k%F{000}%f " "$(build_left_prompt)" unalias systemd-detect-virt } @@ -53,7 +53,7 @@ function testDetectVirtSegmentIfRootFsIsOnExpectedInode() { # which translates to: Show the inode number of "/" and test if it is "2". alias ls="echo '2'" - assertEquals "%K{000} %F{011}none %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}none %k%F{000}%f " "$(build_left_prompt)" unalias ls unalias systemd-detect-virt @@ -74,7 +74,7 @@ function testDetectVirtSegmentIfRootFsIsNotOnExpectedInode() { # which translates to: Show the inode number of "/" and test if it is "2". alias ls="echo '3'" - assertEquals "%K{000} %F{011}chroot %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}chroot %k%F{000}%f " "$(build_left_prompt)" unalias ls unalias systemd-detect-virt diff --git a/test/segments/dir.spec b/test/segments/dir.spec index d43545b4..7e65cb71 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -29,9 +29,9 @@ function testDirPathAbsoluteWorks() { # of /home or /Users path.. That is why we change the test # according to the OS of the host. if [[ "${OS}" == 'Linux' ]]; then - assertEquals "%K{012} %F{000}/home/${USER} %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/home/${USER} %k%F{004}%f " "$(build_left_prompt)" elif [[ "${OS}" == 'OSX' ]]; then - assertEquals "%K{012} %F{000}/Users/${USER} %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/Users/${USER} %k%F{004}%f " "$(build_left_prompt)" fi cd - @@ -50,7 +50,7 @@ function testTruncateFoldersWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}…/12345678/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}…/12345678/123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -72,7 +72,7 @@ function testTruncateFolderWithHomeDirWorks() { # Switch back to home folder as this causes the problem. cd .. - assertEquals "%K{012} %F{000}~ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}~ %k%F{004}%f " "$(build_left_prompt)" rmdir $FOLDER cd ${CURRENT_DIR} @@ -91,7 +91,7 @@ function testTruncateMiddleWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/po…st/1/12/123/1234/12…45/12…56/12…67/12…78/123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -110,7 +110,7 @@ function testTruncationFromRightWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/po…/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -129,7 +129,7 @@ function testTruncateToLastWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -148,7 +148,7 @@ function testTruncateToFirstAndLastWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -167,7 +167,7 @@ function testTruncateAbsoluteWorks() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}…89 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}…89 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -187,7 +187,7 @@ function testTruncationFromRightWithEmptyDelimiter() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -207,7 +207,7 @@ function testTruncateWithFolderMarkerWorks() { # Setup folder marker touch $BASEFOLDER/1/12/.shorten_folder_marker cd $FOLDER - assertEquals "%K{012} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -228,7 +228,7 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { # Setup folder marker touch $BASEFOLDER/1/12/.xxx cd $FOLDER - assertEquals "%K{012} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/…/12/123/1234/12345/123456/1234567 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr $BASEFOLDER @@ -260,7 +260,7 @@ function testTruncateWithPackageNameWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{004}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -300,7 +300,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}My_Package/as…/qwerqwer %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}My_Package/as…/qwerqwer %k%F{004}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -336,7 +336,7 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}My_Package/.g…/re…/heads %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}My_Package/.g…/re…/heads %k%F{004}%f " "$(build_left_prompt)" # Go back cd $p9kFolder @@ -352,7 +352,7 @@ function testHomeFolderDetectionWorks() { source ${P9K_HOME}/powerlevel9k.zsh-theme cd ~ - assertEquals "%K{012} %F{000}home-icon %f%F{000}~ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}home-icon %f%F{000}~ %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -368,7 +368,7 @@ function testHomeSubfolderDetectionWorks() { local FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}sub-icon %f%F{000}~/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}sub-icon %f%F{000}~/powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -385,7 +385,7 @@ function testOtherFolderDetectionWorks() { local FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -403,7 +403,7 @@ function testChangingDirPathSeparator() { mkdir -p $FOLDER cd $FOLDER - assertEquals "%K{012} %F{000}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -421,7 +421,7 @@ function testHomeFolderAbbreviation() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}~ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}~ %k%F{004}%f " "$(build_left_prompt)" # substituted local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' @@ -429,7 +429,7 @@ function testHomeFolderAbbreviation() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}qQq %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}qQq %k%F{004}%f " "$(build_left_prompt)" cd /tmp # default @@ -438,7 +438,7 @@ function testHomeFolderAbbreviation() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" # substituted local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' @@ -446,7 +446,7 @@ function testHomeFolderAbbreviation() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp %k%F{004}%f " "$(build_left_prompt)" cd "$dir" } @@ -462,7 +462,7 @@ function testOmittingFirstCharacterWorks() { cd /tmp - assertEquals "%K{012} %F{000}folder-icon %f%F{000}tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}folder-icon %f%F{000}tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -480,7 +480,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{012} %F{000}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}folder-icon %f%F{000}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -507,7 +507,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{012} %F{000}xXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}xXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -527,7 +527,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{012} %F{000}tmpxXxpo…stxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}tmpxXxpo…stxXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -547,7 +547,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{012} %F{000}tmpxXxpo…xXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}tmpxXxpo…xXx1xXx2 %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -570,7 +570,7 @@ function testTruncateToUniqueWorks() { mkdir -p /tmp/powerlevel9k-test/bob/docs cd /tmp/powerlevel9k-test/alice/devl - assertEquals "%K{012} %F{000}txXxpxXxalxXxde %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}txXxpxXxalxXxde %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -586,7 +586,7 @@ function testBoldHomeDirWorks() { cd ~ - assertEquals "%K{012} %F{000}%B~%b %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}%B~%b %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -602,7 +602,7 @@ function testBoldHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{012} %F{000}~/%Bpowerlevel9k-test%b %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}~/%Bpowerlevel9k-test%b %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -618,7 +618,7 @@ function testBoldRootDirWorks() { cd / - assertEquals "%K{012} %F{000}%B/%b %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}%B/%b %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -633,7 +633,7 @@ function testBoldRootSubdirWorks() { cd /tmp - assertEquals "%K{012} %F{000}/%Btmp%b %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/%Btmp%b %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -649,7 +649,7 @@ function testBoldRootSubSubdirWorks() { mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{012} %F{000}/tmp/%Bpowerlevel9k-test%b %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/%Bpowerlevel9k-test%b %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -665,7 +665,7 @@ function testHighlightHomeWorks() { cd ~ - assertEquals "%K{012} %F{000}%F{red}~ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}%F{red}~ %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -681,7 +681,7 @@ function testHighlightHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{012} %F{000}~/%F{red}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}~/%F{red}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -697,7 +697,7 @@ function testHighlightRootWorks() { cd / - assertEquals "%K{012} %F{000}%F{red}/ %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}%F{red}/ %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -712,7 +712,7 @@ function testHighlightRootSubdirWorks() { cd /tmp - assertEquals "%K{012} %F{000}/%F{red}tmp %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/%F{red}tmp %k%F{004}%f " "$(build_left_prompt)" cd - } @@ -728,7 +728,7 @@ function testHighlightRootSubSubdirWorks() { mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{012} %F{000}/tmp/%F{red}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}/tmp/%F{red}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -745,7 +745,7 @@ function testDirSeparatorColorHomeSubdirWorks() { mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test - assertEquals "%K{012} %F{000}~%F{red}/%F{black}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}~%F{red}/%F{black}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr ~/powerlevel9k-test @@ -762,7 +762,7 @@ function testDirSeparatorColorRootSubSubdirWorks() { mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test - assertEquals "%K{012} %F{000}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{004}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec index 56bc402d..ebafe31d 100755 --- a/test/segments/disk_usage.spec +++ b/test/segments/disk_usage.spec @@ -40,7 +40,7 @@ function testDiskUsageSegmentWhenDiskIsAlmostFull() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{009} %F{015}hdd %f%F{015}97%% %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{007}hdd %f%F{007}97%% %k%F{001}%f " "$(build_left_prompt)" unfunction df } @@ -56,7 +56,7 @@ function testDiskUsageSegmentWhenDiskIsVeryFull() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000}hdd %f%F{000}94%% %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000}hdd %f%F{000}94%% %k%F{003}%f " "$(build_left_prompt)" unfunction df } @@ -72,7 +72,7 @@ function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}hdd %f%F{011}4%% %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}hdd %f%F{003}4%% %k%F{000}%f " "$(build_left_prompt)" unfunction df } @@ -88,7 +88,7 @@ function testDiskUsageSegmentPrintsNothingIfDiskIsQuiteEmptyAndOnlyWarningsShoul local POWERLEVEL9K_DISK_USAGE_ONLY_WARNING=true local POWERLEVEL9K_CUSTOM_WORLD='echo world' - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unfunction df } @@ -105,7 +105,7 @@ function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000}hdd %f%F{000}11%% %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000}hdd %f%F{000}11%% %k%F{003}%f " "$(build_left_prompt)" unfunction df } @@ -123,7 +123,7 @@ function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{009} %F{015}hdd %f%F{015}11%% %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{007}hdd %f%F{007}11%% %k%F{001}%f " "$(build_left_prompt)" unfunction df } diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index f619dfae..d7a1c2c9 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -56,7 +56,7 @@ function testGoSegmentPrintsNothingIfEmptyGopath() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testGoSegmentPrintsNothingIfNotInGopath() { @@ -68,7 +68,7 @@ function testGoSegmentPrintsNothingIfNotInGopath() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testGoSegmentPrintsNothingIfGoIsNotAvailable() { @@ -80,7 +80,7 @@ function testGoSegmentPrintsNothingIfGoIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias go } diff --git a/test/segments/ip.spec b/test/segments/ip.spec index cba4af16..254f11c9 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -19,7 +19,7 @@ function testIpSegmentPrintsNothingOnOsxIfNotConnected() { source powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias networksetup } @@ -34,7 +34,7 @@ function testIpSegmentPrintsNothingOnLinuxIfNotConnected() { source powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias ip } @@ -68,7 +68,7 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{014} %F{000}IP %f%F{000}1.2.3.4 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unalias ipconfig unalias networksetup @@ -123,7 +123,7 @@ function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{014} %F{000}IP %f%F{000}1.2.3.4 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unfunction ipconfig unalias networksetup @@ -139,7 +139,7 @@ function testIpSegmentWorksOnOsxWithInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{014} %F{000}IP %f%F{000}1.2.3.4 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unalias ipconfig } @@ -169,7 +169,7 @@ function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{014} %F{000}IP %f%F{000}10.0.2.15 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } @@ -204,7 +204,7 @@ function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{014} %F{000}IP %f%F{000}10.0.2.15 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } @@ -223,7 +223,7 @@ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{014} %F{000}IP %f%F{000}10.0.2.15 %k%F{014}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 343c8937..76b35c34 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -71,7 +71,7 @@ function testKubeContext() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{013} %F{015}⎈ %f%F{015}minikube/default %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{007}⎈ %f%F{007}minikube/default %k%F{005}%f " "$(build_left_prompt)" unalias kubectl } @@ -83,7 +83,7 @@ function testKubeContextOtherNamespace() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{013} %F{015}⎈ %f%F{015}minikube/kube-system %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{007}⎈ %f%F{007}minikube/kube-system %k%F{005}%f " "$(build_left_prompt)" unalias kubectl } @@ -96,7 +96,7 @@ function testKubeContextPrintsNothingIfKubectlNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias kubectl } diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index 4c2f0f26..c4f09e58 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -34,7 +34,7 @@ function testLaravelVersionSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{001} %F{015}x %f%F{015}5.4.23 %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{009} %F{007}x %f%F{007}5.4.23 %k%F{009}%f " "$(build_left_prompt)" unalias php } @@ -49,7 +49,7 @@ function testLaravelVersionSegmentIfArtisanIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias php } @@ -64,7 +64,7 @@ function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias php } diff --git a/test/segments/load.spec b/test/segments/load.spec index 2ab7d23b..0f8ee332 100755 --- a/test/segments/load.spec +++ b/test/segments/load.spec @@ -121,7 +121,7 @@ function testLoadSegmentWarningState() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{011} %F{000}L %f%F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}L %f%F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } @@ -141,7 +141,7 @@ function testLoadSegmentCriticalState() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{009} %F{000}L %f%F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{001} %F{000}L %f%F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec index b931082e..69b9cbb7 100755 --- a/test/segments/node_version.spec +++ b/test/segments/node_version.spec @@ -18,7 +18,7 @@ function testNodeVersionSegmentPrintsNothingWithoutNode() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias node } @@ -33,7 +33,7 @@ function testNodeVersionSegmentWorks() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{002} %F{015}⬢ %f%F{015}1.2.3 %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{007}⬢ %f%F{007}1.2.3 %k%F{002}%f " "$(build_left_prompt)" unfunction node } diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index b16c577a..2e9d779e 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -23,7 +23,7 @@ function testNodeenvSegmentPrintsNothingWithoutNode() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias node } @@ -39,7 +39,7 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unfunction node } @@ -57,7 +57,7 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unset NODE_VIRTUAL_ENV_DISABLE_PROMPT unset NODE_VIRTUAL_ENV diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index eb58f83b..c9ed430d 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -37,7 +37,7 @@ function testNvmSegmentPrintsNothingIfNvmIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testNvmSegmentWorksWithoutHavingADefaultAlias() { @@ -51,7 +51,7 @@ function testNvmSegmentWorksWithoutHavingADefaultAlias() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' } - assertEquals "%K{013} %F{000}⬢ %f%F{000}4.6.0 %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{000}⬢ %f%F{000}4.6.0 %k%F{005}%f " "$(build_left_prompt)" } function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { @@ -66,7 +66,7 @@ function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v4.6.0' } - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/php_version.spec b/test/segments/php_version.spec index 55f5bf71..6d64c570 100755 --- a/test/segments/php_version.spec +++ b/test/segments/php_version.spec @@ -18,7 +18,7 @@ function testPhpVersionSegmentPrintsNothingIfPhpIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias php } diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 80c46ac5..334a6423 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -45,7 +45,7 @@ function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias dig } @@ -62,7 +62,7 @@ function testPublicIpSegmentPrintsNoticeIfNotConnected() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}disconnected %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}disconnected %k%F{000}%f " "$(build_left_prompt)" unalias dig } @@ -79,7 +79,7 @@ function testPublicIpSegmentWorksWithWget() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}wget 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}wget 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" unfunction wget unalias dig @@ -98,7 +98,7 @@ function testPublicIpSegmentUsesCurlAsFallbackMethodIfWgetIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}curl 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}curl 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" unfunction curl unalias dig @@ -117,7 +117,7 @@ function testPublicIpSegmentUsesDigAsFallbackMethodIfWgetAndCurlAreNotAvailable( # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}dig 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}dig 1.2.3.4 %k%F{000}%f " "$(build_left_prompt)" unfunction dig unalias curl @@ -134,14 +134,14 @@ function testPublicIpSegmentCachesFile() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}first %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" dig() { echo "second" } # Segment should not have changed! - assertEquals "%K{000} %F{015}first %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" unfunction dig } @@ -157,7 +157,7 @@ function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}first %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" sleep 3 dig() { @@ -165,7 +165,7 @@ function testPublicIpSegmentRefreshesCachesFileAfterTimeout() { } # Segment should not have changed! - assertEquals "%K{000} %F{015}second %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" unfunction dig } @@ -180,7 +180,7 @@ function testPublicIpSegmentRefreshesCachesFileIfEmpty() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}first %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}first %k%F{000}%f " "$(build_left_prompt)" # Truncate cache file echo "" >! $POWERLEVEL9K_PUBLIC_IP_FILE @@ -190,7 +190,7 @@ function testPublicIpSegmentRefreshesCachesFileIfEmpty() { } # Segment should not have changed! - assertEquals "%K{000} %F{015}second %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" unfunction dig } @@ -205,7 +205,7 @@ function testPublicIpSegmentWhenGoingOnline() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}disconnected %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}disconnected %k%F{000}%f " "$(build_left_prompt)" unalias dig @@ -214,7 +214,7 @@ function testPublicIpSegmentWhenGoingOnline() { } # Segment should not have changed! - assertEquals "%K{000} %F{015}second %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{007}second %k%F{000}%f " "$(build_left_prompt)" unfunction dig } diff --git a/test/segments/ram.spec b/test/segments/ram.spec index a3d97aa7..2c9f1693 100755 --- a/test/segments/ram.spec +++ b/test/segments/ram.spec @@ -36,7 +36,7 @@ Pages inactive: 1313411. source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{011} %F{000}RAM %f%F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %f%F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})" unalias vm_stat } @@ -49,7 +49,7 @@ function testRamSegmentWorksOnBsd() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="BSD" # Fake BSD - assertEquals "%K{011} %F{000}RAM %f%F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %f%F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})" } function testRamSegmentWorksOnLinux() { @@ -60,7 +60,7 @@ function testRamSegmentWorksOnLinux() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{011} %F{000}RAM %f%F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %f%F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 007ca694..07331edb 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -45,7 +45,7 @@ function testRustPrintsNothingIfRustIsNotAvailable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec index ad1b70fb..3245231f 100755 --- a/test/segments/ssh.spec +++ b/test/segments/ssh.spec @@ -22,7 +22,7 @@ function testSshSegmentPrintsNothingIfNoSshConnection() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testSshSegmentWorksIfOnlySshClientIsSet() { @@ -37,7 +37,7 @@ function testSshSegmentWorksIfOnlySshClientIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" unset SSH_CLIENT } @@ -54,7 +54,7 @@ function testSshSegmentWorksIfOnlySshTtyIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" unset SSH_TTY } @@ -71,7 +71,7 @@ function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{011}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" unset SSH_TTY unset SSH_CLIENT diff --git a/test/segments/status.spec b/test/segments/status.spec index 1eba2b86..9fb34e09 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -24,7 +24,7 @@ function testStatusPrintsNothingIfReturnCodeIsZeroAndVerboseIsUnset() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { @@ -50,7 +50,7 @@ function testStatusInGeneralErrorCase() { source powerlevel9k.zsh-theme local RETVAL=1 - assertEquals "%K{009} %F{226}↵ %f%F{226}1 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %f%F{226}1 %k%F{001}%f " "$(build_left_prompt)" } function testPipestatusInErrorCase() { @@ -64,7 +64,7 @@ function testPipestatusInErrorCase() { local -a RETVALS RETVALS=(0 0 1 0) - assertEquals "%K{009} %F{226}↵ %f%F{226}0|0|1|0 %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %f%F{226}0|0|1|0 %k%F{001}%f " "$(build_left_prompt)" } function testStatusCrossWinsOverVerbose() { @@ -78,7 +78,7 @@ function testStatusCrossWinsOverVerbose() { source powerlevel9k.zsh-theme local RETVAL=1 - assertEquals "%K{000} %F{009}✘%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{001}✘%f %k%F{000}%f " "$(build_left_prompt)" } function testStatusShowsSignalNameInErrorCase() { @@ -92,7 +92,7 @@ function testStatusShowsSignalNameInErrorCase() { source powerlevel9k.zsh-theme local RETVAL=132 - assertEquals "%K{009} %F{226}↵ %f%F{226}SIGILL(4) %k%F{009}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %f%F{226}SIGILL(4) %k%F{001}%f " "$(build_left_prompt)" } function testStatusSegmentIntegrated() { @@ -107,7 +107,7 @@ function testStatusSegmentIntegrated() { false; powerlevel9k_prepare_prompts - assertEquals "%f%b%k%K{000} %F{009}✘%f %k%F{000}%f " "${(e)PROMPT}" + assertEquals "%f%b%k%K{000} %F{001}✘%f %k%F{000}%f " "${(e)PROMPT}" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swap.spec b/test/segments/swap.spec index 2ad5188d..7db5416b 100755 --- a/test/segments/swap.spec +++ b/test/segments/swap.spec @@ -36,7 +36,7 @@ function testSwapSegmentWorksOnOsx() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{011} %F{000}SWP %f%F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}SWP %f%F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})" unfunction sysctl } @@ -52,7 +52,7 @@ function testSwapSegmentWorksOnLinux() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{011} %F{000}SWP %f%F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}SWP %f%F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec index 53074776..47fc0b7f 100755 --- a/test/segments/swift_version.spec +++ b/test/segments/swift_version.spec @@ -34,7 +34,7 @@ function testSwiftSegmentPrintsNothingIfSwiftIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias swift } @@ -49,7 +49,7 @@ function testSwiftSegmentWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{013} %F{015}Swift %f%F{015}3.0.1 %k%F{013}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{007}Swift %f%F{007}3.0.1 %k%F{005}%f " "$(build_left_prompt)" unfunction swift } diff --git a/test/segments/symfony_version.spec b/test/segments/symfony_version.spec index 82618162..cb480724 100755 --- a/test/segments/symfony_version.spec +++ b/test/segments/symfony_version.spec @@ -34,7 +34,7 @@ function testSymfonyVersionSegmentPrintsNothingIfPhpIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unalias php } @@ -50,7 +50,7 @@ function testSymfonyVersionSegmentPrintsNothingIfSymfonyIsNotAvailable() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { @@ -68,7 +68,7 @@ function testSymfonyVersionPrintsNothingIfPhpThrowsAnError() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" unfunction php } diff --git a/test/segments/todo.spec b/test/segments/todo.spec index 14494454..875c45f8 100755 --- a/test/segments/todo.spec +++ b/test/segments/todo.spec @@ -38,7 +38,7 @@ function testTodoSegmentPrintsNothingIfTodoShIsNotInstalled() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{000}world %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testTodoSegmentWorksAsExpected() { diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index 224d76e2..bddecf6c 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -76,7 +76,7 @@ function testColorOverridingForCleanStateWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{014} master %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{006} master %k%F{007}%f " "$(build_left_prompt)" } function testColorOverridingForModifiedStateWorks() { @@ -93,7 +93,7 @@ function testColorOverridingForModifiedStateWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{009} master ● %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{001} master ● %k%F{003}%f " "$(build_left_prompt)" } function testColorOverridingForUntrackedStateWorks() { @@ -107,7 +107,7 @@ function testColorOverridingForUntrackedStateWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{014} master ? %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{006} master ? %k%F{003}%f " "$(build_left_prompt)" } function testGitIconWorks() { @@ -194,7 +194,7 @@ function testStagedFilesIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000} master + %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000} master + %k%F{003}%f " "$(build_left_prompt)" } function testUnstagedFilesIconWorks() { @@ -211,7 +211,7 @@ function testUnstagedFilesIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000} master M %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000} master M %k%F{003}%f " "$(build_left_prompt)" } function testStashIconWorks() { @@ -289,7 +289,7 @@ function testActionHintWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000} master %F{red}| merge%f %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000} master %F{red}| merge%f %k%F{003}%f " "$(build_left_prompt)" } function testIncomingHintWorks() { diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 27243fbe..2903f544 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -40,7 +40,7 @@ function testColorOverridingForCleanStateWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{015} %F{014} default %k%F{015}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{006} default %k%F{007}%f " "$(build_left_prompt)" } function testColorOverridingForModifiedStateWorks() { @@ -57,7 +57,7 @@ function testColorOverridingForModifiedStateWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{009} default ● %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{001} default ● %k%F{003}%f " "$(build_left_prompt)" } # There is no staging area in mercurial, therefore there are no "untracked" @@ -74,7 +74,7 @@ function testAddedFilesIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000} default ● %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000} default ● %k%F{003}%f " "$(build_left_prompt)" } # We don't support tagging in mercurial right now.. @@ -137,7 +137,7 @@ function testActionHintWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{011} %F{000} default %F{red}| merging%f %k%F{011}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000} default %F{red}| merging%f %k%F{003}%f " "$(build_left_prompt)" } function testShorteningCommitHashWorks() { diff --git a/test/segments/vi_mode.spec b/test/segments/vi_mode.spec index 8535cc4e..6a3a07b5 100755 --- a/test/segments/vi_mode.spec +++ b/test/segments/vi_mode.spec @@ -15,7 +15,7 @@ function testViInsertModeWorks() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{012}INSERT " "$(prompt_vi_mode left 1 false)" + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" } function testViInsertModeWorksWhenLabeledAsMain() { @@ -24,7 +24,7 @@ function testViInsertModeWorksWhenLabeledAsMain() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{012}INSERT " "$(prompt_vi_mode left 1 false)" + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" } function testViCommandModeWorks() { @@ -33,7 +33,7 @@ function testViCommandModeWorks() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{015}NORMAL " "$(prompt_vi_mode left 1 false)" + assertEquals "%K{000} %F{007}NORMAL " "$(prompt_vi_mode left 1 false)" } function testViInsertModeStringIsCustomizable() { @@ -42,7 +42,7 @@ function testViInsertModeStringIsCustomizable() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{012}INSERT " "$(prompt_vi_mode left 1 false)" + assertEquals "%K{000} %F{004}INSERT " "$(prompt_vi_mode left 1 false)" } source shunit2/shunit2 \ No newline at end of file From 94897a40f0775e54e181e98fd152d981ca188e98 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 5 Sep 2018 19:07:25 +0200 Subject: [PATCH 099/103] Fix tests --- test/powerlevel9k.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 37aa2704..586c2b27 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -117,7 +117,7 @@ function testNewlineOnRpromptCanBeDisabled() { POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_rworld) powerlevel9k_prepare_prompts - assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" + assertEquals '$(print_icon MULTILINE_FIRST_PROMPT_PREFIX) world  $(print_icon MULTILINE_LAST_PROMPT_PREFIX) rworld' "$(print -P ${PROMPT}${RPROMPT})" } source shunit2/shunit2 From 54d4aee6f4a94ed0d4724adecd2f9ad9c168f41c Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Wed, 5 Sep 2018 14:47:27 -0400 Subject: [PATCH 100/103] Updating CHANGELOG for v0.6.6 --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02341f4a..4902d1ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## v0.6.6 + +- PR #959 - Fixing issue in v0.6.5 where we changed some color codes. +- PR #934 - Add Tests +- PR #884 - test-in-docker: fix with newer ZSH versions +- PR #928 - [Docs] Add etc state description in dir docs +- PR #937 - Use SUDO_COMMAND to check for sudo +- PR #925 - [Bugfix] Resolve #918 Transparent background +- PR #923 - Fix font issue debugging script +- PR #921 - Add missing colors to fix color comparison +- PR #951 - Add fallback icon for missing linux distro icons +- PR #956 - Fix broken link in readme +- Fixed #936 - fallback icons for Linux distros +- Fixed #926 - `etc` state for `dir` segment in docs +- Fixed #852 - `sudo` detection got crazy, there. sorry, everyone. +- Fixed #927 - more default color issues. + ## v0.6.5 - Multiple PRs: General fixes to README, improved documentation. From 572b7a1299331fa3e191f11e527e8da0c7711567 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 6 Sep 2018 09:38:34 -0400 Subject: [PATCH 101/103] Removing `rbenv` from default LPROMPT list. --- CHANGELOG.md | 1 + README.md | 2 +- powerlevel9k.zsh-theme | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4902d1ef..b40ce50b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## v0.6.6 +- The `rbenv` segment is no longer a default segment in the LPROMPT. - PR #959 - Fixing issue in v0.6.5 where we changed some color codes. - PR #934 - Add Tests - PR #884 - test-in-docker: fix with newer ZSH versions diff --git a/README.md b/README.md index 756b9794..5b228857 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ variables to your `~/.zshrc`. | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir rbenv vcs)`|Segment list for left prompt| +|`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS`|`(context dir vcs)`|Segment list for left prompt| |`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`|`(status root_indicator background_jobs history time)`|Segment list for right prompt| diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a7a3de35..3c3303fa 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1911,7 +1911,7 @@ prompt_powerlevel9k_setup() { fi fi - defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) + defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) # Display a warning if deprecated segments are in use. From 358c105de7aa5e8109788adf65c08c44e368d418 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 6 Sep 2018 09:47:35 -0400 Subject: [PATCH 102/103] Oops, this change should have been in last commit. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b228857..2b037bd0 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ The table above shows the default values, so if you wanted to set these variables manually, you would put the following in your `~/.zshrc`: ```zsh -POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) ``` #### Available Prompt Segments From 544a383dad553bf41255539fba04d9f7c99f410f Mon Sep 17 00:00:00 2001 From: sblondon Date: Sun, 16 Sep 2018 11:25:49 +0200 Subject: [PATCH 103/103] Add forgotten backtick `truncate_to_first_and_last` is not properly displayed because the ending backtick is not there. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b037bd0..2ecf2972 100644 --- a/README.md +++ b/README.md @@ -413,7 +413,7 @@ Customizations available are: |`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| |`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3`, you will get "..l9k".| |`truncate_to_last`|Truncates everything before the last folder in the path.| -|`truncate_to_first_and_last|Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get "~/../powerlevel9k".|| +|`truncate_to_first_and_last`|Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get "~/../powerlevel9k".|| |`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.| |`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| |`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).|