Skip to content

test/system: Simplify handling Bash's 'set -e' set by Bats#1816

Merged
debarshiray merged 1 commit into
containers:mainfrom
debarshiray:wip/rishi/test-system-simplify-set-e-ignore
Jul 6, 2026
Merged

test/system: Simplify handling Bash's 'set -e' set by Bats#1816
debarshiray merged 1 commit into
containers:mainfrom
debarshiray:wip/rishi/test-system-simplify-set-e-ignore

Conversation

@debarshiray

Copy link
Copy Markdown
Member

No description provided.

Bats sets Bash's 'set -e' [1,2] to fail and exit immediately if a
pipeline, list of commands or compound command returns with a non-zero
exit code.  This means that if the 'skopeo copy' used to download and
cache an OCI image in _pull_and_cache_distro_image() fails, the function
will return immediately without doing anything else, and it will be
impossible to try the 'skopeo copy' again.

So far, this was being solved by creating a situation where Bash ignores
the 'set -e' and doesn't exit [2].  Specifically, by assembling a list
of commands [3] separated by the '||' operator and ensuring that
_pull_and_cache_distro_image() wasn't the last.  This ignored 'set -e'
for the whole function.

Instead of expecting callers of _pull_and_cache_distro_image() to
carefully use the function in alignment with its implementation, it will
be better to align the implementation with itself.

So far, a failure to download and cache an image led to:
  not ok 1 setup_suite
  # (from function `setup_suite' in test file
       test/system/setup_suite.bash, line 45)
  #   `_pull_and_cache_distro_image arch latest || false' failed
  # Failed to cache image quay.io/toolbx/arch-toolbox:latest to
      /var/tmp/bats-run-KCijAa/suite/image-cache/arch-toolbox-latest
  # time="2026-07-05T14:58:26+02:00" level=fatal msg="initializing
      source docker://quay.io/toolbx/arch-toolbox:latest-foo: reading
      manifest latest-foo in quay.io/toolbx/arch-toolbox: manifest
      unknown"

Instead, from now on, it will be:
  not ok 1 setup_suite
  # (from function `_pull_and_cache_distro_image' in
       file test/system/libs/helpers.bash, line 136,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 45)
  #   `_pull_and_cache_distro_image arch latest' failed with status 2
  # Failed to cache image quay.io/toolbx/arch-toolbox:latest to
      /var/tmp/bats-run-E2i7Y7/suite/image-cache/arch-toolbox-latest
  # time="2026-07-05T14:52:17+02:00" level=fatal msg="initializing
      source docker://quay.io/toolbx/arch-toolbox:latest-foo: reading
      manifest latest-foo in quay.io/toolbx/arch-toolbox: manifest
      unknown"

The differences are minor.  The backtrace will now show the exit code of
'skopeo copy' and the return site of _pull_and_cache_distro_image().

Fallout from 54a2ca1

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

[2] https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

[3] https://www.gnu.org/software/bash/manual/html_node/Lists.html

containers#1816

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the _pull_and_cache_distro_image helper function in test/system/libs/helpers.bash to correctly capture the exit status of the skopeo command substitution by using an OR operator (|| ret_val="$?") and initializing ret_val to 0. Additionally, it simplifies test/system/setup_suite.bash by removing the redundant || false suffixes from the _pull_and_cache_distro_image calls. There are no review comments, and I have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@debarshiray debarshiray force-pushed the wip/rishi/test-system-simplify-set-e-ignore branch from 2c61968 to 8ffe191 Compare July 5, 2026 14:14
@debarshiray

Copy link
Copy Markdown
Member Author

@debarshiray debarshiray merged commit 8ffe191 into containers:main Jul 6, 2026
2 of 3 checks passed
@debarshiray debarshiray deleted the wip/rishi/test-system-simplify-set-e-ignore branch July 6, 2026 00:17
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.

1 participant