git @ Cat's Eye Technologies Falderal / f224b33
Make the Falderal-to-Haskell formatter generate something runnable. catseye 10 years ago
3 changed file(s) with 29 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
0 > module Demo where
0 > module Test.Falderal.Demo where
11 > import qualified Test.Falderal.Runner as Runner
22
33 Test.Falderal.Demo
3131 -- POSSIBILITY OF SUCH DAMAGE.
3232 --
3333
34 import System
35
3634 import Test.Falderal.Loader
3735
3836 --
3937 -- Formatting function which compiles a Falderal file to Haskell source.
40 -- XXX this is woefully incomplete right now.
4138 --
4239
43 format ((TestInput text):(ExpectedResult result):rest) =
44 "test " ++ (show text) ++ " " ++ (show result) ++ "\n" ++ (format rest)
45 format ((TestInput text):(ExpectedError result):rest) =
46 "testErr " ++ (show text) ++ " " ++ (show result) ++ "\n" ++ (format rest)
47 format ((TestInput text):foo:rest) =
48 "-- malformed Falderal: no expectation for " ++ (show text) ++ (format (foo:rest))
49 format (_:rest) =
50 format rest
51 format [] =
40 formatBlocks (test@(Test desc text expectation):rest) =
41 " " ++ (show test) ++ ",\n" ++ (formatBlocks rest)
42 formatBlocks (_:rest) =
43 formatBlocks rest
44 formatBlocks [] =
5245 ""
46
47 format lines =
48 let
49 lines' = coalesceLines lines Placeholder
50 blocks = reDescribeBlocks $ convertLinesToBlocks $ lines'
51 in
52 prelude ++ (formatBlocks blocks) ++ postlude
53
54 --
55 -- XXX this hard-codes some stuff, just to see things running
56 --
57
58 prelude = "module GeneratedFalderalTests where\n\
59 \\n\
60 \import Test.Falderal.Loader\n\
61 \import Test.Falderal.Runner\n\
62 \import Test.Falderal.Demo\n\
63 \\n\
64 \testModule = runTests [] (everySecond) [\n"
65
66 postlude = " (Section \"DONE\")\n\
67 \ ]\n"
0 module Test.Falderal.Runner (run) where
0 module Test.Falderal.Runner (run, runTests) where
11
22 --
33 -- Test.Falderal.Runner -- The Falderal Test Runner