git @ Cat's Eye Technologies Falderal / 0366ab3
Tests (and fixes) for %(test-text) and missing newline at EOF. catseye 10 years ago
6 changed file(s) with 78 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
7575 History
7676 -------
7777
78 Version 0.6 "Streeterville" (currently under development):
78 Version 0.6 "Streeterville" (unreleased, currently under development):
7979
8080 * Variables may be included in the specification of a shell command
8181 implementation; these will be expanded before generating the results
101101 scheduling by `ghc`, although really, I haven't a clue.) Results are
102102 now written to different temporary files with different, generated
103103 names.
104 * Previously, if the output of a shell command being tested did not end
105 with a newline, the intermediate results file was not being generated
106 correctly, resulting in failures being misreported. This has been
107 recitified.
104108
105109 TODO:
106110
107 * Skip blank lines at end of each block in results. Test for missing eol.
108111 * Command-line option to clear functionalities.
109112 * Command-line option to skip tests for given functionalities.
110113
105105 escapeHtml ('&':rest) = "&" ++ escapeHtml rest
106106 escapeHtml (c:cs) = c:(escapeHtml cs)
107107
108 escapeSingleQuotes "" = ""
109 escapeSingleQuotes ('\'':rest) = "'\\''" ++ escapeSingleQuotes rest
110 escapeSingleQuotes (c:cs) = c:(escapeSingleQuotes cs)
111
108112 formatLines formatter lines = foldl (++) "" (map (formatter) lines)
109113
110114 pad s n = padFrom s (n-(length s))
1515 format _ blocks =
1616 prelude ++ (formatBlocks blocks) ++ postlude
1717
18 formatBlocks (test@(Test id [(ShellTest cmd)] desc input _ _):rest) =
18 formatBlocks (test@(Test id [(ShellTest cmd)] desc body _ _):rest) =
1919 let
20 inputHereDoc = hereDoc "input.txt" input
21 cmd' = expandCommand cmd
20 inputHereDoc = hereDoc "input.txt" body
21 cmd' = expandCommand cmd body
2222 formattedBlock = inputHereDoc ++ testExecution cmd' id
2323 in
2424 formattedBlock ++ "\n" ++ formatBlocks rest
4646 -- TODO: capture output/errors from command, even when output variable
4747 -- is present
4848
49 expandCommand cmd =
49 expandCommand cmd body =
5050 let
5151 substitutions = [
5252 ("test-file", "input.txt"),
53 ("test-text", "`cat input.txt`"),
53 ("test-text", escapeSingleQuotes body),
5454 ("output-file", "output.txt")
5555 ]
5656 suppliedInput =
8080 \ echo \"output\"\n\
8181 \fi\n\
8282 \echo " ++ (show id) ++ "\n\
83 \falderal newlinify output.txt >output2.txt\n\
84 \mv output2.txt output.txt\n\
8385 \echo `wc -l output.txt`\n\
8486 \cat output.txt\n"
0 -> encoding: UTF-8
1
2 Tests for echo
3 ==============
4
5 This Falderal document was written by Chris Pressey. It is hereby placed in
6 the public domain.
7
8 This test suite is part of the Falderal internal tests. It tests two
9 things: expansion of the `%(test-text)` variable, and correctly handling
10 the case where the program being tested does not end its output with
11 a new line.
12
13 -> Functionality "Echo" is implemented by
14 -> shell command "echo -n '%(test-text)'"
15
16 -> Functionality "Echo" is implemented by
17 -> shell command "echo '%(test-text)'"
18
19 -> Tests for functionality "Echo"
20
21 Echo a single line.
22
23 | This is a test.
24 = This is a test.
25
26 Echo multiple lines.
27
28 | This is
29 | a test.
30 = This is
31 = a test.
32
33 Echo with an embedded single quote.
34
35 | This isn't a test.
36 = This isn't a test.
103103 report reportFormat (haskellBlocks' ++ shellBlocks')
104104 exitWith ExitSuccess
105105
106 dispatch ("newlinify":fileName:_) flags = do
107 text <- readFile fileName
108 case last text of
109 '\n' -> putStr text
110 _ -> putStrLn text
111 exitWith ExitSuccess
112
106113 dispatch ("version":_) _ = do
107 putStrLn "Test.Falderal version 0.5"
114 putStrLn "Test.Falderal version 0.6"
108115
109116 dispatch _ _ = putStrLn header
110117
7777 E2=$?
7878 rm -f expected.txt actual.txt
7979
80 echo 'Testing wc.falderal (multiple impls, var exp...)'
80 echo 'Testing wc.falderal (multiple impls, var exp)...'
8181
8282 cat >expected.txt <<EOF
8383 --------------------------------
9797 cd ..
9898 diff -u expected.txt actual.txt
9999 EWC=$?
100 rm -f expected.txt actual.txt
101
102 echo 'Testing echo.falderal (test-text var, missing newline)...'
103
104 cat >expected.txt <<EOF
105 --------------------------------
106 Total tests: 6, failures: 0
107 --------------------------------
108
109 EOF
110 cd eg
111 falderal test echo.falderal >../actual.txt
112 cd ..
113 diff -u expected.txt actual.txt
114 EECHO=$?
100115 rm -f expected.txt actual.txt
101116
102117 echo 'Testing Erroneous.falderal...'
155170 E5=$?
156171 rm -f expected.txt actual.txt
157172
158 if [ $E1 != 0 -o $E2 != 0 -o $E3 != 0 -o $E4 != 0 -o $E5 != 0 -o $EWC != 0 ]
173 if [ $E1 != 0 -o $E2 != 0 -o $E3 != 0 -o $E4 != 0 -o $E5 != 0 -o $EWC != 0 -o $EECHO != 0 ]
159174 then
160175 echo "Internal tests failed!"
161176 exit 1