-
Notifications
You must be signed in to change notification settings - Fork 0
/
t
executable file
·129 lines (114 loc) · 2.34 KB
/
t
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
#
# Author: Richard James Howe
# Email: howe.r.j.89@gmail.com
# License: The Unlicense / Public Domain
# Repo: https://github.com/howerj/ffs
#
# Unit tests for a Block Based Forth File System. This really could
# use a lot of work to add more tests, the file system has a large
# surface area and only cursory tests are done, mainly be the image
# generation routines present in `ffs.fth`. If an error is found a
# test should be added here to either document it or prevent a
# regression.
#
set -eu
# Forth Unit Test Framework, this will be run under
# the Forth system to test.
UNIT=$(
cat <<'EOF'
marker [UNIT]
+ffs +dos
: .fail cr source type cr ." [FAIL]" cr bye ;
: .pass cr ." [PASS]" cr bye ;
: +> token find 0= if .fail then catch 0= ?exit .fail ;
: -> token find 0= if .fail then catch 0<> ?exit .fail ;
: exists? token count file-exists? 0<> ?exit .fail ;
: unexists? token count file-exists? 0= ?exit .fail ;
EOF
)
FORTH="${1:-gforth}";
case "${FORTH}" in
gforth) echo "GFORTH testing" ;;
subleq) echo "SUBLEQ eForth testing" ;;
*) echo "Invalid test option (either 'gforth' or 'subleq' are allowed): ${FORTH}";
exit 1; ;;
esac
disk() { # Make a SUBLEQ eForth disk image
if [ ! -f disk.dec ]; then make disk; fi;
}
clean () {
make clean;
}
target () {
if [ "${FORTH}" = "gforth" ]; then
# Do nothing, `ffs.fb` will be made as part of `make run` and
# is fast to do. Making `disk.dec` is very slow.
true;
else
disk;
fi;
}
reset () {
clean;
target;
}
run () {
target;
if [ "${FORTH}" = "gforth" ]; then
rm -f ffs.fb;
make run; # Default makefile run target is gforth
else
./subleq disk.dec _.dec
fi;
}
# TODO: Get working with SUBLEQ eFORTH
#TFILE=$(tempfile)
TFILE=$(mktemp)
echo "TFILE: ${TFILE}";
trap 'rm -fv -- "${TFILE}"' EXIT
PROG=$(
cat <<'EOF'
unexists? 1.txt
fallocate 1.txt 1
exists? 1.txt
-> mkdir
-> rmdir
\ -> rmdir 1.txt ( fails! )
rm 1.txt
unexists? 1.txt
mkdir a
exists? a
mkdir b
-> rm b
exists? b
exists? a
mv a c
unexists? a
exists? c
ls
file: test.fth
| : example ." HELLO" ;
;file
require test.fth
+> example
rm test.fth
unexists? test.fth
file: script.fth
| mkdir x
| mkdir y
| ls
;file
require script.fth
require x
require y
rmdir x
rmdir y
.pass
EOF
)
echo "${UNIT}" "${PROG}" | run | tee "${TFILE}"
grep -v '^\[FAIL\]' "${TFILE}" > /dev/null
grep '^\[PASS\]' "${TFILE}" > /dev/null
rm "${TFILE}"
exit