git @ Cat's Eye Technologies Falderal / 0037ff3
Interpret shell failures as exceptions; improve internal tests. catseye 10 years ago
5 changed file(s) with 84 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
00 module Test.Falderal.Formatter.Shell (format) where
11
22 --
3 -- Test.Falderal.Formatter.Shell -- Shell-script compiler for Falderal
3 -- Test.Falderal.Formatter.Shell -- Bourne shell script compiler for Falderal
44 -- Copyright (c)2011 Cat's Eye Technologies. All rights reserved.
55 --
66 -- Redistribution and use in source and binary forms, with or without
7171 \rm -f input.txt output.txt\n"
7272
7373 testExecution cmd id =
74 cmd ++ " <input.txt >output.txt\n\
75 \echo \"output\"\n\
74 cmd ++ " <input.txt >output.txt 2>&1\n\
75 \if [ $? != 0 ]; then\n\
76 \ echo \"exception\"\n\
77 \else\n\
78 \ echo \"output\"\n\
79 \fi\n\
7680 \echo " ++ (show id) ++ "\n\
7781 \echo `wc -l output.txt`\n\
7882 \cat output.txt\n"
0 -> encoding: UTF-8
1
2 -> Functionality "Count lines" is implemented by
3 -> Haskell function Erroneous:countLines
4
5 -> Tests for functionality "Count lines"
6
7 | These are eight words
8 | that span two lines.
9 = 2
10
11 | These are eight words
12 | that span
13 | three lines.
14 = 3
15
16 -> Functionality "Raise exception" is implemented by shell command
17 -> "./exception.sh"
18
19 -> Tests for functionality "Raise exception"
20
21 When a shell script returns a non-zero exit code, that should be interpreted
22 as an exception by Falderal, which can be matched with an expected exception
23 block.
24
25 | whatever
26 ? gello
0 module Erroneous where
1
2 -- This Haskell module contains some errors which will cause the results
3 -- generator generated for it to not even compile. Test.Falderal should
4 -- handle this in some way where it's obvious something went wrong.
5
6 countLines str = show $ length $ likes str
0 #!/bin/sh
1
2 # This Bourne shell script should fail when run, unless you have some really
3 # weirdly-named executables on your $PATH. Test.Falderal should interpret
4 # this failure as an exception.
5
6 echo 1>&2 gello
7 exit 1
44 # installed via Cabal first:
55 # $ cabal clean && cabal install --prefix=$HOME --user
66
7 echo 'Testing formatting...'
8
79 falderal format identity eg/LiterateHaskellDemo.lhs >formatted.txt
810 diff -u eg/LiterateHaskellDemo.lhs formatted.txt
911 E1=$?
1012 rm -f formatted.txt
13
14 echo 'Testing LiterateHaskellDemo...'
1115
1216 cat >expected.txt <<EOF
1317 --------------------------------
6872 E2=$?
6973 rm -f expected.txt actual.txt
7074
71 if [ $E1 != 0 -o $E2 != 0 ]
75 echo 'Testing Erroneous.falderal...'
76
77 cat >expected.txt <<EOF
78 --------------------------------
79 Total tests: 3, failures: 2
80 --------------------------------
81
82 NOT RUN : (#2)
83 Input:
84 These are eight words
85 that span two lines.
86 Expected: Output "2"
87
88 NOT RUN : (#3)
89 Input:
90 These are eight words
91 that span
92 three lines.
93 Expected: Output "3"
94
95 EOF
96 cd eg
97 falderal -m test Erroneous.falderal >../actual.txt 2>/dev/null
98 cd ..
99 diff -u expected.txt actual.txt
100 E3=$?
101 rm -f expected.txt actual.txt
102
103 if [ $E1 != 0 -o $E2 != 0 -o $E3 != 0 ]
72104 then
105 echo "Internal tests failed!"
73106 exit 1
74107 else
108 echo "All tests passed."
75109 exit 0
76110 fi