Skip to content

Commit

Permalink
add workflow tests for comparison checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed May 6, 2024
1 parent 489bf77 commit 1901992
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions testdata/err/invalid_comparisons.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test.yaml:16:17: "string" value cannot be compared to "{}" value with "==" operator [expression]
test.yaml:18:17: "number" value cannot be compared to "array<bool>" value with "!=" operator [expression]
test.yaml:20:17: "array<bool>" value cannot be compared to "array<{}>" value with "==" operator [expression]
test.yaml:22:17: "number" value cannot be compared to "null" value with ">" operator [expression]
test.yaml:24:17: "bool" value cannot be compared to "bool" value with "<" operator [expression]
test.yaml:26:17: "string" value cannot be compared to "{}" value with ">=" operator [expression]
test.yaml:28:17: "bool" value cannot be compared to "array<bool>" value with "<=" operator [expression]
28 changes: 28 additions & 0 deletions testdata/err/invalid_comparisons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on: push

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
o:
- {}
a:
- [true]
a2:
- [{}]
steps:
- run: echo 'comparing == to object with implicit conversion is not allowed'
if: ${{ 'foo' == matrix.o }}
- run: echo 'comparing != to array with implicit conversion is not allowed'
if: ${{ 42 != matrix.a }}
- run: echo 'comparing == array and incompatible array is not allowed'
if: ${{ matrix.a == matrix.a2 }}
- run: echo 'comparing > to null is not allowed'
if: ${{ 1 > null }}
- run: echo 'comparing > to bool is not allowed'
if: ${{ false < true }}
- run: echo 'comparing >= to object is not allowed'
if: ${{ 'foo' >= matrix.o }}
- run: echo 'comparing <= to array is not allowed'
if: ${{ false <= matrix.a }}
30 changes: 30 additions & 0 deletions testdata/ok/valid_comparisons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on: push

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
o:
- {}
a:
- [true]
steps:
- run: echo 'string is converted to number implicitly'
if: ${{ '42' == 42 }}
- run: echo 'bool is converted to number implicitly'
if: ${{ true == 1 }}
- run: echo 'null is converted to number implicitly'
if: ${{ null == 0 }}
- run: echo 'string and bool implicit conversions are allowed though it is problematic'
if: ${{ '1' == true }}
- run: echo 'string and null implicit conversions are allowed though it is problematic'
if: ${{ '0' == null }}
- run: echo 'comparing null to any value is allowed'
if: ${{ null == matrix.o }}
- run: echo 'comparing object to object is allowed'
if: ${{ matrix.o == matrix.o }}
- run: echo 'comparing object to object is allowed'
if: ${{ matrix.a == matrix.a }}
- run: echo 'string is converted to number implicitly on <'
if: ${{ '41' < 42 }}

0 comments on commit 1901992

Please sign in to comment.