test(frontend): Add scope `open` test
This commit is contained in:
parent
1dceb5428e
commit
0cfd73e44e
|
@ -40,6 +40,7 @@ def stxByteRange (stx : Syntax) : String.Pos × String.Pos :=
|
||||||
abbrev FrontendM := Elab.Frontend.FrontendM
|
abbrev FrontendM := Elab.Frontend.FrontendM
|
||||||
|
|
||||||
structure CompilationStep where
|
structure CompilationStep where
|
||||||
|
scope : Elab.Command.Scope
|
||||||
fileName : String
|
fileName : String
|
||||||
fileMap : FileMap
|
fileMap : FileMap
|
||||||
src : Substring
|
src : Substring
|
||||||
|
@ -74,7 +75,7 @@ def processOneCommand: FrontendM (CompilationStep × Bool) := do
|
||||||
let msgs := s'.messages.toList.drop s.messages.toList.length
|
let msgs := s'.messages.toList.drop s.messages.toList.length
|
||||||
let trees := s'.infoState.trees.drop s.infoState.trees.size
|
let trees := s'.infoState.trees.drop s.infoState.trees.size
|
||||||
let ⟨_, fileName, fileMap⟩ := (← read).inputCtx
|
let ⟨_, fileName, fileMap⟩ := (← read).inputCtx
|
||||||
return ({ fileName, fileMap, src, stx, before, after, msgs, trees }, done)
|
return ({ scope := s.scopes.head!, fileName, fileMap, src, stx, before, after, msgs, trees }, done)
|
||||||
|
|
||||||
partial def mapCompilationSteps { α } (f: CompilationStep → IO α) : FrontendM (List α) := do
|
partial def mapCompilationSteps { α } (f: CompilationStep → IO α) : FrontendM (List α) := do
|
||||||
let (cmd, done) ← processOneCommand
|
let (cmd, done) ← processOneCommand
|
||||||
|
|
|
@ -1,11 +1,27 @@
|
||||||
import LSpec
|
|
||||||
import Pantograph
|
import Pantograph
|
||||||
import Repl
|
import Repl
|
||||||
import Test.Common
|
import Test.Common
|
||||||
|
|
||||||
|
import LSpec
|
||||||
|
|
||||||
open Lean Pantograph
|
open Lean Pantograph
|
||||||
namespace Pantograph.Test.Frontend
|
namespace Pantograph.Test.Frontend
|
||||||
|
|
||||||
|
def runFrontend { α } (source: String) (f : Frontend.CompilationStep → IO α) : MetaM (List α) := do
|
||||||
|
let filename := "<anonymous>"
|
||||||
|
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
||||||
|
let m := Frontend.mapCompilationSteps f
|
||||||
|
m.run context |>.run' state
|
||||||
|
|
||||||
|
def test_open : TestT MetaM Unit := do
|
||||||
|
let sketch := "
|
||||||
|
open Nat
|
||||||
|
example : ∀ (n m: Nat), n + m = m + n := by
|
||||||
|
apply add_comm
|
||||||
|
"
|
||||||
|
let errors ← runFrontend sketch λ step => step.msgs.mapM (·.toString)
|
||||||
|
checkEq "errors" errors [[]]
|
||||||
|
|
||||||
def collectSorrysFromSource (source: String) (options : Frontend.GoalCollectionOptions := {})
|
def collectSorrysFromSource (source: String) (options : Frontend.GoalCollectionOptions := {})
|
||||||
: MetaM (List GoalState) := do
|
: MetaM (List GoalState) := do
|
||||||
let filename := "<anonymous>"
|
let filename := "<anonymous>"
|
||||||
|
@ -233,6 +249,7 @@ theorem mystery [SizeOf α] (as : List α) (i : Fin as.length) : sizeOf (as.get
|
||||||
|
|
||||||
def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
let tests := [
|
let tests := [
|
||||||
|
("open", test_open),
|
||||||
("multiple_sorrys_in_proof", test_multiple_sorrys_in_proof),
|
("multiple_sorrys_in_proof", test_multiple_sorrys_in_proof),
|
||||||
("sorry_in_middle", test_sorry_in_middle),
|
("sorry_in_middle", test_sorry_in_middle),
|
||||||
("sorry_in_induction", test_sorry_in_induction),
|
("sorry_in_induction", test_sorry_in_induction),
|
||||||
|
|
Loading…
Reference in New Issue