Skip to content

Commit

Permalink
tests: qualify commands with run and ignore pipe errors
Browse files Browse the repository at this point in the history
When `set -o pipefail` is enabled, `yes | X` fails even when
such pipe cutoff is intended.
  • Loading branch information
ZoomTen committed Jun 19, 2024
1 parent e977c81 commit 458ebf4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/init-rgbenv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ setup() {

@test "init rgbenv at ~/.rgbenv" {
export XDG_DATA_HOME=""
yes | rgbenv
set +o pipefail && yes | rgbenv

assert [ -d "$HOME/.rgbenv" ]
assert [ -d "$HOME/.rgbenv/versions" ]
Expand All @@ -22,7 +22,7 @@ setup() {
@test "init rgbenv at \$XDG_DATA_HOME/rgbenv" {
export XDG_DATA_HOME="$HOME/data"
mkdir $XDG_DATA_HOME # requires the dir to exist first
yes | rgbenv
set +o pipefail && yes | rgbenv

assert [ -d "$XDG_DATA_HOME/rgbenv" ]
assert [ -d "$XDG_DATA_HOME/rgbenv/versions" ]
Expand All @@ -37,7 +37,7 @@ setup() {

assert [ ! -d "$XDG_DATA_HOME/rgbenv" ]

yes | rgbenv # should offer to move the directory there
set +o pipefail && yes | rgbenv # should offer to move the directory there

assert [ ! -d "$HOME/.rgbenv" ]
assert [ -d "$XDG_DATA_HOME/rgbenv" ]
Expand Down
16 changes: 8 additions & 8 deletions tests/install-rgbds.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ get_old_version() {

@test "verify correct rgbasm version" {
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
rgbenv use 0.5.1
run rgbenv use 0.5.1
assert [ -x "$RGBENV_TEST_DEFAULT/bin/rgbasm" ]
assert [ "$(rgbasm -V)" = "rgbasm v0.5.1" ]
}

@test "verify correct rgblink version" {
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
rgbenv use 0.5.1
run rgbenv use 0.5.1
assert [ -x "$RGBENV_TEST_DEFAULT/bin/rgblink" ]
assert [ "$(rgblink -V)" = "rgblink v0.5.1" ]
}

@test "verify correct rgbgfx version" {
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
rgbenv use 0.5.1
run rgbenv use 0.5.1
assert [ -x "$RGBENV_TEST_DEFAULT/bin/rgbgfx" ]
assert [ "$(rgbgfx -V)" = "rgbgfx v0.5.1" ]
}

@test "install two RGBDS versions" {
# ...but redownload versions anyway, just for this:
rgbenv install 0.5.1
rgbenv install 0.6.1
run rgbenv install 0.5.1
run rgbenv install 0.6.1

# save 0.6.1 for later
mv $RGBENV_TEST_VERSIONS/rgbds-0.6.1 $RGBENV_VERSION_CACHE/rgbds-0.6.1
Expand Down Expand Up @@ -112,11 +112,11 @@ compile_v061_051 () {
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
ln -s $RGBENV_VERSION_CACHE/rgbds-0.6.1 $RGBENV_TEST_VERSIONS/rgbds-0.6.1

rgbenv use 0.5.1
run rgbenv use 0.5.1
run compile_v051_051
assert_success

rgbenv use 0.6.1
run rgbenv use 0.6.1
run compile_v061_061
assert_success
}
Expand All @@ -125,7 +125,7 @@ compile_v061_051 () {
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
ln -s $RGBENV_VERSION_CACHE/rgbds-0.6.1 $RGBENV_TEST_VERSIONS/rgbds-0.6.1

rgbenv use 0.5.1
run rgbenv use 0.5.1
run compile_v061_051
assert_fail

Expand Down
10 changes: 5 additions & 5 deletions tests/uninstall-rgbds.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ check_used_version () {
}

@test "install a version of rgbds, use it, and then disuse it" {
rgbenv install 0.5.1
run rgbenv install 0.5.1
assert_success
mv $RGBENV_TEST_VERSIONS/rgbds-0.5.1 $RGBENV_VERSION_CACHE/rgbds-0.5.1
ln -s $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1

rgbenv use 0.5.1
run rgbenv use 0.5.1
assert [ -x "$RGBENV_TEST_DEFAULT/bin/rgbasm" ]

run check_used_version
assert_line_number -1 "rgbasm v0.5.1"

rgbenv no-use
run rgbenv no-use
assert [ ! -x "$RGBENV_TEST_DEFAULT/bin/rgbasm" ]
}

@test "uninstall an rgbds version" {
mv $RGBENV_VERSION_CACHE/rgbds-0.5.1 $RGBENV_TEST_VERSIONS/rgbds-0.5.1
rgbenv uninstall 0.5.1
run rgbenv uninstall 0.5.1
assert [ ! -x "$RGBENV_TEST_VERSIONS/rgbds-0.5.1/rgbasm" ]
}

@test "remove the rgbenv directories entirely" {
yes | rgbenv remove
set +eo pipefail && yes | rgbenv remove
assert [ ! -d "$RGBENV_TEST_VERSIONS" ]
assert [ ! -d "$RGBENV_TEST_DEFAULT" ]
}

0 comments on commit 458ebf4

Please sign in to comment.