hascheme/test.sh

51 lines
1.1 KiB
Bash
Raw Normal View History

2013-07-17 20:25:48 +00:00
#!/usr/bin/env zsh
2013-07-18 08:54:25 +00:00
typeset -a listfic
if (($#==0)); then
listfic=( tests/*(.N) )
else
for arg in $@; do
listfic=( $listfic tests/$arg )
done
fi
2013-07-18 08:47:46 +00:00
tmpfic=tests/tmp
2013-07-26 15:53:37 +00:00
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
2013-07-18 08:54:25 +00:00
for input in $listfic; do
2013-07-18 08:47:46 +00:00
sed 's/\\/\\\\/g' $input > $tmpfic
# set 3 as the file descriptor for the file $tmpfic
exec 3< $tmpfic
done=0
num=1
until ((done == 1)); do
read <&3 program
(($?!=0)) && {done=1;continue}
read <&3 expected
(($?!=0)) && {done=1;continue}
2013-07-26 15:53:37 +00:00
result="$($cmd "$program")"
2013-07-18 08:47:46 +00:00
printf "%18s (line %3d): " ${input:t} $num
if [[ $expected == $result ]]; then
print -- "OK"
else
print -- "ERROR"
print -- " program: '$program'"
print -- " expected: '$expected'"
print -- " got: '$result'"
print -- ""
fi
((num+=2))
done
2013-07-17 20:25:48 +00:00
done
2013-07-18 08:47:46 +00:00
\rm -f $tmpfic