Skip to content

test/system: Don't use Bats' 'run' to only check if a command succeeded#1825

Merged
debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check
Jul 25, 2026
Merged

test/system: Don't use Bats' 'run' to only check if a command succeeded#1825
debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check

Conversation

@debarshiray

Copy link
Copy Markdown
Member

Bats' run helper is not necessary to merely check if a command
succeeded or not [1].

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. Therefore, directly invoking the command without run is
enough to stop execution in case of an error.

[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

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

The long options are easier to grep(1) for in the sources than their
shorter aliases.

Fallout from ecd1ced and
54a2ca1

containers#1825
@debarshiray
debarshiray force-pushed the wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check branch from 084d171 to de8ef82 Compare July 25, 2026 00:01
@debarshiray

Copy link
Copy Markdown
Member Author

Build failed. https://gateway-cloud-softwarefactory.apps.ocp.cloud.ci.centos.org/zuul/t/local/buildset/61a09b8c654e4a2197592e1a2e619b9f

system-test-fedora-44-runtime-environment-arch-fedora FAILURE

fedora-44 | ok 1 ipc: No namespace
fedora-44 | not ok 2 setup_file failed
fedora-44 | # (from function `assert_success' in file test/system/libs/bats-assert/src/assert.bash, line 114,
fedora-44 | #  from function `pull_distro_image' in file test/system/libs/helpers.bash, line 398,
fedora-44 | #  from function `create_distro_container' in file test/system/libs/helpers.bash, line 454,
fedora-44 | #  from function `setup_file' in test file test/system/203-network.bats, line 41)
fedora-44 | #   `create_distro_container arch latest arch-toolbox-latest' failed
fedora-44 | # ~ /home/zuul-worker/src/github.com/containers/toolbox
fedora-44 | # Failed to load image quay.io/toolbx/arch-toolbox:latest from cache /var/tmp/bats-run-20NPwD/suite/image-cache/arch-toolbox-latest
fedora-44 | #
fedora-44 | # -- command failed --
fedora-44 | # status : 1
fedora-44 | # output (5 lines):
fedora-44 | #   Getting image source signatures
fedora-44 | #   Copying blob sha256:e2eebe7c62faa3bf6b7a06922f46a8458b52fe835b3e7fcf7beb85d5f1788e79
fedora-44 | #   Copying blob sha256:fd51648cfd49d3b15a6bfbc3aecea36d7f69920503571226567bbef5a7c5ae8e
fedora-44 | #   Copying blob sha256:7362ebf38326f221a89826d0a405abda87eb6c1ac3da308420c3f61db33ea9f2
fedora-44 | #   time="2026-07-25T00:08:08Z" level=fatal msg="copying config: context deadline exceeded"
fedora-44 | # --

@debarshiray

Copy link
Copy Markdown
Member Author

recheck

debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 25, 2026
Bats' 'run' helper is not necessary to merely check if a command
succeeded or not [1].

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.  Therefore, directly invoking the command without 'run' is
enough to stop execution in case of an error.

Perhaps more importantly, until Bats 1.14.0 that came out four days ago,
'run --separate-stderr' didn't work inside setup_suite() because
BATS_TEST_TMPDIR wasn't defined [3].

So far, a failure led to:
  not ok 1 setup_suite
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  from function `_pull_and_cache_distro_image' in file
       test/system/libs/helpers.bash, line 110,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  #
  # -- command failed --
  # status : 1
  # output : mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied
  # --
  #

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 109,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  # mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied

Fallout from 8f6dead and
ecd1ced

[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] Bats commit 33ffbedd2760e51c
    bats-core/bats-core@33ffbedd2760e51c
    bats-core/bats-core#1118

containers#1825
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 25, 2026
Bats' 'run' helper is not necessary to merely check if a command
succeeded or not [1].

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.  Therefore, directly invoking the command without 'run' is
enough to stop execution in case of an error.

Perhaps more importantly, until Bats 1.14.0 that came out four days ago,
'run --separate-stderr' didn't work inside setup_suite() because
BATS_TEST_TMPDIR wasn't defined [3].  Hence, using 'run' in these
functions used in setup_suite() exposed it to the possibility that it
would be used in ways that don't work.

So far, a failure led to:
  not ok 1 setup_suite
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  from function `_pull_and_cache_distro_image' in file
       test/system/libs/helpers.bash, line 110,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  #
  # -- command failed --
  # status : 1
  # output : mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied
  # --
  #

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 109,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  # mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied

Fallout from 8f6dead and
ecd1ced

[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] Bats commit 33ffbedd2760e51c
    bats-core/bats-core@33ffbedd2760e51c
    bats-core/bats-core#1118

containers#1825
@debarshiray
debarshiray force-pushed the wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check branch from ce688ce to 9f52e10 Compare July 25, 2026 12:50
Bats' 'run' helper is not necessary to merely check if a command
succeeded or not [1].

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.  Therefore, directly invoking the command without 'run' is
enough to stop execution in case of an error.

Perhaps more importantly, until Bats 1.14.0 that came out four days ago,
'run --separate-stderr' didn't work inside setup_suite() because
BATS_TEST_TMPDIR wasn't defined [3].  Hence, using 'run' in these
functions used in setup_suite() exposed them to the possibility that it
would be used in ways that don't work.

So far, a failure led to:
  not ok 1 setup_suite
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  from function `_pull_and_cache_distro_image' in file
       test/system/libs/helpers.bash, line 110,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  #
  # -- command failed --
  # status : 1
  # output : mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied
  # --
  #

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 109,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 52)
  #   `_pull_and_cache_distro_image fedora 34' failed
  # mkdir: cannot create directory
      ‘/var/tmp/bats-run-KCijAa/suite/image-cache’: Permission denied

Fallout from 8f6dead and
ecd1ced

[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] Bats commit 33ffbedd2760e51c
    bats-core/bats-core@33ffbedd2760e51c
    bats-core/bats-core#1118

containers#1825
@debarshiray
debarshiray force-pushed the wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check branch from 9f52e10 to 8422277 Compare July 25, 2026 17:08
@debarshiray
debarshiray merged commit 8422277 into containers:main Jul 25, 2026
3 checks passed
@debarshiray
debarshiray deleted the wip/rishi/test-system-run-helper-is-not-necessary-to-merely-check branch July 25, 2026 22:41
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