-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The pmset-simulator function was actually quite helpful, but without a testing framework around it, there was no automated testing done. Which meant my mistake a while back was not caught. Convert those inputs into a real testing function, so that we can test the data function against real test cases.
- Loading branch information
Showing
2 changed files
with
79 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
# Load MacOS version of _lp_battery() | ||
uname() { printf 'Darwin'; } | ||
|
||
. ../liquidprompt --no-activate | ||
unset -f uname | ||
|
||
LP_ENABLE_BATT=1 | ||
|
||
typeset -a outputs statuses values | ||
|
||
# Simulated, originally from ./pmset-simulator | ||
# https://github.com/nojhan/liquidprompt/issues/315 | ||
outputs+=( | ||
"Now drawing from 'AC Power'" | ||
) | ||
statuses+=(4) | ||
values+=('') | ||
# https://github.com/nojhan/liquidprompt/issues/326#issuecomment-66120495 | ||
outputs+=( | ||
"Now drawing from 'AC Power' | ||
-InternalBattery-0 37%; AC attached; not charging" | ||
) | ||
statuses+=(2) | ||
values+=(37) | ||
# https://github.com/nojhan/liquidprompt/issues/326 | ||
outputs+=( | ||
"Now drawing from 'AC Power' | ||
-InternalBattery-0 8%; charging; 2:46 remaining" | ||
) | ||
statuses+=(2) | ||
values+=(8) | ||
# https://github.com/nojhan/liquidprompt/issues/326 | ||
outputs+=( | ||
"Now drawing from 'Battery Power' | ||
-InternalBattery-0 9%; discharging; (no estimate)" | ||
) | ||
statuses+=(0) | ||
values+=(9) | ||
# https://github.com/nojhan/liquidprompt/issues/326 | ||
outputs+=( | ||
"Now drawing from 'Battery Power' | ||
-InternalBattery-0 7%; discharging; 0:13 remaining | ||
Battery Warning: Early" | ||
) | ||
statuses+=(0) | ||
values+=(7) | ||
|
||
|
||
function test_pmset { | ||
|
||
pmset() { | ||
printf '%s\n' "$__output" | ||
} | ||
|
||
for (( index=0; index < ${#values[@]}; index++ )); do | ||
__output=${outputs[$index]} | ||
|
||
LP_BATTERY_THRESHOLD=100 | ||
_lp_battery | ||
assertEquals "pmset battery below returns" "${statuses[$index]}" "$?" | ||
assertEquals "pmset battery value" "${values[$index]}" "$lp_battery" | ||
|
||
_status=${statuses[$index]} | ||
(( _status < 4 )) && _status=$(( _status + 1 )) | ||
|
||
LP_BATTERY_THRESHOLD=0 | ||
_lp_battery | ||
assertEquals "pmset battery above returns" "$_status" "$?" | ||
assertEquals "pmset battery value" "${values[$index]}" "$lp_battery" | ||
done | ||
} | ||
|
||
if [ -n "${ZSH_VERSION-}" ]; then | ||
SHUNIT_PARENT="$0" | ||
setopt shwordsplit ksh_arrays | ||
fi | ||
|
||
. ./shunit2 |