Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexf91/ltest
A unit testing framework for Lean 4
https://github.com/alexf91/ltest
lean lean4 unit-testing unittest
Last synced: 3 days ago
JSON representation
A unit testing framework for Lean 4
- Host: GitHub
- URL: https://github.com/alexf91/ltest
- Owner: alexf91
- License: apache-2.0
- Created: 2022-03-11T05:21:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-05T04:19:00.000Z (about 1 year ago)
- Last Synced: 2024-11-01T21:42:16.541Z (about 2 months ago)
- Topics: lean, lean4, unit-testing, unittest
- Language: Lean
- Homepage:
- Size: 151 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
**WARNING: This is work in progress**
# Fixture-based test framework for Lean 4
`LTest` uses macros to define testcases and fixtures for testing IO functions in Lean 4.
It is heavily inspired by [`pytest`](https://docs.pytest.org/) and [`rstest`](https://docs.rs/rstest).## Fixtures
Fixtures are structures with a default state, a setup function and a teardown function.
They can depend on other fixtures. The value of dependencies is available in the setup function.The following example defines a fixture `NatFixture` with a state of type `Nat` and a value of type `Nat`.
It depends on `AnotherFixture`.```Lean
fixture NatFixture Nat Nat requires (n : AnotherFixture) where
default := 0
setup := do
-- Do something with n
return 0
teardown := do return
```In the `setup` function, the state is set to `default`. It can then be changed and queried
with the functions of the `StateM` monad (`set`, `get`, ...).## Testcases
Testcases are essentially functions of type `IO Unit`, but they can depend
on fixtures. The value of a setup function is available in a testcases and their
teardown-function is executed when the test finishes.```Lean
testcase testSomething requires (a : FixtureA) (b : FixtureB) := do
-- Do someting with a and b
return
```## Running Tests
For now, testsuites are compiled and executed as regular programs.
The `main` function is created with the `#LTestMain` command, which has to be called exactly once.
See the `examples` directory for more information.```Lean
import LTest#LTestMain
```