From 4e4bc530fe0de23ae30c56de558a4cea5a861b8d Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Wed, 23 Oct 2024 06:38:55 -0400 Subject: [PATCH] test: remove FORCE_TTY from pipelines.sh This works around a lack of TTY in github actions. See https://github.com/actions/runner/issues/241#issuecomment-2019042651 Signed-off-by: Nick Mitchell --- .github/workflows/tests.yml | 6 +++++ tests/bin/pipelines.sh | 49 +++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b26d651..0f319e31 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 ] diff --git a/tests/bin/pipelines.sh b/tests/bin/pipelines.sh index 03130eda..3d286c4a 100755 --- a/tests/bin/pipelines.sh +++ b/tests/bin/pipelines.sh @@ -34,24 +34,22 @@ function actual { echo "$dir"/"$bb".output.$ext } -function tester { - cmdline="$1" +function start { + echo "🧪 $(tput setaf 5)Starting Pipeline Test: $(tput bold)$1$(tput sgr0)" + echo -n "$(tput dim)" +} + +function validate { + echo "$(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 @@ -75,14 +73,27 @@ 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 "✅ PASS all pipeline tests have passed!"