-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests that run on github actions
- Loading branch information
Showing
3 changed files
with
163 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Run pytest | ||
|
||
on: [push] | ||
|
||
env: | ||
PYTHON_VERSION: "3.11" | ||
POETRY_VERSION: "1.4.2" | ||
POETRY_URL: https://install.python-poetry.org | ||
|
||
jobs: | ||
run-pytest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Python ${{ env.PYTHON_VERSION }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
id: setup_python | ||
- name: Cache Poetry cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pypoetry | ||
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }} | ||
- name: Cache Packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.local | ||
key: poetry-local-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }} | ||
- name: Install Poetry ${{ env.POETRY_VERSION }} | ||
run: | | ||
curl -sSL ${{ env.POETRY_URL }} | python - --version ${{ env.POETRY_VERSION }} | ||
echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
- name: Install Dependencies | ||
run: poetry install | ||
- name: Run pytest | ||
run: poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from textwrap import dedent | ||
from verified_cogen.runners.validating import remove_asserts_and_invariants | ||
|
||
|
||
def test_remove_line(): | ||
code = dedent( | ||
"""\ | ||
method main() { | ||
assert a == 1; // assert-line | ||
}""" | ||
) | ||
assert remove_asserts_and_invariants(code) == dedent( | ||
"""\ | ||
method main() { | ||
}""" | ||
) | ||
|
||
|
||
def test_remove_multiline_assert(): | ||
code = dedent( | ||
"""\ | ||
method main() { | ||
// assert-start | ||
assert a == 1 by { | ||
} | ||
// assert-end | ||
}""" | ||
) | ||
assert remove_asserts_and_invariants(code) == dedent( | ||
"""\ | ||
method main() { | ||
}""" | ||
) | ||
|
||
|
||
def test_remove_invariants(): | ||
code = dedent( | ||
"""\ | ||
method main() { | ||
while true | ||
// invariants-start | ||
invariant false | ||
invariant true | ||
// invariants-end | ||
{ | ||
} | ||
}""" | ||
) | ||
assert remove_asserts_and_invariants(code) == dedent( | ||
"""\ | ||
method main() { | ||
while true | ||
{ | ||
} | ||
}""" | ||
) | ||
|
||
|
||
def test_remove_all(): | ||
code = dedent( | ||
"""\ | ||
method is_prime(k: int) returns (result: bool) | ||
requires k >= 2 | ||
ensures result ==> forall i :: 2 <= i < k ==> k % i != 0 | ||
ensures !result ==> exists j :: 2 <= j < k && k % j == 0 | ||
{ | ||
var i := 2; | ||
result := true; | ||
while i < k | ||
// invariants-start | ||
invariant 2 <= i <= k | ||
invariant !result ==> exists j :: 2 <= j < i && k % j == 0 | ||
invariant result ==> forall j :: 2 <= j < i ==> k % j != 0 | ||
// invariants-end | ||
{ | ||
if k % i == 0 { | ||
result := false; | ||
} | ||
assert result ==> forall j :: 2 <= j < i ==> k % j != 0; // assert-line | ||
// assert-start | ||
assert !result ==> exists j :: 2 <= j < i && k % j == 0 by { | ||
assert true; | ||
} | ||
// assert-end | ||
i := i + 1; | ||
} | ||
}""" | ||
) | ||
assert remove_asserts_and_invariants(code) == dedent( | ||
"""\ | ||
method is_prime(k: int) returns (result: bool) | ||
requires k >= 2 | ||
ensures result ==> forall i :: 2 <= i < k ==> k % i != 0 | ||
ensures !result ==> exists j :: 2 <= j < k && k % j == 0 | ||
{ | ||
var i := 2; | ||
result := true; | ||
while i < k | ||
{ | ||
if k % i == 0 { | ||
result := false; | ||
} | ||
i := i + 1; | ||
} | ||
}""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters