Skip to content

Commit

Permalink
testing.sh: fix testing conditions and assertions
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Dec 1, 2024
1 parent 60c201d commit b5038bc
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ SCRIPTDIR="$(readlink -f "$0")" && SCRIPTDIR="${SCRIPTDIR%/*}"
TEST=
die()
{
set +x
R='\033[31m'
Z='\033[0m'
[ -n "$*" ] &&
echo -e "$SCRIPTNAME: $R**ERROR**:${TEST:+ $TEST:}$Z ${*:-aborting}" >&2
exit 127
( set +x
R='\033[31m'
Z='\033[0m'
[ -n "$*" ] &&
echo -e "$SCRIPTNAME: $R**ERROR**:${TEST:+ $TEST:}$Z ${*:-aborting}"
) >&2
exit 77
}
DEVERR=/dev/null
[[ " $* " =~ -x ]] && {
DEVERR=/dev/stderr
PS4="$SCRIPTNAME:\${LINENO}: "
PS4="+ $SCRIPTNAME:\${LINENO}: "
set -x
}

Expand All @@ -37,7 +38,7 @@ assert1error()
}
assert0error()
{
grep -Eq '\bERROR:' <<<"$*" &&
! grep -Eq '\bERROR:' <<<"$*" ||
die "output contains an ERROR message: $*"
}
assert_zero()
Expand All @@ -50,10 +51,9 @@ assert_nonzero()
test "$1" != 0 ||
die "command exit status failed to be non-zero: $1"
}
OK()
TEST_OK()
{
printf " %-7s" OK
echo "${TEST:-}$*"
printf ' %-7s %s\n' OK "$*"
}
mkcommits() # mkcommits A B 'A|B ->C'
( # Create empty test commits with bookamrks
Expand Down Expand Up @@ -83,20 +83,22 @@ clear_repo()
# == TESTS ==
TEST='jj-fzf-functions-fail-early'
clear_repo
( set +e
OUT="$(export EDITOR=false JJ_CONFIG='' && jj-fzf describe 'zzzzaaaa' 2>&1)"
assert_nonzero $?
( set -e
export JJ_CONFIG='' EDITOR=false
OUT="$(set +x; jj-fzf describe 'zzzzaaaa' 2>&1)" && E=$? || E=$?
assert_nonzero $E
assert1error "$OUT"
) && OK
); TEST_OK "$TEST"

TEST='jj-fzf-new'
clear_repo && mkcommits A B
( set +e
( set -e
export JJ_CONFIG=''
WC="$(jj log --no-pager --ignore-working-copy --no-graph -T commit_id -r @)"
OUT="$(export JJ_CONFIG='' && jj-fzf new A B 2>&1)"
assert_zero $?
OUT="$(set +x; jj-fzf new A B 2>&1)" && E=$? || E=$?
assert_zero $E
assert0error "$OUT"
NEW="$(jj log --no-pager --ignore-working-copy --no-graph -T commit_id -r @)"
test "$WC" != "$NEW" ||
die "failed to create new revision"
) && OK
); TEST_OK "$TEST"

0 comments on commit b5038bc

Please sign in to comment.