Skip to content

Commit

Permalink
Merge pull request #124 from fish-shop/refactor-tests
Browse files Browse the repository at this point in the history
Add title input and refactor tests
  • Loading branch information
marcransome authored Aug 25, 2024
2 parents 864e566 + 57631c2 commit 83ad7f8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 25 deletions.
81 changes: 62 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,71 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Install fish shell
uses: fish-shop/install-fish-shell@720ad65b07b693d9332d73aaf811502196c1efb8 # v1.0.12
- name: Create test file
- name: Create passing tests
run: |
cat << 'EOF' > test.fish
@test "passing test" (true) $status -eq 0
@test "passing test" (true) $status -eq 0
@test "passing test" (true) $status -eq 0
EOF
- name: Run fishtape tests
id: run-fishtape-tests
echo > test.fish
for count in (seq 1 3)
echo '@test "passing test" (true) $status -eq 0' >> test.fish
end
shell: fish {0}
- name: Test passing tests
id: passing-tests
continue-on-error: true
uses: ./
with:
title: 'Passing tests summary'
- name: Check passing tests outcome
run: |
if test "${{ steps.passing-tests.outcome }}" != "success"
echo "Action is expected to succeed for file with passing tests"
exit 1
end
shell: fish {0}
- name: Create failing tests
run: |
echo > test.fish
for count in (seq 1 3)
echo '@test "failing test" (false) $status -eq 0' >> test.fish
end
shell: fish {0}
- name: Test failing tests
id: failing-tests
continue-on-error: true
uses: ./
- name: Check fishtape installed
run: type -q fishtape
with:
title: 'Failing tests summary'
- name: Check failing tests outcome
run: |
if test "${{ steps.failing-tests.outcome }}" != "failure"
echo "Action is expected to fail for file with failing tests"
exit 1
end
shell: fish {0}
- name: Create mixed passing/failing tests
run: |
echo > test.fish
for count in (seq 1 3)
echo '@test "passing test" (true) $status -eq 0' >> test.fish
end
for count in (seq 1 2)
echo '@test "failing test" (false) $status -eq 0' >> test.fish
end
shell: fish {0}
- name: Test mixed passing/failing tests
id: mixed-tests
continue-on-error: true
uses: ./
with:
title: 'Mixed tests summary'
- name: Check output parameters
env:
TOTAL: ${{ steps.run-fishtape-tests.outputs.total }}
PASSED: ${{ steps.run-fishtape-tests.outputs.passed }}
FAILED: ${{ steps.run-fishtape-tests.outputs.failed }}
TOTAL: ${{ steps.mixed-tests.outputs.total }}
PASSED: ${{ steps.mixed-tests.outputs.passed }}
FAILED: ${{ steps.mixed-tests.outputs.failed }}
run: |
set failures 0
set expected_total 3
set expected_total 5
if test "$TOTAL" != "$expected_total"
echo "Output parameter 'total' should equal $expected_total (got '$TOTAL')"
set failures (math $failures + 1)
Expand All @@ -59,16 +102,16 @@ jobs:
set expected_passes 3
if test "$PASSED" != "$expected_passes"
echo "Output parameter 'passed' should equal $expected_passes (got '$PASSED')"
set failures (math $failures + 1)
echo "Output parameter 'passed' should equal $expected_passes (got '$PASSED')"
set failures (math $failures + 1)
else
echo "Output parameter 'passed' equals expected value $expected_passes"
end
set expected_failures 0
set expected_failures 2
if test "$FAILED" != "$expected_failures"
echo "Output parameter 'failed' should equal $expected_failures (got '$FAILED')"
set failures (math $failures + 1)
echo "Output parameter 'failed' should equal $expected_failures (got '$FAILED')"
set failures (math $failures + 1)
else
echo "Output parameter 'failed' equals expected value $expected_failures"
end
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Configure the action using the following inputs:
|--------------|----------------------------------------|-----------------------|
| `patterns` | A space-separated list of file patterns to match against when running tests; each pattern may include [wildcards](https://fishshell.com/docs/current/language.html#expand-wildcard) and/or [brace expansions](https://fishshell.com/docs/current/language.html?highlight=brace+expansion#brace-expansion) | `**.fish` |
| `raw-output` | The string value `'true'` or `'false'` indicating whether to generate raw [TAP](https://testanything.org/) output or not; output is prettified using [tap-diff](https://github.com/axross/tap-diff) when `'false'` | `false` |
| `title` | The title to display in the job summary; can be used to distinguish multiple summaries generated from a single workflow | `Test results` |

## Outputs

Expand Down
18 changes: 12 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ branding:
icon: 'check-square'
color: 'green'
inputs:
title:
description: 'Title to display in job summary'
required: false
default: 'Test results'
patterns:
description: 'File patterns to match against when running tests'
required: false
Expand Down Expand Up @@ -36,12 +40,14 @@ runs:
- name: Run fishtape tests
id: run-fishtape-tests
env:
TITLE: ${{ inputs.title }}
PATTERNS: ${{ inputs.patterns }}
RAW_OUTPUT: ${{ inputs.raw-output }}
run: |
set -gx TERM xterm-256color
set -gx FORCE_COLOR 2
set title "$TITLE"
set raw_output (string escape --no-quoted -- $RAW_OUTPUT)
for pattern in (string split --no-empty -- " " $PATTERNS)
Expand All @@ -65,18 +71,18 @@ runs:
set failed (tail -n 4 output | sed -rn 's/^# fail ([[:digit:]]+)$/\1/p')
for param in total passed failed
if test -z "$$param"
set $param 0
end
if test -z "$$param"
set $param 0
end
end
if test "$failed" = "0"
set result ":white_check_mark: Pass"
set result ":white_check_mark: Pass"
else
set result ":x: Fail"
set result ":x: Fail"
end
echo "### Test results" >> $GITHUB_STEP_SUMMARY
echo "### $title" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Test result :microscope: | Passed :white_check_mark: | Failed :x: |" >> $GITHUB_STEP_SUMMARY
echo "|--------------------------|---------------------------|------------|" >> $GITHUB_STEP_SUMMARY
Expand Down

0 comments on commit 83ad7f8

Please sign in to comment.