6 | import public Control.Monad.Either
9 | import Language.Reflection
10 | import Language.Reflection.TTImp
12 | %language ElabReflection
16 | TestFunc : Type -> Type
17 | TestFunc = EitherT String IO
25 | description : String
28 | red : String -> String
29 | red s = show $
colored Red s
40 | test : (description : String) -> (run : TestFunc ()) -> Test
44 | record Location where
50 | emptyLoc = Loc EmptyFC
59 | here : TTImp -> Elab Location
60 | here ttimp = pure $
Loc $
getFC ttimp
62 | getFile : OriginDesc -> String
63 | getFile (PhysicalIdrSrc (MkMI path)) = showSep "/" (reverse path) ++ ".idr"
64 | getFile (PhysicalPkgSrc fname) = fname
65 | getFile (Virtual _) = "virtual"
67 | formatFC : FC -> String
68 | formatFC (MkFC origin (startLn, startCol) (endLn, endCol)) = " at \{getFile origin}:\{show startLn}:\{show startCol}--\{show endLn}:\{show endCol}"
69 | formatFC (MkVirtualFC origin (startLn, startCol) (endLn, endCol)) = " at \{getFile origin}:\{show startLn}:\{show startCol}--\{show endLn}:\{show endCol}"
70 | formatFC EmptyFC = ""
73 | formatLoc : Location -> String
74 | formatLoc loc = formatFC loc.inner
82 | {default emptyLoc loc : Location} ->
83 | (left, right : a) ->
85 | assertEq left right =
86 | unless (left == right) $
88 | red "assertEq" ++ " failed\{formatLoc loc}",
89 | " left `" ++ red (show left) ++ "`",
90 | " right `" ++ red (show right) ++ "`"
100 | {default emptyLoc loc : Location} ->
101 | (left, right : a) ->
103 | assertNotEq left right =
104 | if left == right then
105 | let msg = unlines [
106 | red "assertNotEq" ++ " failed\{formatLoc loc}:",
107 | " left `" ++ red (show left) ++ "`",
108 | " right `" ++ red (show right) ++ "`"
119 | {default emptyLoc loc : Location} ->
124 | let msg = red "assert" ++ "failed\{formatLoc loc}"
131 | throw : (msg : String) -> TestFunc a