Added tests for WMIC

pull/1080/head
Nils Winkler 2017-10-24 07:40:42 +02:00
parent 601202e816
commit 7602b1da32
2 changed files with 60 additions and 9 deletions

View File

@ -72,15 +72,8 @@ battery_percentage(){
echo ${IOREG_OUTPUT:--1}
elif _command_exists WMIC;
then
local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*')
case $WINPC in
100*)
echo '100'
;;
*)
echo $WINPC
;;
esac
local WINPC=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
echo ${WINPC:--1}
else
echo "no"
fi

View File

@ -272,3 +272,61 @@ function setup_ioreg {
run battery_percentage
assert_output "0"
}
#######################
#
# WMIC
#
function setup_WMIC {
percent="$1"
function WMIC {
printf "Charge: %s" "${percent}"
}
}
@test 'plugins battery: battery-percentage with WMIC, 100%' {
setup_command_exists "WMIC"
setup_WMIC "100%"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with WMIC, 98%' {
setup_command_exists "WMIC"
setup_WMIC "98%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with WMIC, 98.5%' {
setup_command_exists "WMIC"
setup_WMIC "98.5%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with WMIC, 4%' {
setup_command_exists "WMIC"
setup_WMIC "4%"
run battery_percentage
assert_output "4"
}
@test 'plugins battery: battery-percentage with WMIC, no status' {
setup_command_exists "WMIC"
setup_WMIC ""
run battery_percentage
assert_output "-1"
}