Skip to content

Commit 41c8a9b

Browse files
chore: Switch to module system (#74)
* chore: Switch to module system * Don't use modules in examples
1 parent b76de46 commit 41c8a9b

9 files changed

Lines changed: 40 additions & 17 deletions

File tree

LSpec.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import LSpec.LSpec
2-
import LSpec.Instances
3-
import LSpec.SlimCheck
1+
module
2+
public import LSpec.LSpec
3+
public import LSpec.Instances
4+
public import LSpec.SlimCheck

LSpec/Instances.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import LSpec.LSpec
1+
module
2+
public import LSpec.LSpec
23

34
/-!
45
# Testable Instances
@@ -16,6 +17,7 @@ LSpec to test equality, inequality, and bounded quantification directly.
1617
-/
1718

1819
namespace LSpec
20+
public section
1921

2022
/-- Testable instance for decidable equality. -/
2123
instance (priority := 50) (x y : α) [DecidableEq α] [Repr α] : Testable (x = y) :=
@@ -85,4 +87,5 @@ instance Nat.Testable_forall_lt
8587
| .isFalse h failedAt totalTests msg => .isFalse (λ h' => h λ n hn => h' _ (Nat.le_succ_of_le hn)) failedAt totalTests msg
8688
| .isFailure failedAt totalTests msg => .isFailure failedAt totalTests msg
8789

90+
end
8891
end LSpec

LSpec/LSpec.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Lean
2-
import LSpec.SlimCheck.Checkable
1+
module
2+
public import LSpec.SlimCheck.Checkable
33

44
/-!
55
# The core `LSpec` framework
@@ -64,7 +64,7 @@ Use `check` and `checkIO` (without apostrophe) for simpler output.
6464
-/
6565

6666
namespace LSpec
67-
67+
public section
6868
/--
6969
The main typeclass of propositions that can be tested by `LSpec`.
7070
@@ -585,4 +585,5 @@ def lspecEachIO (l : List α) (f : α → IO TestSeq) : IO UInt32 := do
585585
| (false, msg) => IO.eprintln msg; pure false
586586
if success then return 0 else return 1
587587

588+
end
588589
end LSpec

LSpec/SlimCheck.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import LSpec.SlimCheck.Gen
2-
import LSpec.SlimCheck.Checkable
3-
import LSpec.SlimCheck.Sampleable
1+
module
2+
public import LSpec.SlimCheck.Gen
3+
public import LSpec.SlimCheck.Checkable
4+
public import LSpec.SlimCheck.Sampleable

LSpec/SlimCheck/Checkable.lean

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Henrik Böving, Simon Hudon
55
-/
66

7-
import LSpec.SlimCheck.Sampleable
8-
import Lean
7+
module
8+
public import LSpec.SlimCheck.Sampleable
9+
public import Lean.Elab.Tactic.Basic
10+
meta import Lean.Elab.Tactic.Basic
911

1012
/-!
1113
# `Checkable` Class
@@ -61,7 +63,7 @@ random testing
6163
-/
6264

6365
namespace SlimCheck
64-
66+
public section
6567
/-- Result of trying to disprove `p`
6668
The constructors are:
6769
* `success : (PSum Unit p) → TestResult p`
@@ -127,6 +129,7 @@ instance (priority := low) : PrintableProp p where
127129
class Checkable (p : Prop) where
128130
run (cfg : Configuration) (minimize : Bool) : Gen (TestResult p)
129131

132+
@[expose]
130133
def NamedBinder (_n : String) (p : Prop) : Prop := p
131134

132135
namespace TestResult
@@ -458,7 +461,7 @@ open Lean
458461

459462
/-- Traverse the syntax of a proposition to find universal quantifiers
460463
quantifiers and add `NamedBinder` annotations next to them. -/
461-
partial def addDecorations (e : Expr) : Expr :=
464+
meta partial def addDecorations (e : Expr) : Expr :=
462465
e.replace fun expr => match expr with
463466
| Expr.forallE name type body data =>
464467
let n := name.toString
@@ -507,4 +510,5 @@ def Checkable.check (p : Prop) (cfg : Configuration := {})
507510
-- #eval Checkable.check (∀ (x : (Nat × Nat)), x.fst - x.snd - 10 = x.snd - x.fst - 10) Configuration.verbose
508511
-- #eval Checkable.check (∀ (x : Nat) (h : 10 < x), 5 < x) Configuration.verbose
509512

513+
end
510514
end SlimCheck

LSpec/SlimCheck/Control/DefaultRange.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2022 Hanting Zhang. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Hanting Zhang
55
-/
6+
module
67

78
/-!
89
# Bounded and DefaultRange classes
@@ -29,6 +30,7 @@ Lean developers, please forgive us.
2930
-/
3031

3132
namespace SlimCheck
33+
public section
3234

3335
class Bounded (α : Type u) where
3436
lo : α
@@ -58,4 +60,5 @@ instance : DefaultRange Int where
5860
lo := - Int.ofNat (USize.size / 2)
5961
hi := Int.ofNat (USize.size / 2 - 1)
6062

63+
end
6164
end SlimCheck

LSpec/SlimCheck/Control/Random.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Henrik Böving
55
-/
6-
import LSpec.SlimCheck.Control.DefaultRange
6+
module
7+
public import LSpec.SlimCheck.Control.DefaultRange
78

89
/-!
910
# Rand Monad and Random Class
@@ -29,6 +30,7 @@ defining objects that can be created randomly.
2930
-/
3031

3132
namespace SlimCheck
33+
public section
3234

3335
/-- A monad to generate random objects using the generic generator type `g` -/
3436
abbrev RandT (g : Type) := StateM (ULift g)
@@ -133,4 +135,5 @@ def IO.runRand (cmd : Rand α) : BaseIO α := do
133135
def IO.runRandWith (seed : Nat) (cmd : Rand α) : BaseIO α := do
134136
pure $ (cmd.run (ULift.up $ mkStdGen seed)).1
135137

138+
end
136139
end SlimCheck

LSpec/SlimCheck/Gen.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Copyright (c) 2021 Henrik Böving. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Henrik Böving, Simon Hudon
55
-/
6-
import LSpec.SlimCheck.Control.Random
6+
module
7+
public import LSpec.SlimCheck.Control.Random
78

89
/-!
910
# `Gen` Monad
@@ -19,6 +20,7 @@ random testing
1920
-/
2021

2122
namespace SlimCheck
23+
public section
2224

2325
open Random
2426

@@ -118,4 +120,5 @@ end Gen
118120
def Gen.run (x : Gen α) (size : Nat) : BaseIO α :=
119121
IO.runRand $ ReaderT.run x ⟨size⟩
120122

123+
end
121124
end SlimCheck

LSpec/SlimCheck/Sampleable.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Henrik Böving, Simon Hudon
55
-/
6-
import LSpec.SlimCheck.Gen
6+
module
7+
public import LSpec.SlimCheck.Gen
78

89
/-!
910
# `SampleableExt` Class
@@ -63,6 +64,7 @@ random testing
6364
-/
6465

6566
namespace SlimCheck
67+
public section
6668

6769
open Random
6870

@@ -205,6 +207,7 @@ instance Prop.sampleableExt : SampleableExt Prop where
205207
end Samplers
206208

207209
/-- An annotation for values that should never get shrinked. -/
210+
@[expose]
208211
def NoShrink (α : Type u) := α
209212

210213
namespace NoShrink
@@ -223,4 +226,5 @@ instance sampleableExt [SampleableExt α] [Repr α] : SampleableExt (NoShrink α
223226

224227
end NoShrink
225228

229+
end
226230
end SlimCheck

0 commit comments

Comments
 (0)