From cc778ef6ba4d090bf772241942850841f2b5ace0 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 12 May 2026 14:08:21 +0100 Subject: [PATCH 1/2] Add automated tests for cowsay implementation --- .github/workflows/validate-pr-metadata.yml | 11 +++++-- expect/implement-cowsay/cow-grass.txt | 10 +++++++ expect/implement-cowsay/turtle-fish.txt | 22 ++++++++++++++ test-sdc.sh | 35 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 expect/implement-cowsay/cow-grass.txt create mode 100644 expect/implement-cowsay/turtle-fish.txt diff --git a/.github/workflows/validate-pr-metadata.yml b/.github/workflows/validate-pr-metadata.yml index 8ff276f7..b4ff6020 100644 --- a/.github/workflows/validate-pr-metadata.yml +++ b/.github/workflows/validate-pr-metadata.yml @@ -48,15 +48,20 @@ jobs: if: contains(steps.changed-files.outputs.modified_files, 'number-systems/') run: ./test-sdc.sh number-systems shell: bash + - name: test implement-cowsay + id: test-implement-cowsay + if: contains(steps.changed-files.outputs.modified_files, 'implement-cowsay/') + run: ./test-sdc.sh implement-cowsay + shell: bash - name: make output comment - if: steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y' || steps.test-number-systems.outputs.attempted == 'y' + if: steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y' || steps.test-number-systems.outputs.attempted == 'y' || steps.test-implement-cowsay.outputs.attempted == 'y' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ISSUE_URL: ${{ github.event.pull_request.html_url }} run: | gh pr comment $ISSUE_URL --body-file testoutput.txt - name: add appropriate labels - if: steps.test-individual-shell-tools.outputs.complete == 'y' || steps.test-jq.outputs.complete == 'y' || steps.test-shell-pipelines.outputs.complete == 'y' + if: steps.test-individual-shell-tools.outputs.complete == 'y' || steps.test-jq.outputs.complete == 'y' || steps.test-shell-pipelines.outputs.complete == 'y' || steps.test-implement-cowsay.outputs.complete == 'y' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ISSUE_URL: ${{ github.event.pull_request.html_url }} @@ -64,6 +69,6 @@ jobs: gh pr edit $ISSUE_URL --add-label "Complete" gh pr edit $ISSUE_URL --remove-label "Needs Review" - name: fail if not complete - if: (steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y') && !(steps.test-individual-shell-tools.outputs.complete == 'y' || steps.test-jq.outputs.complete == 'y' || steps.test-shell-pipelines.outputs.complete == 'y') + if: (steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y' || steps.test-implement-cowsay.outputs.attempted == 'y') && !(steps.test-individual-shell-tools.outputs.complete == 'y' || steps.test-jq.outputs.complete == 'y' || steps.test-shell-pipelines.outputs.complete == 'y' || steps.test-implement-cowsay.outputs.complete == 'y') run: | exit -1 diff --git a/expect/implement-cowsay/cow-grass.txt b/expect/implement-cowsay/cow-grass.txt new file mode 100644 index 00000000..d9c665a0 --- /dev/null +++ b/expect/implement-cowsay/cow-grass.txt @@ -0,0 +1,10 @@ + ________________ +| Grass, delicious | + ================ + \ + \ + ^__^ + (oo)\_______ + (__)\ )\/\ + ||----w | + || || diff --git a/expect/implement-cowsay/turtle-fish.txt b/expect/implement-cowsay/turtle-fish.txt new file mode 100644 index 00000000..5dadfa0e --- /dev/null +++ b/expect/implement-cowsay/turtle-fish.txt @@ -0,0 +1,22 @@ + ______________ +| Fish are cool! | + ============== + \ + \ + \ + \ + ___-------___ + _-~~ ~~-_ + _-~ /~-_ + /^\__/^\ /~ \ / \ + /| O|| O| / \_______________/ \ + | |___||__| / / \ \ + | \ / / \ \ + | (_______) /______/ \_________ \ + | / / \ / \ + \ \^\\ \ / \ / + \ || \______________/ _-_ //\__// + \ ||------_-~~-_ ------------- \ --/~ ~\ || __/ + ~-----||====/~ |==================| |/~~~~~ + (_(__/ ./ / \_\ \. + (_(___/ \_____)_) diff --git a/test-sdc.sh b/test-sdc.sh index b8f32cfb..1045b21e 100755 --- a/test-sdc.sh +++ b/test-sdc.sh @@ -127,6 +127,41 @@ elif [[ "$1" == "number-systems" ]]; then fi echo "Please let a volunteer check the answers for part 2." >> testoutput.txt cat testoutput.txt +elif [[ "$1" == "implement-cowsay" ]]; then + if [ -v GITHUB_OUTPUT ]; then + echo "attempted=y" >> "$GITHUB_OUTPUT" + fi + if [[ -e .cowsay-venv ]]; then + echo ".cowsay-venv already exists - couldn't test cowsay" >> testoutput.txt + else + if [ ! -e implement-cowsay/requirements.txt ]; then + echo "Expected implement-cowsay/requirements.txt to exist but it didn't" >> testoutput.txt + else + python3 -m venv .cowsay-venv + . .cowsay-venv/bin/activate + pip3 install -r implement-cowsay/requirements.txt + + all_ok=true + + python3 implement-cowsay/cow.py Grass, delicious > test.tmp + cmp test.tmp expect/implement-cowsay/cow-grass.txt + if [ $? -ne 0 ]; then + echo "Unexpected cowsay output for Grass, delicious" >> testoutput.txt + all_ok=false + fi + + python3 implement-cowsay/cow.py --animal turtle "Fish are cool!" > test.tmp + cmp test.tmp expect/implement-cowsay/turtle-fish.txt + if [ $? -ne 0 ]; then + echo "Unexpected cowsay output for Fish are cool!" >> testoutput.txt + all_ok=false + fi + + if [[ "${all_ok}" == "true" && -v GITHUB_OUTPUT ]]; then + echo "completed=y" >> "$GITHUB_OUTPUT" + fi + fi + fi else echo "Please run this with a valid test directory name as argument" fi From 676a031320cf9a7fb02af4b960d4350fb59abbb4 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 12 May 2026 14:43:00 +0100 Subject: [PATCH 2/2] Include dragon checks --- test-sdc.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test-sdc.sh b/test-sdc.sh index 1045b21e..ea66b048 100755 --- a/test-sdc.sh +++ b/test-sdc.sh @@ -157,6 +157,18 @@ elif [[ "$1" == "implement-cowsay" ]]; then all_ok=false fi + python3 implement-cowsay/cow.py --help | grep dragon + if [ $? -ne 0 ]; then + echo "Expected python3 cow.py --help to include dragon as it's one of the animal options" >> testoutput.txt + all_ok=false + fi + + grep dragon implement-cowsay/cow.py > /dev/null + if [ $? -eq 0 ]; then + echo "Didn't expect cow.py to include the word dragon - you should pull in the animal options from the library not write them yourself" >> testoutput.txt + all_ok=false + fi + if [[ "${all_ok}" == "true" && -v GITHUB_OUTPUT ]]; then echo "completed=y" >> "$GITHUB_OUTPUT" fi