Skip to content

Commit

Permalink
test: remove FORCE_TTY from pipelines.sh
Browse files Browse the repository at this point in the history
This works around a lack of TTY in github actions. See actions/runner#241 (comment)

Signed-off-by: Nick Mitchell <[email protected]>
  • Loading branch information
starpit committed Oct 23, 2024
1 parent 985fa7a commit f12de45
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
# GitHub Actions run without a TTY device. This is a workaround to get one,
# based on https://github.com/actions/runner/issues/241#issuecomment-2019042651
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'

on:
push:
branches: [ main ]
Expand Down
51 changes: 32 additions & 19 deletions tests/bin/pipelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ function actual {
echo "$dir"/"$bb".output.$ext
}

function tester {
cmdline="$1"
function start {
echo
echo "🧪 $(tput setaf 5)Starting Pipeline Test: $(tput bold)$1$(tput sgr0)"
echo -n "$(tput dim)"
}

function validate {
echo -n "$(tput sgr0)"
actual_ec=$1
expected="$2"
actual="$3"
expected_ec=${4:-0}

echo ""
echo "------------------------------------------------------------------------------------"
echo " $(tput bold)Test:$(tput sgr0) $1"
echo " $(tput bold)Expected:$(tput sgr0) $expected"
echo " $(tput bold)Actual:$(tput sgr0) $actual"
echo " $(tput bold)Expected exit code$(tput sgr0): $expected_ec"
echo "------------------------------------------------------------------------------------"
echo "🧪 $(tput setaf 5)Expected: $expected$(tput sgr0)"
echo "🧪 $(tput setaf 5)Actual: $actual$(tput sgr0)"
echo "🧪 $(tput setaf 5)Expected exit code: $expected_ec$(tput sgr0)"

set +e
eval "$1 $input"
actual_ec=$?
set -e
if [[ $actual_ec = $expected_ec ]]
then echo "✅ PASS the exit code matches actual_ec=$actual_ec expected_ec=$expected_ec test=$1"
else echo "❌ FAIL mismatched exit code actual_ec=$actual_ec expected_ec=$expected_ec test=$1" && return 1
Expand All @@ -75,14 +74,28 @@ function tester {
}

lpcat="$lp cat $VERBOSE"
lpcatfinal="LUNCHPAIL_FORCE_TTY=1 $lp cat $VERBOSE"

tester "$lpcatfinal $IN1" "$IN1" $(actual "$IN1") # input should equal output
tester "$lpcatfinal nopenopenopenopenope" n/a n/a 1 # expect failure trying to cat a non-existent file
start "cat"
$lpcat $IN1
validate $? "$IN1" $(actual "$IN1") # input should equal output

start "cat expecting error"
set +e
$lpcat nopenopenopenopenope
validate $? n/a n/a 1
set -e

start "cat | cat"
$lpcat $IN1 | $lpcat
validate $? "$IN1" $(actual "$IN1" .)

tester "$lpcat $IN1 | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat: input should still equal output
tester "$lpcat $IN1 | $lpcat | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat | cat: input should still equal output
tester "$lpcat $IN1 | $lpcat | $lpcat | $lpcatfinal" "$IN1" $(actual "$IN1" .) # cat | cat | cat | cat: input should still equal output
start "cat | cat | cat"
$lpcat $IN1 | $lpcat | $lpcat # cat | cat | cat
validate $? "$IN1" $(actual "$IN1" .)

start "cat | cat | cat | cat"
$lpcat $IN1 | $lpcat | $lpcat | $lpcat # cat | cat | cat | cat
validate $? "$IN1" $(actual "$IN1" .)

echo
echo "✅ PASS all pipeline tests have passed!"

0 comments on commit f12de45

Please sign in to comment.