| 1 | (* Auxiliary functions for test cases *) |
| 2 | |
| 3 | infix 1 seq |
| 4 | fun e1 seq e2 = e2; |
| 5 | fun check b = if b then "OK" else "WRONG"; |
| 6 | fun check' f = (if f () then "OK" else "WRONG") handle _ => "EXN"; |
| 7 | |
| 8 | fun range (from, to) p = |
| 9 | let open Int |
| 10 | in |
| 11 | (from > to) orelse (p from) andalso (range (from+1, to) p) |
| 12 | end; |
| 13 | |
| 14 | fun checkrange bounds = check o range bounds; |
| 15 | |
| 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); |
| 19 | |
| 20 | fun tstrange s bounds = (tst s) o range bounds |
| 21 | |
| 22 | (* test/filesys.sml |
| 23 | PS 1995-03-23, 1996-05-01, 1998-04-06 |
| 24 | *) |
| 25 | |
| 26 | (* DOS: Plain WRONG: test6a, test9a (and test9b); |
| 27 | Excusable: test8b, test11b, test12a, test13a, test13b, test13c |
| 28 | *) |
| 29 | |
| 30 | (* The test requires three symbolic links to be present in the current directory: |
| 31 | testlink -> README |
| 32 | testcycl -> testcycl |
| 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. |
| 36 | *) |
| 37 | |
| 38 | val _ = print "\nFile filesys.sml: Testing structure FileSys...\n" |
| 39 | |
| 40 | local |
| 41 | open OS.FileSys |
| 42 | (* Clean up: *) |
| 43 | val _ = (rmDir "testdir") handle OS.SysErr _ => (); |
| 44 | val _ = (rmDir "testdir2") handle OS.SysErr _ => (); |
| 45 | |
| 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") |
| 49 | |
| 50 | val test2 = tst' "test2" (fn _ => isDir "testdir"); |
| 51 | |
| 52 | val test3a = tst' "test3a" (fn _ => access("testdir", [A_READ, A_EXEC, A_WRITE])); |
| 53 | |
| 54 | local |
| 55 | val cdir = getDir(); |
| 56 | in |
| 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()); |
| 61 | val _ = chDir ".."; |
| 62 | val test4d = tst' "test4d" (fn _ => cdir = getDir()); |
| 63 | end; |
| 64 | |
| 65 | val _ = rename{old = "testdir", new = "exists.not"}; |
| 66 | |
| 67 | val test5 = tst0 "test5" ((rmDir "exists.not" seq "OK") handle _ => "WRONG") |
| 68 | |
| 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", []))); |
| 92 | |
| 93 | val _ = mkDir "testdir"; |
| 94 | |
| 95 | local |
| 96 | val dstr = openDir "testdir"; |
| 97 | in |
| 98 | val test7a = |
| 99 | tst' "test7a" (fn _ => NONE = readDir dstr); |
| 100 | val _ = rewindDir dstr; |
| 101 | val test7b = |
| 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") |
| 109 | handle _ => "WRONG") |
| 110 | end |
| 111 | |
| 112 | val _ = |
| 113 | List.app |
| 114 | (fn (new, old) => |
| 115 | if isLink new handle OS.SysErr _ => false |
| 116 | then () |
| 117 | else Posix.FileSys.symlink {new = new, old = old}) |
| 118 | [("testlink", "README"), |
| 119 | ("testcycl", "testcycl"), |
| 120 | ("testbadl", "exists.not")] |
| 121 | |
| 122 | val test8a = |
| 123 | tst' "test8a" (fn _ => fullPath "." = getDir ()); |
| 124 | val test8b = |
| 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") |
| 136 | |
| 137 | val test9a = |
| 138 | tst' "test9a" (fn _ => |
| 139 | setTime ("README", SOME (Time.fromReal 1E6)) = ()); |
| 140 | val test9b = |
| 141 | tst' "test9b" (fn _ => modTime "README" = Time.fromReal 1E6); |
| 142 | |
| 143 | val test10a = tst0 "test10a" ((remove "testdir" seq "WRONG") |
| 144 | handle OS.SysErr _ => "OK" | _ => "WRONG") |
| 145 | val test10b = |
| 146 | tst' "test10b" (fn _ => |
| 147 | rename{old = "testdir", new = "testdir2"} = ()); |
| 148 | val test10c = |
| 149 | tst' "test10c" (fn _ => isDir "testdir2"); |
| 150 | |
| 151 | val test11a = |
| 152 | tst' "test11a" (fn _ => not (access ("testdir", []))); |
| 153 | val test11b = |
| 154 | tst' "test11b" (fn _ => access("testlink", [])); |
| 155 | val test11c = |
| 156 | tst' "test11c" (fn _ => not (access("testbadl", []))); |
| 157 | |
| 158 | val test12a = |
| 159 | tst' "test12a" (fn _ => isLink "testcycl" |
| 160 | andalso isLink "testlink" |
| 161 | andalso isLink "testbadl"); |
| 162 | val test12b = |
| 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") |
| 167 | |
| 168 | val test13a = |
| 169 | tst' "test13a" (fn _ => readLink "testcycl" = "testcycl"); |
| 170 | val test13b = |
| 171 | tst' "test13b" (fn _ => readLink "testlink" = "README"); |
| 172 | val test13c = |
| 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") |
| 178 | |
| 179 | val test14 = tst0 "test14" ((tmpName () seq "OK")) |
| 180 | |
| 181 | val test15a = |
| 182 | tst' "test15a" (fn _ => |
| 183 | fileId "." = fileId "." |
| 184 | andalso fileId "testlink" = fileId "README" |
| 185 | andalso fileId "." <> fileId "README"); |
| 186 | val test15b = |
| 187 | tst' "test15b" (fn _ => compare(fileId ".", fileId ".") = EQUAL) |
| 188 | val test15b1 = |
| 189 | tst' "test15b1" (fn _ => compare(fileId ".", fileId "README") <> EQUAL) |
| 190 | val test15b2 = |
| 191 | tst' "test15b2" (fn _ => compare(fileId "testlink", fileId "README") = EQUAL) |
| 192 | val test15b3 = |
| 193 | tst' "test15b3" (fn _ => |
| 194 | (compare(fileId ".", fileId "README") = LESS |
| 195 | andalso compare(fileId "README", fileId ".") = GREATER |
| 196 | orelse |
| 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") |
| 205 | (* Unix only: *) |
| 206 | |
| 207 | val _ = |
| 208 | (if access ("hardlinkA", []) |
| 209 | then () |
| 210 | else TextIO.closeOut (TextIO.openOut "hardlinkA") |
| 211 | ; if access ("hardlinkB", []) |
| 212 | then () |
| 213 | else Posix.FileSys.link {old = "hardlinkA", new = "hardlinkB"}) |
| 214 | |
| 215 | val test15f = |
| 216 | tst' "test15f" (fn _ => fileId "hardlinkA" = fileId "hardlinkB") |
| 217 | val test15g = |
| 218 | tst' "test15g" (fn _ => compare(fileId "hardlinkA", fileId "hardlinkB") = EQUAL) |
| 219 | |
| 220 | val _ = rmDir "testdir2"; |
| 221 | in |
| 222 | end |