summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml1
-rwxr-xr-xtest/segments/command_execution_time.spec58
2 files changed, 59 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml
index 4f2c7a39..ad4eb8c6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,6 +21,7 @@ script:
- test/powerlevel9k.spec
- test/functions/utilities.spec
- test/functions/colors.spec
+ - test/segments/command_execution_time.spec
- test/segments/dir.spec
- test/segments/rust_version.spec
- test/segments/go_version.spec
diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec
new file mode 100755
index 00000000..5b6c782b
--- /dev/null
+++ b/test/segments/command_execution_time.spec
@@ -0,0 +1,58 @@
+#!/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 testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
+ POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ _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 testCommandExecutionTimesThresholdCouldBeChanged() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
+ POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
+ _P9K_COMMAND_DURATION=2
+
+ assertEquals "%K{red} %F{226%}Dur%f %F{226}2 %k%F{red}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset _P9K_COMMAND_DURATION
+ unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
+}
+
+function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
+ _P9K_COMMAND_DURATION=180
+
+ assertEquals "%K{red} %F{226%}Dur%f %F{226}03:00 %k%F{red}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset _P9K_COMMAND_DURATION
+}
+
+function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
+ _P9K_COMMAND_DURATION=7200
+
+ assertEquals "%K{red} %F{226%}Dur%f %F{226}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