1 (* Auxiliary functions for test cases
*)
5 fun check b
= if b
then "OK" else "WRONG";
6 fun check
' f
= (if f () then "OK" else "WRONG") handle _
=> "EXN";
8 fun range (from
, to
) p
=
11 (from
> to
) orelse (p from
) andalso (range (from
+1, to
) p
)
14 fun checkrange bounds
= check
o range bounds
;
16 fun tst0 s s
' = print (s ^
" \t" ^ s
' ^
"\n");
17 fun tst s b
= tst0
s (check b
);
18 fun tst
' s f
= tst0
s (check
' f
);
20 fun tstrange s bounds
= (tst s
) o range bounds
23 PS
1995-03-23, 1996-05-01, 1998-04-06
26 (* DOS
: Plain WRONG
: test6a
, test9a (and test9b
);
27 Excusable
: test8b
, test11b
, test12a
, test13a
, test13b
, test13c
30 (* The test requires three symbolic links to be present
in the current directory
:
33 testbadl
-> exists
.not
34 Moreover
, the file README must exist
and the file exists
.not not
.
35 Also
, the test requires one hard link between file hardlinkA
and file hardlinkB
.
38 val _
= print
"\nFile filesys.sml: Testing structure FileSys...\n"
43 val _
= (rmDir
"testdir") handle OS
.SysErr _
=> ();
44 val _
= (rmDir
"testdir2") handle OS
.SysErr _
=> ();
46 val test1a
= tst0
"test1a" ((mkDir
"testdir" seq
"OK") handle _
=> "WRONG")
47 val test1b
= tst0
"test1b" ((mkDir
"testdir" seq
"WRONG")
48 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
50 val test2
= tst
' "test2" (fn _
=> isDir
"testdir");
52 val test3a
= tst
' "test3a" (fn _
=> access("testdir", [A_READ
, A_EXEC
, A_WRITE
]));
57 val test4a
= tst0
"test4a" ((chDir cdir seq
"OK") handle _
=> "WRONG")
58 val test4b
= tst
' "test4b" (fn _
=> cdir
= getDir());
59 val _
= chDir
"testdir";
60 val test4c
= tst
' "test4c" (fn _
=> cdir
<> getDir());
62 val test4d
= tst
' "test4d" (fn _
=> cdir
= getDir());
65 val _
= rename
{old
= "testdir", new
= "exists.not"};
67 val test5
= tst0
"test5" ((rmDir
"exists.not" seq
"OK") handle _
=> "WRONG")
69 val test6a
= tst0
"test6a" ((openDir
"exists.not" seq
"WRONG")
70 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
71 val test6b
= tst0
"test6b" ((isDir
"exists.not" seq
"WRONG")
72 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
73 val test6c
= tst0
"test6c" ((rmDir
"exists.not" seq
"WRONG")
74 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
75 val test6d
= tst0
"test6d" ((chDir
"exists.not" seq
"WRONG")
76 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
77 val test6e
= tst0
"test6e" ((fullPath
"exists.not" seq
"WRONG")
78 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
79 val test6f
= tst0
"test6f" ((realPath
"exists.not" seq
"WRONG")
80 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
81 val test6g
= tst0
"test6g" ((modTime
"exists.not" seq
"WRONG")
82 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
83 val test6h
= tst0
"test6h" ((setTime("exists.not", NONE
) seq
"WRONG")
84 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
85 val test6i
= tst0
"test6i" ((remove
"exists.not" seq
"WRONG")
86 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
87 val test6j
= tst0
"test6j" ((rename
{old
="exists.not", new
="testdir2"} seq
"WRONG")
88 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
89 val test6k
= tst0
"test6k" ((fileSize
"exists.not" seq
"WRONG")
90 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
91 val test6l
= tst
' "test6l" (fn _
=> not (access("exists.not", [])));
93 val _
= mkDir
"testdir";
96 val dstr
= openDir
"testdir";
99 tst
' "test7a" (fn _
=> NONE
= readDir dstr
);
100 val _
= rewindDir dstr
;
102 tst
' "test7b" (fn _
=> NONE
= readDir dstr
);
103 val _
= closeDir dstr
;
104 val test7c
= tst0
"test7c" ((readDir dstr seq
"WRONG")
105 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
106 val test7d
= tst0
"test7d" ((rewindDir dstr seq
"WRONG")
107 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
108 val test7e
= tst0
"test7e" ((closeDir dstr seq
"OK")
115 if isLink new
handle OS
.SysErr _
=> false
117 else Posix
.FileSys
.symlink
{new
= new
, old
= old
})
118 [("testlink", "README"),
119 ("testcycl", "testcycl"),
120 ("testbadl", "exists.not")]
123 tst
' "test8a" (fn _
=> fullPath
"." = getDir ());
125 tst
' "test8b" (fn _
=> fullPath
"testlink" = getDir() ^
"/README");
126 val test8c
= tst0
"test8c" ((fullPath
"testcycl" seq
"WRONG")
127 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
128 val test8d
= tst0
"test8d" ((fullPath
"testbadl" seq
"WRONG")
129 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
130 val test8e
= tst
' "test8e" (fn _
=> realPath
"." = ".");
131 val test8f
= tst
' "test8f" (fn _
=> realPath
"testlink" = "README");
132 val test8g
= tst0
"test8g" ((realPath
"testcycl" seq
"WRONG")
133 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
134 val test8h
= tst0
"test8h" ((realPath
"testbadl" seq
"WRONG")
135 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
138 tst
' "test9a" (fn _
=>
139 setTime ("README", SOME (Time
.fromReal
1E6
)) = ());
141 tst
' "test9b" (fn _
=> modTime
"README" = Time
.fromReal
1E6
);
143 val test10a
= tst0
"test10a" ((remove
"testdir" seq
"WRONG")
144 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
146 tst
' "test10b" (fn _
=>
147 rename
{old
= "testdir", new
= "testdir2"} = ());
149 tst
' "test10c" (fn _
=> isDir
"testdir2");
152 tst
' "test11a" (fn _
=> not (access ("testdir", [])));
154 tst
' "test11b" (fn _
=> access("testlink", []));
156 tst
' "test11c" (fn _
=> not (access("testbadl", [])));
159 tst
' "test12a" (fn _
=> isLink
"testcycl"
160 andalso isLink
"testlink"
161 andalso isLink
"testbadl");
163 tst
' "test12b" (fn _
=> not (isLink
"testdir2"
164 orelse isLink
"README"));
165 val test12c
= tst0
"test12c" ((isLink
"exists.not" seq
"WRONG")
166 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
169 tst
' "test13a" (fn _
=> readLink
"testcycl" = "testcycl");
171 tst
' "test13b" (fn _
=> readLink
"testlink" = "README");
173 tst
' "test13c" (fn _
=> readLink
"testbadl" = "exists.not");
174 val test13d
= tst0
"test13d" ((readLink
"testdir2" seq
"WRONG")
175 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
176 val test13e
= tst0
"test13e" ((readLink
"exists.not" seq
"WRONG")
177 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
179 val test14
= tst0
"test14" ((tmpName () seq
"OK"))
182 tst
' "test15a" (fn _
=>
183 fileId
"." = fileId
"."
184 andalso fileId
"testlink" = fileId
"README"
185 andalso fileId
"." <> fileId
"README");
187 tst
' "test15b" (fn _
=> compare(fileId
".", fileId
".") = EQUAL
)
189 tst
' "test15b1" (fn _
=> compare(fileId
".", fileId
"README") <> EQUAL
)
191 tst
' "test15b2" (fn _
=> compare(fileId
"testlink", fileId
"README") = EQUAL
)
193 tst
' "test15b3" (fn _
=>
194 (compare(fileId
".", fileId
"README") = LESS
195 andalso compare(fileId
"README", fileId
".") = GREATER
197 compare(fileId
".", fileId
"README") = GREATER
198 andalso compare(fileId
"README", fileId
".") = LESS
));
199 val test15c
= tst0
"test15c" ((fileId
"exists.not" seq
"WRONG")
200 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
201 val test15d
= tst0
"test15d" ((fileId
"testbadl" seq
"WRONG")
202 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
203 val test15e
= tst0
"test15e" ((fileId
"testcycl" seq
"WRONG")
204 handle OS
.SysErr _
=> "OK" | _
=> "WRONG")
208 (if access ("hardlinkA", [])
210 else TextIO.closeOut (TextIO.openOut
"hardlinkA")
211 ; if access ("hardlinkB", [])
213 else Posix
.FileSys
.link
{old
= "hardlinkA", new
= "hardlinkB"})
216 tst
' "test15f" (fn _
=> fileId
"hardlinkA" = fileId
"hardlinkB")
218 tst
' "test15g" (fn _
=> compare(fileId
"hardlinkA", fileId
"hardlinkB") = EQUAL
)
220 val _
= rmDir
"testdir2";