test: lake: show module with failed import
This commit is contained in:
parent
99b78bcc23
commit
275af93904
8 changed files with 28 additions and 3 deletions
|
|
@ -60,7 +60,7 @@ building an `Array` product of its direct local imports.
|
|||
-/
|
||||
def Module.recParseImports (mod : Module) : IndexBuildM (Array Module) := do
|
||||
let callstack : CallStack BuildKey ← EquipT.lift <| CycleT.readCallStack
|
||||
let contents ← liftM <| tryCatch (IO.FS.readFile mod.leanFile) (fun err =>
|
||||
let contents ← liftM <| tryCatch (IO.FS.readFile mod.leanFile) fun err =>
|
||||
-- filter out only modules from build key, and remove adjacent duplicates (squeeze),
|
||||
-- since Lake visits multiple nested facets of the same module.
|
||||
let callstack := callstack.filterMap (fun bk =>
|
||||
|
|
@ -69,8 +69,7 @@ def Module.recParseImports (mod : Module) : IndexBuildM (Array Module) := do
|
|||
| _ => .none
|
||||
) |> List.squeeze
|
||||
let breadcrumb := String.intercalate " ▸ " callstack.reverse
|
||||
throw <| IO.userError s!"({breadcrumb}): {err}"
|
||||
)
|
||||
error s!"{breadcrumb}: {err}"
|
||||
let imports ← Lean.parseImports' contents mod.leanFile.toString
|
||||
let mods ← imports.foldlM (init := OrdModuleSet.empty) fun set imp =>
|
||||
findModule? imp.module <&> fun | some mod => set.insert mod | none => set
|
||||
|
|
|
|||
1
src/lake/tests/badImport/.gitignore
vendored
Normal file
1
src/lake/tests/badImport/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
lakefile.olean
|
||||
1
src/lake/tests/badImport/Lib/A.lean
Normal file
1
src/lake/tests/badImport/Lib/A.lean
Normal file
|
|
@ -0,0 +1 @@
|
|||
import Lib.A
|
||||
1
src/lake/tests/badImport/Lib/B.lean
Normal file
1
src/lake/tests/badImport/Lib/B.lean
Normal file
|
|
@ -0,0 +1 @@
|
|||
import Lib.C
|
||||
1
src/lake/tests/badImport/X.lean
Normal file
1
src/lake/tests/badImport/X.lean
Normal file
|
|
@ -0,0 +1 @@
|
|||
import Y
|
||||
1
src/lake/tests/badImport/clean.sh
Executable file
1
src/lake/tests/badImport/clean.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
rm -f lakefile.olean
|
||||
7
src/lake/tests/badImport/lakefile.lean
Normal file
7
src/lake/tests/badImport/lakefile.lean
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import Lake
|
||||
open Lake DSL
|
||||
|
||||
package test
|
||||
|
||||
lean_lib X
|
||||
lean_lib Lib
|
||||
14
src/lake/tests/badImport/test.sh
Executable file
14
src/lake/tests/badImport/test.sh
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euxo pipefail
|
||||
|
||||
LAKE=${LAKE:-../../build/bin/lake}
|
||||
|
||||
./clean.sh
|
||||
|
||||
# Test that failed imports show the module that imported them
|
||||
# https://github.com/leanprover/lake/issues/25
|
||||
# https://github.com/leanprover/lean4/issues/2569
|
||||
# https://github.com/leanprover/lean4/issues/2415
|
||||
|
||||
($LAKE build +X 2>&1 && exit 1 || true) | grep -F "X.lean"
|
||||
($LAKE print-paths Lib.B 2>&1 && exit 1 || true) | grep -F "Lib.B"
|
||||
Loading…
Add table
Reference in a new issue