0 | module Evince.Spec
 1 |
 2 | import Language.Reflection
 3 | import Language.Reflection.TTImp
 4 | import Evince.Core
 5 |
 6 | %language ElabReflection
 7 |
 8 | ||| Group related specs under a label.
 9 | export
10 | describe : String -> Spec a () -> Spec a ()
11 | describe label body = MkSpec [< Describe label (getSpecTrees body)] ()
12 |
13 | ||| Alias for `describe` — use with "when"/"with" phrasing.
14 | export
15 | context : String -> Spec a () -> Spec a ()
16 | context = describe
17 |
18 | ||| Define a test case with pure expectations.
19 | export
20 | it : String -> TestResult () -> Spec a ()
21 | it label result = MkSpec [< It label Nothing (\_ => pure result)] ()
22 |
23 | ||| Define a test case with IO-based expectations.
24 | export
25 | itIO : String -> IO (TestResult ()) -> Spec a ()
26 | itIO label action = MkSpec [< It label Nothing (\_ => action)] ()
27 |
28 | ||| Define a test case that receives the resource.
29 | export
30 | itWith : String -> (a -> TestResult ()) -> Spec a ()
31 | itWith label f = MkSpec [< It label Nothing (\res => pure (f res))] ()
32 |
33 | ||| Define an IO test case that receives the resource.
34 | export
35 | itIOWith : String -> (a -> IO (TestResult ())) -> Spec a ()
36 | itIOWith label f = MkSpec [< It label Nothing f] ()
37 |
38 | ||| Define a test with source location captured at the call site.
39 | ||| Pass a dummy quasiquoted value as the first argument:
40 | |||   itLoc `(()) "test name" $ expectation
41 | export
42 | %macro
43 | itLoc : TTImp -> String -> TestResult () -> Elab (Spec a ())
44 | itLoc t label result = do
45 |   let loc = fcToSrcLoc (getFC t)
46 |   pure $ MkSpec [< It label (Just loc) (\_ => pure result)] ()
47 |
48 | ||| Define an IO test with source location captured at the call site.
49 | |||   itIOLoc `(()) "test name" $ ioAction
50 | export
51 | %macro
52 | itIOLoc : TTImp -> String -> IO (TestResult ()) -> Elab (Spec a ())
53 | itIOLoc t label action = do
54 |   let loc = fcToSrcLoc (getFC t)
55 |   pure $ MkSpec [< It label (Just loc) (\_ => action)] ()
56 |
57 | ||| Mark a test as pending — the body is ignored and not executed.
58 | export
59 | xit : String -> TestResult () -> Spec a ()
60 | xit label _ = MkSpec [< Pending label Nothing] ()
61 |
62 | ||| Mark an entire group as pending.
63 | export
64 | xdescribe : String -> Spec a () -> Spec a ()
65 | xdescribe label _ = MkSpec [< Pending label Nothing] ()
66 |
67 | ||| Alias for `xdescribe`.
68 | export
69 | xcontext : String -> Spec a () -> Spec a ()
70 | xcontext = xdescribe
71 |
72 | ||| Focus a test — when any focused specs exist, only focused ones run.
73 | export
74 | fit : String -> TestResult () -> Spec a ()
75 | fit label result = MkSpec [< Focused (It label Nothing (\_ => pure result))] ()
76 |
77 | ||| Focus an entire group.
78 | export
79 | fdescribe : String -> Spec a () -> Spec a ()
80 | fdescribe label body = MkSpec [< Focused (Describe label (getSpecTrees body))] ()
81 |
82 | ||| Alias for `fdescribe`.
83 | export
84 | fcontext : String -> Spec a () -> Spec a ()
85 | fcontext = fdescribe
86 |