Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin/battery: fix handling of multiple batteries with upower #2105

Merged
merged 1 commit into from
Mar 4, 2022

Conversation

gaelicWizard
Copy link
Contributor

Description

This should fix both our BATS tests as well as the battery_percentage() (and related) function(s) to properly handle multiple attached batteries, and closes #2104.

Motivation and Context

The previous fix for multiple batteries returned by upower -e just tried to snip off the first line and run with it, but this seems to have triggered a bug in Bash related to set -o pipefail (which is enabled by BATS during testing, and elsewhere).

This patch changes plugin/battery to just read all the batteries into an array, thus not cutting off the enumeration prematurely and avoiding the testing bug.

Currently, this patch does not handle any batteries after the first, but at least it doesn't just trim the list.

How Has This Been Tested?

locally, and GitHub Actions

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@NoahGorny NoahGorny merged commit 9dece7f into Bash-it:master Mar 4, 2022
@gaelicWizard gaelicWizard deleted the bats/upower branch March 4, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test battery_percentage with upower fails randomly
2 participants