git @ Cat's Eye Technologies Falderal / 607d6b8
Give tests w/empty literal text the previous sensible literal text. Chris Pressey 10 years ago
3 changed file(s) with 63 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
111111 | 01
112112 | 10
113113 = [False,False,True,True]
114
115 If we have a set of tests where the tests after the first one have no
116 descriptions of their own, we can take this to suggest they are all
117 testing the same thing. In this case, the literal text that is displayed
118 when any of them fails is the text that comes before the first of them,
119 annotated with the number of the test in the set that failed. The
120 intentionally-failing third test below demonstrates this.
121
122 | 00
123 = [False,False]
124
125 | 000
126 = [False,False,False]
127
128 | 0000
129 = [False,False,False,Flse]
8181 loadFile fileName = do
8282 testText <- readFile fileName
8383 lines <- return $ transformLines $ lines testText
84 blocks <- return $ convertLinesToBlocks $ lines
84 blocks <- return $ reDescribeBlocks $ convertLinesToBlocks $ lines
8585 return blocks
8686
8787 loadLines fileName = do
150150 coalesceLines (line:lines) last =
151151 (last:coalesceLines lines line)
152152
153 --
154 -- Convert lines to blocks.
155 --
156
153157 convertLinesToBlocks ((LiteralText literalText):(TestInput testText):(ExpectedResult expected):rest) =
154158 ((Test literalText testText (Output expected)):convertLinesToBlocks rest)
155159 convertLinesToBlocks ((LiteralText literalText):(TestInput testText):(ExpectedError expected):rest) =
166170 convertLinesToBlocks (_:rest) =
167171 convertLinesToBlocks rest
168172 convertLinesToBlocks [] = []
173
174 --
175 -- Give blocks that don't have a description, the description of the previous
176 -- block that did have a description. Note that when we encounter a new
177 -- section, we do not remember the previous description, as it will surely
178 -- be irrelevant now.
179 --
180
181 reDescribeBlocks blocks = reDescribeBlocks' blocks "" 2
182
183 reDescribeBlocks' [] desc n =
184 []
185 reDescribeBlocks' (block@(Test literalText inp exp):rest) desc n
186 | allWhitespace literalText = (Test numberedDesc inp exp):(reDescribeBlocks' rest desc (n+1))
187 | otherwise = (block):(reDescribeBlocks' rest literalText 2)
188 where numberedDesc = "(#" ++ (show n) ++ ") " ++ (stripLeading '\n' desc)
189 reDescribeBlocks' (block:rest) desc n =
190 block:(reDescribeBlocks' rest "" 2)
191
192 --
193 -- This could use Char.isSpace
194 --
195
196 allWhitespace [] = True
197 allWhitespace (' ':rest) = allWhitespace rest
198 allWhitespace ('\n':rest) = allWhitespace rest
199 allWhitespace ('\t':rest) = allWhitespace rest
200 allWhitespace (_:rest) = False
169201
170202 --
171203 -- The main test-running engine of Falderal:
220252 putStrLn ""
221253 reportEachTest rest
222254
255 stripLeading y [] = []
223256 stripLeading y all@(x:xs)
224257 | x == y = stripLeading y xs
225258 | otherwise = all
00 --------------------------------
1 Total tests: 12, failures: 4
1 Total tests: 15, failures: 5
22 --------------------------------
33
44 FAILED:
3535 Expected: Output "[False,False,True,True]"
3636 Actual : Output "[False,True,True,False]"
3737
38 FAILED:
39 (#3) If we have a set of tests where the tests after the first one have no
40 descriptions of their own, we can take this to suggest they are all
41 testing the same thing. In this case, the literal text that is displayed
42 when any of them fails is the text that comes before the first of them,
43 annotated with the number of the test in the set that failed. The
44 intentionally-failing third test below demonstrates this.
45
46 Input : 0000
47 Expected: Output "[False,False,False,Flse]"
48 Actual : Output "[False,False,False,False]"
49