Skip to content

Commit db76512

Browse files
chore: Update Lean to v4.21.0 (#61)
* chore: Bump toolchain * fix: Use `NeZero` semantics instead of Fin n.succ * chore: Remove deprecated notation * chore: Remove deprecated function * chore: Update lean4-nix * chore: Use Garnix cache for lean4-nix * Test CI * Accept flake config * Update flake.lock * Fix CI --------- Co-authored-by: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com>
1 parent 24cceb6 commit db76512

File tree

11 files changed

+86
-45
lines changed

11 files changed

+86
-45
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v4
28-
- uses: cachix/install-nix-action@v30
28+
- uses: cachix/install-nix-action@v31
2929
with:
3030
nix_path: nixpkgs=channel:nixos-unstable
3131
github_access_token: ${{ secrets.GITHUB_TOKEN }}
32-
- uses: cachix/cachix-action@v14
33-
with:
34-
name: argumentcomputer
35-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
36-
- run: nix build
32+
- run: nix build --accept-flake-config
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ This instance is generic enough that tests like `∀ n, n < 10 → n - 5 < 5` ca
2525
-/
2626
#lspec test "all lt" $ ∀ n, n < 10 → n - 5 < 5
2727

28+
/-
29+
It is also possible to run tests inside the `IO` monad. The purpose of these tests is to plug in
30+
`LSpec` into a testing script for a `lake script`
31+
-/
32+
33+
def fourIO : IO Nat :=
34+
return 4
35+
36+
def fiveIO : IO Nat :=
37+
return 5
38+
39+
def main := do
40+
let four ← fourIO
41+
let five ← fiveIO
42+
lspecIO $
43+
test "fourIO equals 4" (four = 4) $
44+
test "fiveIO equals 5" (five = 5)
45+
46+
#eval main
47+
-- ✓ fourIO equals 4
48+
-- ✓ fiveIO equals 5
49+
-- 0
50+
2851
/-
2952
There are even more ways to invoke LSpec tests (`lspecEachIO` for example) for more intricate moandic
3053
testing

LSpec.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import LSpec.LSpec
22
import LSpec.Instances
3-
import LSpec.SlimCheck.Checkable
3+
import LSpec.SlimCheck

LSpec/LSpec.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ def lspecIO (map : HashMap String (List TestSeq)) (args : List String) : IO UInt
183183
let filteredMap :=
184184
if args.isEmpty then map
185185
else Id.run do
186-
let mut acc := .empty
186+
let mut acc := .emptyWithCapacity args.length
187187
for arg in args do
188188
for (key, tSeq) in map do
189189
if key.startsWith arg then
190190
acc := acc.insert key tSeq
191191
pure acc
192192

193193
-- Accumulate error messages
194-
let mut testsWithErrors : HashMap String (Array String) := .empty
194+
let mut testsWithErrors : HashMap String (Array String) := .emptyWithCapacity map.size
195195
for (key, tSeqs) in filteredMap do
196196
IO.println key
197197
for tSeq in tSeqs do

LSpec/SlimCheck.lean

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

LSpec/SlimCheck/Control/Random.lean

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ def rand (α : Type u) [Random α] [range : DefaultRange α] [RandomGen g] : Ran
8383
def randBound (α : Type u) [Random α] (lo hi : α) [RandomGen g] : RandT g α :=
8484
Random.randomR lo hi
8585

86-
def randFin {n : Nat} [RandomGen g] : RandT g (Fin n.succ) :=
87-
λ ⟨g⟩ => randNat g 0 n.succ |>.map (Fin.ofNat' _) ULift.up
86+
def randFin {n : Nat} [NeZero n] [RandomGen g] : RandT g (Fin n) :=
87+
λ ⟨g⟩ =>
88+
let (x, gen) := randNat g 0 n.succ
89+
(Fin.ofNat n x, ULift.up gen)
8890

8991
instance : Random Bool where
9092
randomR := fun lo hi g =>
@@ -99,10 +101,10 @@ instance : Random Nat where
99101
let (n, g') := randNat g.down lo hi
100102
(n, .up g')
101103

102-
instance {n : Nat} : Random (Fin n.succ) where
104+
instance {n : Nat} [NeZero n] : Random (Fin n) where
103105
randomR := fun lo hi g =>
104-
let (n, g') := randNat g.down lo hi
105-
(.ofNat' _ n, .up g')
106+
let (x, g') := randNat g.down lo hi
107+
(Fin.ofNat n x, .up g')
106108

107109
instance : Random Int where
108110
randomR := fun lo hi g =>

LSpec/SlimCheck/Sampleable.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ instance Nat.shrinkable : Shrinkable Nat where
126126
shrink := Nat.shrink
127127

128128
/-- `Fin.shrink` works like `Nat.shrink` but instead operates on `Fin`. -/
129-
partial def Fin.shrink {n : Nat} (m : Fin n.succ) : List (Fin n.succ) :=
129+
partial def Fin.shrink {n : Nat} [NeZero n] (m : Fin n) : List (Fin n) :=
130130
if 0 < m then
131131
let m := m / 2
132132
let rest := shrink m
133133
m :: rest
134134
else
135135
[]
136136

137-
instance Fin.shrinkable {n : Nat} : Shrinkable (Fin n.succ) where
137+
instance Fin.shrinkable {n : Nat} [NeZero n] : Shrinkable (Fin n) where
138138
shrink := Fin.shrink
139139

140140
local instance Int_sizeOfAbs : SizeOf Int := ⟨Int.natAbs⟩
@@ -162,8 +162,8 @@ open Gen SampleableExt
162162
instance Nat.sampleableExt : SampleableExt Nat :=
163163
mkSelfContained (do choose Nat 0 (← getSize))
164164

165-
instance Fin.sampleableExt {n : Nat} : SampleableExt (Fin (n.succ)) :=
166-
mkSelfContained (do choose (Fin n.succ) (Fin.ofNat' _ 0) (Fin.ofNat' _ (← getSize)))
165+
instance Fin.sampleableExt {n : Nat} [NeZero n] : SampleableExt (Fin n) :=
166+
mkSelfContained (do choose (Fin n) (Fin.ofNat n 0) (Fin.ofNat n (← getSize)))
167167

168168
instance Int.sampleableExt : SampleableExt Int :=
169169
mkSelfContained (do choose Int (-(← getSize)) (← getSize))

flake.lock

Lines changed: 33 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
description = "LSpec Nix Flake";
33

4+
nixConfig = {
5+
extra-substituters = [
6+
"https://cache.garnix.io"
7+
];
8+
extra-trusted-public-keys = [
9+
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
10+
];
11+
};
12+
413
inputs = {
514
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
615
flake-parts.url = "github:hercules-ci/flake-parts";
7-
lean4-nix = {
8-
url = "github:argumentcomputer/lean4-nix";
9-
inputs.nixpkgs.follows = "nixpkgs";
10-
};
16+
lean4-nix.url = "github:lenianiva/lean4-nix";
1117
};
1218

1319
outputs = inputs @ {

0 commit comments

Comments
 (0)