Skip to content

Commit

Permalink
lib/battery: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelicWizard committed Feb 9, 2022
1 parent 8ef853c commit bf5e947
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 67 deletions.
60 changes: 31 additions & 29 deletions test/lib/battery.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
load ../test_helper
load ../test_helper_libs

load ../../plugins/available/battery.plugin
function local_setup() {
load "../../lib/battery.bash"
}

# Sets up the `_command_exists` function so that it only responds `true` if called with
# the name of the function that was passed in as an argument to `setup_command_exists`.
Expand Down Expand Up @@ -37,7 +39,7 @@ function setup_command_exists {
# no tool
#

@test 'plugins battery: battery-percentage with no tool' {
@test 'lib battery: battery-percentage with no tool' {
setup_command_exists "fooooo"

run battery_percentage
Expand All @@ -59,7 +61,7 @@ function setup_pmset {
}
}

@test 'plugins battery: battery-percentage with pmset, 100%' {
@test 'lib battery: battery-percentage with pmset, 100%' {
setup_command_exists "pmset"

setup_pmset "100%"
Expand All @@ -68,7 +70,7 @@ function setup_pmset {
assert_output "100"
}

@test 'plugins battery: battery-percentage with pmset, 98%' {
@test 'lib battery: battery-percentage with pmset, 98%' {
setup_command_exists "pmset"

setup_pmset "98%"
Expand All @@ -77,7 +79,7 @@ function setup_pmset {
assert_output "98"
}

@test 'plugins battery: battery-percentage with pmset, 98.5%' {
@test 'lib battery: battery-percentage with pmset, 98.5%' {
setup_command_exists "pmset"

setup_pmset "98.5%"
Expand All @@ -86,7 +88,7 @@ function setup_pmset {
assert_output "98"
}

@test 'plugins battery: battery-percentage with pmset, 4%' {
@test 'lib battery: battery-percentage with pmset, 4%' {
setup_command_exists "pmset"

setup_pmset "4%"
Expand All @@ -95,7 +97,7 @@ function setup_pmset {
assert_output "04"
}

@test 'plugins battery: battery-percentage with pmset, no status' {
@test 'lib battery: battery-percentage with pmset, no status' {
setup_command_exists "pmset"

setup_pmset ""
Expand All @@ -122,7 +124,7 @@ function setup_acpi {
}
}

@test 'plugins battery: battery-percentage with acpi, 100% Full' {
@test 'lib battery: battery-percentage with acpi, 100% Full' {
setup_command_exists "acpi"

setup_acpi "100%" "Full"
Expand All @@ -131,7 +133,7 @@ function setup_acpi {
assert_output "100"
}

@test 'plugins battery: battery-percentage with acpi, 98% Charging' {
@test 'lib battery: battery-percentage with acpi, 98% Charging' {
setup_command_exists "acpi"

setup_acpi "98%" "Charging"
Expand All @@ -140,7 +142,7 @@ function setup_acpi {
assert_output "98"
}

@test 'plugins battery: battery-percentage with acpi, 98% Discharging' {
@test 'lib battery: battery-percentage with acpi, 98% Discharging' {
setup_command_exists "acpi"

setup_acpi "98%" "Discharging"
Expand All @@ -149,7 +151,7 @@ function setup_acpi {
assert_output "98"
}

@test 'plugins battery: battery-percentage with acpi, 98% Unknown' {
@test 'lib battery: battery-percentage with acpi, 98% Unknown' {
setup_command_exists "acpi"

setup_acpi "98%" "Unknown"
Expand All @@ -158,7 +160,7 @@ function setup_acpi {
assert_output "98"
}

@test 'plugins battery: battery-percentage with acpi, 4% Charging' {
@test 'lib battery: battery-percentage with acpi, 4% Charging' {
setup_command_exists "acpi"

setup_acpi "4%" "Charging"
Expand All @@ -167,7 +169,7 @@ function setup_acpi {
assert_output "04"
}

@test 'plugins battery: battery-percentage with acpi, 4% no status' {
@test 'lib battery: battery-percentage with acpi, 4% no status' {
setup_command_exists "acpi"

setup_acpi "4%" ""
Expand All @@ -176,7 +178,7 @@ function setup_acpi {
assert_output "04"
}

@test 'plugins battery: battery-percentage with acpi, no status' {
@test 'lib battery: battery-percentage with acpi, no status' {
setup_command_exists "acpi"

setup_acpi "" ""
Expand All @@ -200,7 +202,7 @@ function setup_upower {
}
}

@test 'plugins battery: battery-percentage with upower, 100%' {
@test 'lib battery: battery-percentage with upower, 100%' {
setup_command_exists "upower"

setup_upower "100.00%"
Expand All @@ -209,7 +211,7 @@ function setup_upower {
assert_output "100"
}

@test 'plugins battery: battery-percentage with upower, 98%' {
@test 'lib battery: battery-percentage with upower, 98%' {
setup_command_exists "upower"

setup_upower "98.4567%"
Expand All @@ -218,7 +220,7 @@ function setup_upower {
assert_output "98"
}

@test 'plugins battery: battery-percentage with upower, 98.5%' {
@test 'lib battery: battery-percentage with upower, 98.5%' {
setup_command_exists "upower"

setup_upower "98.5%"
Expand All @@ -227,7 +229,7 @@ function setup_upower {
assert_output "98"
}

@test 'plugins battery: battery-percentage with upower, 4%' {
@test 'lib battery: battery-percentage with upower, 4%' {
setup_command_exists "upower"

setup_upower "4.2345%"
Expand All @@ -236,7 +238,7 @@ function setup_upower {
assert_output "04"
}

@test 'plugins battery: battery-percentage with upower, no output' {
@test 'lib battery: battery-percentage with upower, no output' {
setup_command_exists "upower"

setup_upower ""
Expand All @@ -260,7 +262,7 @@ function setup_ioreg {
}
}

@test 'plugins battery: battery-percentage with ioreg, 100%' {
@test 'lib battery: battery-percentage with ioreg, 100%' {
setup_command_exists "ioreg"

setup_ioreg "100%"
Expand All @@ -269,7 +271,7 @@ function setup_ioreg {
assert_output "100"
}

@test 'plugins battery: battery-percentage with ioreg, 98%' {
@test 'lib battery: battery-percentage with ioreg, 98%' {
setup_command_exists "ioreg"

setup_ioreg "98%"
Expand All @@ -278,7 +280,7 @@ function setup_ioreg {
assert_output "98"
}

@test 'plugins battery: battery-percentage with ioreg, 98.5%' {
@test 'lib battery: battery-percentage with ioreg, 98.5%' {
setup_command_exists "ioreg"

setup_ioreg "98.5%"
Expand All @@ -287,7 +289,7 @@ function setup_ioreg {
assert_output "98"
}

@test 'plugins battery: battery-percentage with ioreg, 4%' {
@test 'lib battery: battery-percentage with ioreg, 4%' {
setup_command_exists "ioreg"

setup_ioreg "4%"
Expand All @@ -296,7 +298,7 @@ function setup_ioreg {
assert_output "04"
}

@test 'plugins battery: battery-percentage with ioreg, no status' {
@test 'lib battery: battery-percentage with ioreg, no status' {
setup_command_exists "ioreg"

# Simulate that no battery is present
Expand All @@ -323,7 +325,7 @@ function setup_WMIC {
}
}

@test 'plugins battery: battery-percentage with WMIC, 100%' {
@test 'lib battery: battery-percentage with WMIC, 100%' {
setup_command_exists "WMIC"

setup_WMIC "100%"
Expand All @@ -332,7 +334,7 @@ function setup_WMIC {
assert_output "100"
}

@test 'plugins battery: battery-percentage with WMIC, 98%' {
@test 'lib battery: battery-percentage with WMIC, 98%' {
setup_command_exists "WMIC"

setup_WMIC "98%"
Expand All @@ -341,7 +343,7 @@ function setup_WMIC {
assert_output "98"
}

@test 'plugins battery: battery-percentage with WMIC, 98.5%' {
@test 'lib battery: battery-percentage with WMIC, 98.5%' {
setup_command_exists "WMIC"

setup_WMIC "98.5%"
Expand All @@ -350,7 +352,7 @@ function setup_WMIC {
assert_output "98"
}

@test 'plugins battery: battery-percentage with WMIC, 4%' {
@test 'lib battery: battery-percentage with WMIC, 4%' {
setup_command_exists "WMIC"

setup_WMIC "4%"
Expand All @@ -359,7 +361,7 @@ function setup_WMIC {
assert_output "04"
}

@test 'plugins battery: battery-percentage with WMIC, no status' {
@test 'lib battery: battery-percentage with WMIC, no status' {
setup_command_exists "WMIC"

setup_WMIC ""
Expand Down
53 changes: 15 additions & 38 deletions test/themes/base.theme.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,26 @@ load ../test_helper
load ../test_helper_libs
load ../../themes/base.theme

@test 'themes base: battery_percentage should not exist' {
run type -a battery_percentage &> /dev/null
@test 'themes base: battery_percentage should exist if battery plugin loaded' {
run type -t battery_percentage
assert_failure
}

@test 'themes base: battery_percentage should exist if battery plugin loaded' {
load ../../plugins/available/battery.plugin
load "../../lib/battery.bash"

run type -a battery_percentage &> /dev/null
run type -t battery_percentage
assert_success
assert_output "function"
}

@test 'themes base: battery_char should exist' {
@test 'themes base: battery_char should exist if battery plugin loaded' {
run type -t battery_char
assert_success
assert_line "function"
assert_output "function"

run battery_char
assert_line -n 0 ""
}

@test 'themes base: battery_char should exist if battery plugin loaded' {
unset -f battery_char

load ../../plugins/available/battery.plugin
load "../../lib/battery.bash"
run type -t battery_percentage
assert_success
assert_line "function"

load ../../themes/base.theme
run type -t battery_char
assert_success
assert_line "function"
assert_output "function"

run battery_char
assert_success
Expand All @@ -45,26 +32,16 @@ load ../../themes/base.theme
assert_output --partial 'THEME_BATTERY_PERCENTAGE_CHECK'
}

@test 'themes base: battery_charge should exist' {
run type -a battery_charge &> /dev/null
assert_success

run battery_charge
assert_success
assert_line -n 0 ""
}

@test 'themes base: battery_charge should exist if battery plugin loaded' {
unset -f battery_charge
load ../../plugins/available/battery.plugin
load ../../themes/base.theme
run type -t battery_charge
assert_failure

run type -a battery_charge &> /dev/null
load "../../lib/battery.bash"

run type -t battery_charge
assert_success
assert_output "function"

run battery_charge
assert_success

run type -a battery_charge
assert_line ' no)'
}

0 comments on commit bf5e947

Please sign in to comment.