better testing with compilation
This commit is contained in:
parent
710e049cfa
commit
b0ed22f436
4 changed files with 26 additions and 5 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,3 +1,8 @@
|
||||||
|
# tests & compilation
|
||||||
|
y
|
||||||
|
.tmp
|
||||||
|
|
||||||
|
# haskell
|
||||||
dist
|
dist
|
||||||
cabal-dev
|
cabal-dev
|
||||||
*.o
|
*.o
|
||||||
|
|
14
test.sh
14
test.sh
|
@ -10,6 +10,18 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmpfic=tests/tmp
|
tmpfic=tests/tmp
|
||||||
|
|
||||||
|
|
||||||
|
if ((${#listfic}>1)); then
|
||||||
|
# compile
|
||||||
|
[[ ! -d .tmp ]] && mkdir .tmp
|
||||||
|
ghc -O2 -hidir .tmp -odir .tmp y.hs
|
||||||
|
cmd='./y'
|
||||||
|
else
|
||||||
|
cmd=(runghc y.hs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# test
|
||||||
for input in $listfic; do
|
for input in $listfic; do
|
||||||
sed 's/\\/\\\\/g' $input > $tmpfic
|
sed 's/\\/\\\\/g' $input > $tmpfic
|
||||||
# set 3 as the file descriptor for the file $tmpfic
|
# set 3 as the file descriptor for the file $tmpfic
|
||||||
|
@ -21,7 +33,7 @@ for input in $listfic; do
|
||||||
(($?!=0)) && {done=1;continue}
|
(($?!=0)) && {done=1;continue}
|
||||||
read <&3 expected
|
read <&3 expected
|
||||||
(($?!=0)) && {done=1;continue}
|
(($?!=0)) && {done=1;continue}
|
||||||
result="$(runghc y.hs "$program")"
|
result="$($cmd "$program")"
|
||||||
printf "%18s (line %3d): " ${input:t} $num
|
printf "%18s (line %3d): " ${input:t} $num
|
||||||
if [[ $expected == $result ]]; then
|
if [[ $expected == $result ]]; then
|
||||||
print -- "OK"
|
print -- "OK"
|
||||||
|
|
4
tests/bool
Normal file
4
tests/bool
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#t
|
||||||
|
#t
|
||||||
|
#f
|
||||||
|
#f
|
8
y.hs
8
y.hs
|
@ -48,8 +48,8 @@ parseExpr :: Parser LispVal
|
||||||
parseExpr = parseString
|
parseExpr = parseString
|
||||||
<|> try parseChar -- #\a #\b etc...
|
<|> try parseChar -- #\a #\b etc...
|
||||||
<|> try parseFloat -- 3.1415
|
<|> try parseFloat -- 3.1415
|
||||||
<|> parseNumber -- 3, #b011001, #o070, #d930, #xFF3
|
<|> try parseNumber -- 3, #b011001, #o070, #d930, #xFF3
|
||||||
<|> parseAtom -- symbol-323
|
<|> try parseAtom -- symbol-323
|
||||||
<|> parseQuoted
|
<|> parseQuoted
|
||||||
<|> do
|
<|> do
|
||||||
char '('
|
char '('
|
||||||
|
@ -90,8 +90,8 @@ parseAtom = do
|
||||||
rest <- many (letter <|> digit <|> symbol)
|
rest <- many (letter <|> digit <|> symbol)
|
||||||
let atom = first:rest
|
let atom = first:rest
|
||||||
return $ case atom of
|
return $ case atom of
|
||||||
"#vrai" -> Bool True
|
"#t" -> Bool True
|
||||||
"#faux" -> Bool False
|
"#f" -> Bool False
|
||||||
_ -> Atom atom
|
_ -> Atom atom
|
||||||
|
|
||||||
numFromBase n str = foldl' traiteNombre 0 str
|
numFromBase n str = foldl' traiteNombre 0 str
|
||||||
|
|
Loading…
Reference in a new issue