-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·73 lines (67 loc) · 1.63 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/zsh
set -ue
TEMPDIR=testtmp
BIN="./$(stack path --dist-dir)/build/hash2/hash2"
function assert() {
set +ue
echo $1 | PROMPT="" $BIN > $TEMPDIR/result
eval $1 > $TEMPDIR/correct
cmp --silent $TEMPDIR/result $TEMPDIR/correct
RET=$?
set -ue
if [ $RET -eq 0 ] ;then
echo "Success: $1"
else
echo "Failed: $1"
clean
exit $RET
fi
}
function assert_side_effect() {
set +ue
echo $1 | PROMPT="" $BIN
eval $2
eval $3
RET=$?
set -ue
if [ $RET -eq 0 ] ;then
echo "Success: $1"
else
echo "Failed: $1"
clean
exit $RET
fi
}
function setup() {
echo "setup"
stack build
if [ -d $TEMPDIR ] ;then
clean
fi
mkdir $TEMPDIR
}
function clean() {
echo "clean"
rm -rf $TEMPDIR
}
echo "starting test"
setup
assert "ls src"
assert " ls src "
assert "ls | grep R"
assert "ls|grep R"
assert "grep H < LICENSE"
assert_side_effect "ls > $TEMPDIR/hoge" "ls > $TEMPDIR/fuga" "cmp --silent $TEMPDIR/hoge $TEMPDIR/fuga"
assert_side_effect "ls | grep R > $TEMPDIR/hoge" "ls | grep R > $TEMPDIR/fuga" "cmp --silent $TEMPDIR/hoge $TEMPDIR/fuga"
assert_side_effect "cat notexistfile 2> $TEMPDIR/hoge" "cat notexistfile 2> $TEMPDIR/fuga" "cmp --silent $TEMPDIR/hoge $TEMPDIR/fuga"
assert "ls && echo fuga"
assert "ls&&echo fuga"
assert "ls || echo hoge"
assert "ls||echo hoge"
assert "ls; echo hoge"
assert "ls;echo hoge"
#assert "ls;"
assert "cd src; ls; cd .."
#assert "rm -rf $TEMPDIR/hogedir 2> /dev/null; mkdir $TEMPDIR/hogedir; cp src/Hash/* $TEMPDIR/hogedir/; ls $TEMPDIR/hogedir"
clean
echo "All test passed."