test: reimplement package tests using Lake

This commit is contained in:
Sebastian Ullrich 2022-02-08 11:20:50 +01:00 committed by Leonardo de Moura
parent 15e6dd262d
commit 8cbd7ccf09
38 changed files with 250 additions and 3 deletions

View file

@ -147,7 +147,7 @@ rec {
ln -sf ${lean-all}/* .
'';
buildPhase = ''
ctest --output-on-failure -E 'leancomptest_(doc_example|foreign)|laketest' -j$NIX_BUILD_CORES
ctest --output-on-failure -E 'leancomptest_(doc_example|foreign)|laketest|leanpkgtest' -j$NIX_BUILD_CORES
'';
installPhase = ''
touch $out

View file

@ -126,6 +126,17 @@ FOREACH(T ${LEANT0TESTS})
COMMAND bash -c "${TEST_VARS} ./test_single.sh ${T_NAME}")
ENDFOREACH(T)
# LEAN PACKAGE TESTS
file(GLOB LEANPKGTESTS "${LEAN_SOURCE_DIR}/../tests/pkg/*")
FOREACH(T ${LEANPKGTESTS})
if(IS_DIRECTORY ${T})
GET_FILENAME_COMPONENT(T_NAME ${T} NAME)
add_test(NAME "leanpkgtest_${T_NAME}"
WORKING_DIRECTORY "${T}"
COMMAND bash -c "${TEST_VARS} ./test.sh")
endif()
ENDFOREACH(T)
# LEAN SERVER TESTS
file(GLOB LEANTESTS "${LEAN_SOURCE_DIR}/../tests/lean/server/*.lean")
FOREACH(T ${LEANTESTS})
@ -149,7 +160,6 @@ FOREACH(T ${LEANTESTS})
ENDFOREACH(T)
# Create a lake test for each subdirectory of `lake/examples` which contains a `test.sh` file.
# We skip the subdirectories `lean_packages` and `bootstrap` since `lake/examples/Makefile` does not consider them either.
file(GLOB_RECURSE LEANLAKETESTS "${LEAN_SOURCE_DIR}/lake/examples/test.sh")
FOREACH(T ${LEANLAKETESTS})
if(NOT T MATCHES ".*lean_packages.*")

1
tests/pkg/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

View file

@ -0,0 +1 @@
import UserAttr.Tst

View file

@ -0,0 +1,4 @@
import UserAttr.BlaAttr
@[bar] def f (x : Nat) := x + 2
@[bar] def g (x : Nat) := x + 1

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_attr where
defaultFacet := PackageFacet.oleans

4
tests/pkg/builtin_attr/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build

View file

@ -0,0 +1 @@
import UserDeriving.Tst

View file

@ -0,0 +1,15 @@
import Lean
class Simple (α : Type u) where
val : α
open Lean
open Lean.Elab
open Lean.Elab.Command
def mkSimpleHandler (declNames : Array Name) : CommandElabM Bool := do
dbg_trace ">> mkSimpleHandler {declNames}"
-- TODO: see examples at src/Lean/Elab/Deriving
return true
initialize
registerBuiltinDerivingHandler ``Simple mkSimpleHandler

View file

@ -0,0 +1,6 @@
import UserDeriving.Simple
inductive Foo where
| mk₁
| mk₂
deriving Simple

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_deriving where
defaultFacet := PackageFacet.oleans

4
tests/pkg/deriving/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build

5
tests/pkg/prv/Prv.lean Normal file
View file

@ -0,0 +1,5 @@
import Prv.Foo
#check { name := "leo", val := 15 : Foo }
#check { name := "leo", val := 15 : Foo }.name
#check { name := "leo", val := 15 : Foo }.val -- Error

View file

@ -0,0 +1,6 @@
structure Foo where
private val : Nat
name : String
#check { name := "leo", val := 15 : Foo }
#check { name := "leo", val := 15 : Foo }.val

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package prv where
defaultFacet := PackageFacet.oleans

4
tests/pkg/prv/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build 2>&1 | grep 'error: field.*private'

View file

@ -0,0 +1,12 @@
import UserAttr.Tst
open Lean
def tst : MetaM Unit := do
let env ← getEnv
assert! (blaAttr.hasTag env `f)
assert! (blaAttr.hasTag env `g)
assert! !(blaAttr.hasTag env `id)
pure ()
#eval tst

View file

@ -0,0 +1,5 @@
import Lean
open Lean
initialize blaAttr : TagAttribute ← registerTagAttribute `bla "simple user defined attribute"

View file

@ -0,0 +1,4 @@
import UserAttr.BlaAttr
@[bla] def f (x : Nat) := x + 2
@[bla] def g (x : Nat) := x + 1

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_attr where
defaultFacet := PackageFacet.oleans

4
tests/pkg/user_attr/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build

View file

@ -12,5 +12,5 @@ def tst : MetaM Unit := do
#eval tst
unsafe def main : IO Unit := do
initSearchPath (← Lean.findSysroot?) ["build"]
initSearchPath (← Lean.findSysroot?) ["build/lib"]
withImportModules [{ module := `UserAttr.Tst : Import }] {} 0 fun env => pure ()

View file

@ -0,0 +1,5 @@
import Lean
open Lean
initialize blaAttr : TagAttribute ← registerTagAttribute `bla "simple user defined attribute"

View file

@ -0,0 +1,4 @@
import UserAttr.BlaAttr
@[bla] def f (x : Nat) := x + 2
@[bla] def g (x : Nat) := x + 1

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_attr where
supportInterpreter := true

View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build && ./build/bin/user_attr

View file

@ -0,0 +1,5 @@
import UserExt.Tst1
import UserExt.Tst2
show_foo_set
show_bla_set

View file

@ -0,0 +1,23 @@
import Lean
open Lean
initialize blaExtension : SimplePersistentEnvExtension Name NameSet ←
registerSimplePersistentEnvExtension {
name := `blaExt
addEntryFn := NameSet.insert
addImportedFn := fun es => mkStateFromImportedEntries NameSet.insert {} es
}
syntax (name := insertBla) "insert_bla " ident : command
syntax (name := showBla) "show_bla_set" : command
open Lean.Elab
open Lean.Elab.Command
@[commandElab insertBla] def elabInsertBla : CommandElab := fun stx => do
IO.println s!"inserting {stx[1].getId}"
modifyEnv fun env => blaExtension.addEntry env stx[1].getId
@[commandElab showBla] def elabShowBla : CommandElab := fun stx => do
IO.println s!"bla set: {blaExtension.getState (← getEnv) |>.toList}"

View file

@ -0,0 +1,26 @@
import Lean
open Lean
initialize fooExtension : SimplePersistentEnvExtension Name NameSet ←
registerSimplePersistentEnvExtension {
name := `fooExt
addEntryFn := NameSet.insert
addImportedFn := fun es => mkStateFromImportedEntries NameSet.insert {} es
}
initialize registerTraceClass `myDebug
syntax (name := insertFoo) "insert_foo " ident : command
syntax (name := showFoo) "show_foo_set" : command
open Lean.Elab
open Lean.Elab.Command
@[commandElab insertFoo] def elabInsertFoo : CommandElab := fun stx => do
trace[myDebug] "testing trace message at insert foo '{stx}'"
IO.println s!"inserting {stx[1].getId}"
modifyEnv fun env => fooExtension.addEntry env stx[1].getId
@[commandElab showFoo] def elabShowFoo : CommandElab := fun stx => do
IO.println s!"foo set: {fooExtension.getState (← getEnv) |>.toList}"

View file

@ -0,0 +1,14 @@
import UserExt.FooExt
import UserExt.BlaExt
set_option trace.myDebug true
insert_foo hello
set_option trace.myDebug false
insert_foo world
show_foo_set
insert_bla abc
show_bla_set

View file

@ -0,0 +1,6 @@
import UserExt.BlaExt
import UserExt.FooExt
insert_foo test
insert_bla defg
insert_bla hij

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_ext where
defaultFacet := PackageFacet.oleans

4
tests/pkg/user_ext/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build 2>&1 | grep 'world, hello, test'

View file

@ -0,0 +1,20 @@
import UserOpt.Opts
open Lean
def tst1 : MetaM Unit := do
assert! !(myBoolOpt.get (← getOptions))
assert! myNatOpt.get (← getOptions) == 100
pure ()
#eval tst1
set_option myBoolOpt true
set_option myNatOpt 4
def tst2 : MetaM Unit := do
assert! myBoolOpt.get (← getOptions)
assert! myNatOpt.get (← getOptions) == 4
pure ()
#eval tst2

View file

@ -0,0 +1,11 @@
import Lean
register_option myBoolOpt : Bool := {
defValue := false
descr := "my Boolean option"
}
register_option myNatOpt : Nat := {
defValue := 100
descr := "my Nat option"
}

View file

@ -0,0 +1,5 @@
import Lake
open System Lake DSL
package user_opt where
defaultFacet := PackageFacet.oleans

4
tests/pkg/user_opt/test.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf build
lake build