Consolidated cases for acpi

pull/1080/head
Nils Winkler 2017-10-23 17:14:53 +02:00
parent 3aed38c79f
commit 486c9e1382
2 changed files with 11 additions and 24 deletions

View File

@ -60,30 +60,8 @@ battery_percentage(){
elif _command_exists acpi; elif _command_exists acpi;
then then
local ACPI_OUTPUT=$(acpi -b) local ACPI_OUTPUT=$(acpi -b)
case $ACPI_OUTPUT in local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
*" Unknown"*) echo ${PERC_OUTPUT:--1}
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
case $PERC_OUTPUT in
*%)
echo "0${PERC_OUTPUT}" | head -c 2
;;
*)
echo ${PERC_OUTPUT}
;;
esac
;;
*" Charging"* | *" Discharging"*)
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
echo ${PERC_OUTPUT}
;;
*" Full"*)
echo '100'
;;
*)
echo '-1'
;;
esac
elif _command_exists pmset; elif _command_exists pmset;
then then
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p') local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')

View File

@ -135,6 +135,15 @@ function setup_acpi {
setup_acpi "4%" "" setup_acpi "4%" ""
run battery_percentage
assert_output "4"
}
@test 'plugins battery: battery-percentage with acpi, no status' {
setup_command_exists "acpi"
setup_acpi "" ""
run battery_percentage run battery_percentage
assert_output "-1" assert_output "-1"
} }