{"id":13993108,"url":"https://github.com/argumentcomputer/LSpec","last_synced_at":"2025-07-22T17:30:41.447Z","repository":{"id":37499339,"uuid":"491653591","full_name":"argumentcomputer/LSpec","owner":"argumentcomputer","description":"A Testing Framework for Lean","archived":false,"fork":false,"pushed_at":"2025-03-13T16:05:03.000Z","size":116,"stargazers_count":51,"open_issues_count":3,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-13T16:29:13.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/argumentcomputer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-12T20:09:28.000Z","updated_at":"2025-03-13T16:05:05.000Z","dependencies_parsed_at":"2024-11-29T14:32:03.096Z","dependency_job_id":"e4971a5b-9f6b-4592-8a58-f9987c954c99","html_url":"https://github.com/argumentcomputer/LSpec","commit_stats":null,"previous_names":["argumentcomputer/lspec"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/argumentcomputer/LSpec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/argumentcomputer%2FLSpec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/argumentcomputer%2FLSpec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/argumentcomputer%2FLSpec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/argumentcomputer%2FLSpec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/argumentcomputer","download_url":"https://codeload.github.com/argumentcomputer/LSpec/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/argumentcomputer%2FLSpec/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266538499,"owners_count":23944830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:02:14.059Z","updated_at":"2025-07-22T17:30:41.432Z","avatar_url":"https://github.com/argumentcomputer.png","language":"Lean","funding_links":[],"categories":["Lean"],"sub_categories":[],"readme":"# LSpec\n\nA testing framework for Lean 4, inspired by Haskell's [Hspec](https://hspec.github.io/) package.\n\n## Usage\n\n### Composing tests\n\nSequences of tests are represented by the `TestSeq` datatype.\nIn order to instantiate terms of `TestSeq`, use the `test` helper function:\n\n```lean\n#check\n  test \"Nat equality\" (4 = 4) $\n  test \"Nat inequality\" (4 ≠ 5)\n-- test \"Nat equality\" (4 = 4) (test \"Nat inequality\" (4 ≠ 5)) : TestSeq\n```\n\n`test` consumes a description a proposition and a next test\nThe proposition, however, must have its own instance of `Testable`.\n\nYou can also collect `TestSeq` into conceptual test groups by using the\nhelper function `group`:\n\n```lean\n#check\n  test \"Nat equality\" (42 = 42) $\n  group \"manual group\" $\n    test \"Nat equality inside group\" (4 = 4)\n```\n\n### The `Testable` class\n\n`Testable` is how Lean is instructed to decide whether certain propositions are resolved as `true` or `false`.\n\nThis is an example of a simple instance for decidability of equalities:\n\n```lean\ninstance (x y : α) [DecidableEq α] [Repr α] : Testable (x = y) :=\n  if h : x = y then\n    .isTrue h\n  else\n    .isFalse h s!\"Not equal: {repr x} and {repr y}\"\n```\n\nThe custom failure message is optional.\n\nThere are more examples of `Testable` instances in [LSpec/Instances.lean](LSpec/Instances.lean).\n\nThe user is, of course, free to provide their own instances.\n\n### Actually running the tests\n\n#### The `#lspec` command\n\nThe `#lspec` command allows you to test interactively in a file.\n\nExamples:\n\n```lean\n#lspec\n  test \"four equals four\" (4 = 4) $\n  test \"five equals five\" (5 = 5)\n-- ✓ four equals four\n-- ✓ five equals five\n```\n\nAn important note is that a failing test will raise an error, interrupting the building process.\n\n#### The `lspecIO` function\n\n`lspecIO` is meant to be used in files to be compiled and integrated in a testing infrastructure, as shown below.\n\n```lean\ndef aaSuite := [\n    test \"four equals four\" (4 = 4)\n  ]\n\ndef bbSuite := [\n    test \"five equals five\" (5 = 5)\n  ]\n\ndef main := lspecIO $ .ofList [\n    (\"aa\", aaSuite),\n    (\"bb\", bbSuite)\n  ]\n```\n\nOnce such `main` function is defined, its respective executable can be tagged as the `@[test_driver]` in the lakefile.\nFor further information, inspect the docstring of `lspecIO`.\n\n## Integration with `SlimCheck`\n\nThere are 3 main typeclasses associated with any  `SlimCheck` test:\n\n* `Shrinkable` : The typeclass that takes a type `a : α` and returns a `List α` of elements which\n  should be thought of as being \"smaller\" than `a` (in some sense dependent on the type `α` being \n  considered).\n* `SampleableExt` : The typeclass of a . \n  This is roughly equivalent to `QuickCheck`'s `Arbitrary` typeclass. \n* `Checkable` : The property to be checked by `SlimCheck` must have a `Checkable` instance.\n\nIn order to use `SlimCheck` tests for custom data types, the user will need to implement \ninstances of the typeclasses `Shrinkable` and `SampleableExt` for the custom types appearing\nin the properties being tested.\n\nThe module [LSpec.SlimCheck.Checkable](LSpec/SlimCheck/Checkable.lean) contains may of \nthe useful definitions and instances that can be used to derive a Checkable instance \nfor a wide variety of properties given just the instances above. If all else fails, the user can \nalso define the Checkable instance by hand. \n\nOnce this is done a `Slimcheck` test is evaluated in a similar way to \n`LSpec` tests: \n\n```lean\n#lspec check \"add_comm\" $ ∀ n m : Nat, n + m = m + n\n\n#lspec check \"add_comm\" $ ∀ n m : Nat, n + m = m + m\n-- × add_comm\n\n-- ===================\n-- Found problems!\n-- n := 1\n-- m := 0\n-- issue: 1 = 0 does not hold\n-- (0 shrinks)\n-- -------------------\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fargumentcomputer%2FLSpec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fargumentcomputer%2FLSpec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fargumentcomputer%2FLSpec/lists"}