Skip to content

Fix post-increment causing silent exit under set -e#619

Merged
Chemaclass merged 4 commits intoTypedDevs:mainfrom
objctp:fix/post-increment-exit-code-bash-set-e
Apr 9, 2026
Merged

Fix post-increment causing silent exit under set -e#619
Chemaclass merged 4 commits intoTypedDevs:mainfrom
objctp:fix/post-increment-exit-code-bash-set-e

Conversation

@objctp
Copy link
Copy Markdown
Contributor

@objctp objctp commented Apr 9, 2026

Background

Related #618

LCOV and HTML coverage reports were incomplete/missing due to ((var++)) post-increment operator causing early script termination under set -e.

Changes

  • Fixed report_lcov() and generate_file_html() post-increment causing silent exit under set -e
  • Standardised remaining ((var++)) to ((++var)) for consistency (preventive)

Checklist

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

@Chemaclass Chemaclass added the bug Something isn't working label Apr 9, 2026
Copy link
Copy Markdown
Member

@Chemaclass Chemaclass left a comment

Choose a reason for hiding this comment

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

  • Complete coverage: all standalone ((var++)) outside for loop headers are changed. state.sh is correctly left alone since it already uses || true.
  • Correct scope: bashunit runs with set -euo pipefail (set in /bashunit line 2 and src/globals.sh), so this affects bashunit's own execution, not just user scripts.
  • CHANGELOG entry is accurate and references #618.
  • No behavior change: only the expression return value changes, not the increment itself.

Concern: No regression test

The PR has zero tests. Given this bug causes silent failures (the { ... } > "$output_file" redirect swallows the error), a regression test would be valuable. Something like:

function test_get_executable_lines_succeeds_under_set_e() {
  local result
  result=$(set -e; bashunit::coverage::get_executable_lines "some_file.sh")
  assert_greater_than 0 "$result"
}

This would prevent future regressions if someone reintroduces ((var++)).

Add tests that run get_executable_lines, report_lcov, and str::rpad
in subshells with set -e to ensure ((++var)) does not cause silent
early exit when the counter starts at zero.
@Chemaclass
Copy link
Copy Markdown
Member

The failing are flaky tests not related to this changes. PR good to merge. Thanks!

@Chemaclass Chemaclass merged commit 0b892bf into TypedDevs:main Apr 9, 2026
41 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants