diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/functions/icons.spec | 30 | ||||
-rwxr-xr-x | test/segments/context.spec | 18 | ||||
-rwxr-xr-x | test/segments/vcs-git.spec | 159 | ||||
-rwxr-xr-x | test/segments/vcs-hg.spec | 15 |
4 files changed, 208 insertions, 14 deletions
diff --git a/test/functions/icons.spec b/test/functions/icons.spec index ec0cb1fa..8083c095 100755 --- a/test/functions/icons.spec +++ b/test/functions/icons.spec @@ -17,52 +17,58 @@ function tearDown() { LC_CTYPE="${_OLD_LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInDefaultMode() { +function testLcCtypeIsNotOverwrittenInDefaultMode() { local POWERLEVEL9K_MODE="default" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { +function testLcCtypeIsNotOverwrittenInAwesomePatchedMode() { local POWERLEVEL9K_MODE="awesome-patched" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { +function testLcCtypeIsNotOverwrittenInAwesomeFontconfigMode() { local POWERLEVEL9K_MODE="awesome-fontconfig" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { +function testLcCtypeIsNotOverwrittenInNerdfontFontconfigMode() { local POWERLEVEL9K_MODE="nerdfont-fontconfig" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInFlatMode() { +function testLcCtypeIsNotOverwrittenInFlatMode() { local POWERLEVEL9K_MODE="flat" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInCompatibleMode() { +function testLcCtypeIsNotOverwrittenInCompatibleMode() { local POWERLEVEL9K_MODE="compatible" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } # Go through all icons defined in default mode, and diff --git a/test/segments/context.spec b/test/segments/context.spec index 07300370..25c355a7 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -11,11 +11,29 @@ function setUp() { # Test specific settings OLD_DEFAULT_USER=$DEFAULT_USER unset DEFAULT_USER + + # Fix leaked state for travis + OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + OLD_SSH_CLIENT=$SSH_CLIENT + unset SSH_CLIENT + OLD_SSH_TTY=$SSH_TTY + unset SSH_TTY } function tearDown() { # Restore old variables [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER + unset OLD_DEFAULT_USER + + [[ -n "$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW" ]] && POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + + [[ -n "$OLD_SSH_CLIENT" ]] && SSH_CLIENT=$OLD_SSH_CLIENT + unset OLD_SSH_CLIENT + + [[ -n "$OLD_SSH_TTY" ]] && SSH_TTY=$OLD_SSH_TTY + unset OLD_SSH_TTY return 0 } diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index bddecf6c..da28b955 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -375,4 +375,161 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)" } -source shunit2/shunit2
\ No newline at end of file +function testDetectingUntrackedFilesInSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + # Go into checked-out submodule path + cd submodule + # Create untracked file + touch "i-am-untracked.txt" + cd - + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + # Create untracked file + touch "i-am-untracked.txt" + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInNestedSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + local mainRepo="${PWD}" + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + mkdir ../subsubmodule + cd ../subsubmodule + git init 1>/dev/null + touch "i-am-tracked-too.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local subsubmodulePath="${PWD}" + + cd "${submodulePath}" + git submodule add "${subsubmodulePath}" 2>/dev/null + git commit -m "Add subsubmodule" 1>/dev/null + cd "${mainRepo}" + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + git submodule update --init --recursive 2>/dev/null + + cd submodule/subsubmodule + # Create untracked file + touch "i-am-untracked.txt" + cd - + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInCleanSubdirectoryWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + mkdir clean-folder + touch clean-folder/file.txt + mkdir dirty-folder + touch dirty-folder/file.txt + git add . 2>/dev/null + git commit -m "Initial commit" >/dev/null + touch dirty-folder/new-file.txt + cd clean-folder + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testBranchNameScriptingVulnerability() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh + chmod +x evil_script.sh + + git checkout -b '$(./evil_script.sh)' 2>/dev/null + git add . 2>/dev/null + git commit -m "Initial commit" >/dev/null + + assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(build_left_prompt)" +} + +function testGitSubmoduleWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + cd submodule + + source "${P9K_HOME}/powerlevel9k.zsh-theme" + + local result="$(build_left_prompt)" + [[ "$result" =~ ".*(is outside repository)+" ]] && return 1 + + assertEquals "%K{002} %F{000} master %k%F{002}%f " "$result" +} + + +source shunit2/shunit2 diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 2903f544..c4289cef 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -204,4 +204,17 @@ function testBookmarkIconWorks() { assertEquals "%K{002} %F{000} default Binitial %k%F{002}%f " "$(build_left_prompt)" } -source shunit2/shunit2
\ No newline at end of file +function testBranchNameScriptingVulnerability() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh + chmod +x evil_script.sh + + hg branch '$(./evil_script.sh)' >/dev/null + hg add . >/dev/null + hg commit -m "Initial commit" >/dev/null + + assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(build_left_prompt)" +} + +source shunit2/shunit2 |