summaryrefslogtreecommitdiffstats
path: root/tests/fCmd.test
blob: 8d867eb491a8baa40a3d29ef87f67d74cae1a266 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
# This file tests the tclFCmd.c file.
#
# This file contains a collection of tests for one or more of the Tcl built-in
# commands. Sourcing this file into Tcl runs the tests and generates output
# for errors. No output means no errors were found.
#
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {"::tcltest" ni [namespace children]} {
    package require tcltest 2
    namespace import -force ::tcltest::*
}

::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]

cd [temporaryDirectory]

testConstraint testsetplatform [llength [info commands testsetplatform]]
testConstraint testchmod [llength [info commands testchmod]]
testConstraint winVista 0
testConstraint win2000orXP 0
# Don't know how to determine this constraint correctly
testConstraint notNetworkFilesystem 0
testConstraint reg 0
if {[testConstraint win]} {
    catch {
	# Is the registry extension already static to this shell?
	try {
	    load {} Registry
	    set ::reglib {}
	} on error {} {
	    # try the location given to use on the commandline to tcltest
	    ::tcltest::loadTestedCommands
	    load $::reglib Registry
	}
	testConstraint reg 1
    }
}

set tmpspace /tmp;# default value
# Find a group that exists on this Unix system, or else skip tests that
# require Unix groups.
testConstraint foundGroup [expr {![testConstraint unix]}]
if {[testConstraint unix]} {
    catch {
	set groupList [exec groups]
	set group [lindex $groupList 0]
	testConstraint foundGroup 1
    }

    proc dev dir {
	file stat $dir stat
	return $stat(dev)
    }

    if {[catch {makeDirectory tcl[pid] /tmp} tmpspace] == 0} {
	testConstraint xdev [expr {([dev .] != [dev $tmpspace])}]
    }
}

# Also used in winFCmd...
if {[testConstraint win]} {
    set major [string index $tcl_platform(osVersion) 0]
    if {[testConstraint nt] && $major > 4} {
        if {$major > 5} {
            testConstraint winVista 1
        } elseif {$major == 5} {
            testConstraint win2000orXP 1
        }
    }
}

testConstraint darwin9 [expr {
    [testConstraint unix]
    && $tcl_platform(os) eq "Darwin"
    && [package vsatisfies 1.$tcl_platform(osVersion) 1.9]
}]
testConstraint notDarwin9 [expr {![testConstraint darwin9]}]

testConstraint fileSharing 0
testConstraint notFileSharing 1
testConstraint linkFile 1
testConstraint linkDirectory 1

# Several tests require need to match results against the unix username
set user {}
if {[testConstraint unix]} {
    catch {
	set user [exec whoami]
    }
    if {$user eq ""} {
	catch {
	    regexp {^[^(]*\(([^)]*)\)} [exec id] -> user
	}
    }
    if {$user eq ""} {
	set user "root"
    }
}

proc createfile {file {string a}} {
    set f [open $file w]
    puts -nonewline $f $string
    close $f
    return $string
}

#
# checkcontent --
#
#  Ensures that file "file" contains only the string "matchString" returns 0
#  if the file does not exist, or has a different content
#
proc checkcontent {file matchString} {
    try {
	set f [open $file]
	set fileString [read $f]
	close $f
    } on error {} {
	return 0
    }
    return [string match $matchString $fileString]
}

proc openup {path} {
    testchmod 777 $path
    if {[file isdirectory $path]} {
	catch {
	    foreach p [glob -directory $path *] {
		openup $p
	    }
	}
    }
}

proc cleanup {args} {
    set wd [list .]
    foreach p [concat $wd $args] {
	set x ""
	catch {
	    set x [glob -directory $p tf* td*]
	}
	foreach file $x {
	    if {
		[catch {file delete -force -- $file}]
		&& [testConstraint testchmod]
	    } then {
		catch {openup $file}
		catch {file delete -force -- $file}
	    }
	}
    }
}

proc contents {file} {
    set f [open $file]
    set r [read $f]
    close $f
    return $r
}


set root [lindex [file split [pwd]] 0]

# A really long file name.
# Length of long is 1216 chars, which should be greater than any static buffer
# or allowable filename.

set long "abcdefghihjllmnopqrstuvwxyz01234567890"
append long $long
append long $long
append long $long
append long $long
append long $long

test fCmd-1.1 {TclFileRenameCmd} -constraints {notRoot} -setup {
    cleanup
} -body {
    createfile tf1
    file rename tf1 tf2
    glob tf*
} -result {tf2}

test fCmd-2.1 {TclFileCopyCmd} -constraints {notRoot} -setup {
    cleanup
} -body {
    createfile tf1
    file copy tf1 tf2
    lsort [glob tf*]
} -result {tf1 tf2}

test fCmd-3.1 {FileCopyRename: FileForceOption fails} -constraints {notRoot} -body {
    file rename -xyz
} -returnCodes error -result {bad option "-xyz": must be -force or --}
test fCmd-3.2 {FileCopyRename: not enough args} -constraints {notRoot} -body {
    file rename xyz
} -returnCodes error -result {wrong # args: should be "file rename ?-option value ...? source ?source ...? target"}
test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
    file rename xyz ~_totally_bogus_user
} -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file copy tf1 ~
} -result {error copying "tf1": no such file or directory}
test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file rename tf1 tf2 tf3
} -result {error renaming: target "tf3" is not a directory}
test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf3
    file rename tf1 tf2 tf3
} -result {error renaming: target "tf3" is not a directory}
test fCmd-3.7 {FileCopyRename: target exists & is directory} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    createfile tf1 tf1
    file rename tf1 td1
    contents [file join td1 tf1]
} -result {tf1}
test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file rename tf1 tf2 tf3
} -result {error renaming: target "tf3" is not a directory}
test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file copy -force -- tf1 tf2 tf3
} -result {error copying: target "tf3" is not a directory}
test fCmd-3.10 {FileCopyRename: just 2 arguments} -constraints notRoot -setup {
    cleanup
} -body {
    createfile tf1 tf1
    file rename tf1 tf2
    contents tf2
} -result {tf1}
test fCmd-3.11 {FileCopyRename: just 2 arguments} -constraints notRoot -setup {
    cleanup
} -body {
    createfile tf1 tf1
    file rename -force -force -- tf1 tf2
    contents tf2
} -result {tf1}
test fCmd-3.12 {FileCopyRename: move each source: 1 source} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1 tf1
    file mkdir td1
    file rename tf1 td1
    contents [file join td1 tf1]
} -result {tf1}
test fCmd-3.13 {FileCopyRename: move each source: multiple sources} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1 tf1
    createfile tf2 tf2
    createfile tf3 tf3
    createfile tf4 tf4
    file mkdir td1
    file rename tf1 tf2 tf3 tf4 td1
    list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
	[contents [file join td1 tf3]] [contents [file join td1 tf4]]
} -result {tf1 tf2 tf3 tf4}
test fCmd-3.14 {FileCopyRename: FileBasename fails} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir td1
    file rename ~_totally_bogus_user td1
} -result {user "_totally_bogus_user" doesn't exist}
test fCmd-3.15 {FileCopyRename: source[0] == '\0'} -setup {
    cleanup
} -constraints {notRoot unixOrPc} -returnCodes error -body {
    file mkdir td1
    file rename / td1
} -result {error renaming "/" to "td1": file already exists}
test fCmd-3.16 {FileCopyRename: break on first error} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf1
    createfile tf2
    createfile tf3
    createfile tf4
    file mkdir td1
    createfile [file join td1 tf3]
    file rename tf1 tf2 tf3 tf4 td1
} -result [subst {error renaming "tf3" to "[file join td1 tf3]": file already exists}]

test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    glob td*
} -result {td1}
test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1 td2 td3
    lsort [glob td*]
} -result {td1 td2 td3}
test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1
    catch {file mkdir td1 td2 tf1 td3 td4}
    glob td1 td2 tf1 td3 td4
} -result {td1 td2 tf1}
test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir ~_totally_bogus_user
} -result {user "_totally_bogus_user" doesn't exist}
test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\0'} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir ""
} -result {can't create directory "": no such file or directory}
test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    glob td1
} -result {td1}
test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir [file join td1 td2 td3 td4]
    glob td1 [file join td1 td2]
} -result "td1 [file join td1 td2]"
test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    set x [file exists td1]
    file mkdir td1
    list $x [file exists td1]
} -result {1 1}
test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf1
    file mkdir tf1
} -result [subst {can't create directory "[file join tf1]": file already exists}]
test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    set x [file exists td1]
    file mkdir td1
    list $x [file exists td1]
} -result {1 1}
test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} -setup {
    cleanup
} -constraints {unix notRoot testchmod} -returnCodes error -body {
    file mkdir td1/td2/td3
    testchmod 000 td1/td2
    file mkdir td1/td2/td3/td4
} -cleanup {
    testchmod 755 td1/td2
    cleanup
} -result {can't create directory "td1/td2/td3": permission denied}
test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} -setup {
    cleanup
} -constraints {notRoot} -body {
    set x [file exists td1]
    file mkdir td1
    list $x [file exists td1]
} -result {0 1}
test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} -setup {
    cleanup
    file delete -force foo
} -constraints {unix notRoot} -body {
    file mkdir foo
    file attr foo -perm 040000
    file mkdir foo/tf1
} -returnCodes error -cleanup {
    file delete -force foo
} -result {can't create directory "foo/tf1": permission denied}
test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir tf1
    file exists tf1
} -result {1}

test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} -constraints {notRoot} -body {
    file delete -xyz
} -returnCodes error -result {bad option "-xyz": must be -force or --}
test fCmd-5.2 {TclFileDeleteCmd: accept 0 files (TIP 323)} -body {
    file delete -force -force
} -result {}
test fCmd-5.3 {TclFileDeleteCmd: 1 file} -constraints {notRoot} -setup {
    cleanup
} -body {
    createfile tf1
    createfile tf2
    file mkdir td1
    file delete tf2
    glob tf* td*
} -result {tf1 td1}
test fCmd-5.4 {TclFileDeleteCmd: multiple files} -constraints notRoot -setup {
    cleanup
} -body {
    createfile tf1
    createfile tf2
    file mkdir td1
    set x [list [file exists tf1] [file exists tf2] [file exists td1]]
    file delete tf1 td1 tf2
    lappend x [file exists tf1] [file exists tf2] [file exists tf3]
} -cleanup {cleanup} -result {1 1 1 0 0 0}
test fCmd-5.5 {TclFileDeleteCmd: stop at first error} -setup {
    cleanup
} -constraints {notRoot unixOrPc} -body {
    createfile tf1
    createfile tf2
    file mkdir td1
    catch {file delete tf1 td1 $root tf2}
    list [file exists tf1] [file exists tf2] [file exists td1]
} -cleanup {cleanup} -result {0 1 0}
test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
    file delete ~_totally_bogus_user
} -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} -setup {
    catch {file delete ~/tf1}
} -constraints {notRoot} -body {
    createfile ~/tf1
    file delete ~/tf1
} -result {}
test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} -setup {
    cleanup
} -constraints {notRoot} -body {
    set x [file exists tf1]
    file delete tf1
    list $x [file exists tf1]
} -result {0 0}
test fCmd-5.9 {TclFileDeleteCmd: is directory} -constraints {notRoot} -setup {
    cleanup
} -body {
    file mkdir td1
    file delete td1
    file exists td1
} -result {0}
test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir [file join td1 td2]
    file delete td1
} -result {error deleting "td1": directory not empty}
test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} -setup {
    cleanup
    set dir [pwd]
} -constraints {notRoot} -body {
    file mkdir [file join td1 td2]
    cd [file join td1 td2]
    set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
    cd $dir
    lappend res [file exists td1] $msg
} -cleanup {
    cd $dir
} -result {0 0 {}}
test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} -setup {
    cleanup
} -constraints {unix} -body {
    file mkdir [file join td1 td2]
    file attributes [file join td1 td2] -permissions u+rwx
    set res [list [catch {file delete -force td1} msg]]
    lappend res [file exists td1] $msg
} -result {0 0 {}}

test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot emptyTest} {
    # can't test this, because it's caught by FileCopyRename
} {}
test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot emptyTest} {
    # can't test this, because it's caught by FileCopyRename
} {}
test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file rename tf1 tf2
} -result {error renaming "tf1": no such file or directory}
test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1
    file rename tf1 tf2
    glob tf*
} -result {tf2}
test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1
    file rename tf1 tf2
    glob tf*
} -result {tf2}
test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} -setup {
    cleanup
} -constraints {unix notRoot testchmod} -body {
    file mkdir td1
    testchmod 000 td1
    createfile tf1
    file rename tf1 td1
} -returnCodes error -cleanup {
    testchmod 755 td1
} -result {error renaming "tf1" to "td1/tf1": permission denied}
test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} -setup {
    cleanup
} -constraints {unix notRoot} -body {
    createfile tf1
    file rename tf1 tf2
    glob tf*
} -result {tf2}
test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 0} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf1
    createfile tf2
    file rename tf1 tf2
} -result {error renaming "tf1" to "tf2": file already exists}
test fCmd-6.11 {CopyRenameOneFile: force == 0} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf1
    createfile tf2
    file rename tf1 tf2
} -result {error renaming "tf1" to "tf2": file already exists}
test fCmd-6.12 {CopyRenameOneFile: force != 0} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile tf1
    createfile tf2
    file rename -force tf1 tf2
    glob tf*
} -result {tf2}
test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir td1
    file mkdir td2
    createfile [file join td2 td1]
    file rename -force td1 td2
} -result [subst {can't overwrite file "[file join td2 td1]" with directory "td1"}]
test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    createfile tf1
    file mkdir [file join td1 tf1]
    file rename -force tf1 td1
} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} -setup {
    cleanup
} -constraints {notRoot notNetworkFilesystem} -body {
    file mkdir [file join td1 td2]
    file mkdir td2
    createfile [file join td2 tf1]
    file rename -force td2 td1
    file exists [file join td1 td2 tf1]
} -result 1
test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir [file join td1 td2]
    createfile [file join td1 td2 tf1]
    file mkdir td2
    file rename -force td2 td1
} -returnCodes error -match glob -result \
    [subst {error renaming "td2" to "[file join td1 td2]": file *}]
test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file rename -force $root tf1
} -result [subst {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}]
test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir [file join td1 td2]
    createfile [file join td1 td2 tf1]
    file mkdir td2
    file rename -force td2 td1
} -returnCodes error -match glob -result \
    [subst {error renaming "td2" to "[file join td1 td2]": file *}]
test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} -setup {
    cleanup $tmpspace
} -constraints {unix notRoot} -body {
    createfile tf1
    file rename tf1 $tmpspace
    glob -nocomplain tf* [file join $tmpspace tf1]
} -result [file join $tmpspace tf1]
test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} -constraints {win} -setup {
    catch {file delete -force c:/tcl8975@ d:/tcl8975@}
} -body {
    file mkdir c:/tcl8975@
    if {[catch {file rename c:/tcl8975@ d:/}]} {
	return d:/tcl8975@
    }
    glob c:/tcl8975@ d:/tcl8975@
} -cleanup {
    file delete -force c:/tcl8975@
    catch {file delete -force d:/tcl8975@}
} -result {d:/tcl8975@}
test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} -setup {
    cleanup $tmpspace
} -constraints {unix notRoot} -body {
    file mkdir td1
    file rename td1 $tmpspace
    glob -nocomplain td* [file join $tmpspace td*]
} -result [file join $tmpspace td1]
test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} -setup {
    cleanup $tmpspace
} -constraints {unix notRoot} -body {
    createfile tf1
    file rename tf1 $tmpspace
    glob -nocomplain tf* [file join $tmpspace tf*]
} -result [file join $tmpspace tf1]
test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
    cleanup $tmpspace
} -constraints {xdev notRoot} -body {
    file mkdir td1/td2/td3
    file attributes td1 -permissions 0000
    file rename td1 $tmpspace
} -returnCodes error -cleanup {
    file attributes td1 -permissions 0755
    cleanup
} -match regexp -result {^error renaming "td1"( to "/tmp/tcl\d+/td1")?: permission denied$}
test fCmd-6.24 {CopyRenameOneFile: error uses original name} -setup {
    cleanup
} -constraints {unix notRoot} -body {
    file mkdir ~/td1/td2
    set td1name [file join [file dirname ~] [file tail ~] td1]
    file attributes $td1name -permissions 0000
    file copy ~/td1 td1
} -returnCodes error -cleanup {
    file attributes $td1name -permissions 0755
    file delete -force ~/td1
} -result {error copying "~/td1": permission denied}
test fCmd-6.25 {CopyRenameOneFile: error uses original name} -setup {
    cleanup
} -constraints {unix notRoot} -body {
    file mkdir td2
    file mkdir ~/td1
    set td1name [file join [file dirname ~] [file tail ~] td1]
    file attributes $td1name -permissions 0000
    file copy td2 ~/td1
} -returnCodes error -cleanup {
    file attributes $td1name -permissions 0755
    file delete -force ~/td1
} -result {error copying "td2" to "~/td1/td2": permission denied}
test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} -setup {
    cleanup
} -constraints {unix notRoot} -body {
    file mkdir ~/td1/td2
    set td2name [file join [file dirname ~] [file tail ~] td1 td2]
    file attributes $td2name -permissions 0000
    file copy ~/td1 td1
} -returnCodes error -cleanup {
    file attributes $td2name -permissions 0755
    file delete -force ~/td1
} -result "error copying \"~/td1\" to \"td1\": \"[file join $::env(HOME) td1 td2]\": permission denied"
test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
    cleanup $tmpspace
} -constraints {notRoot xdev} -returnCodes error -body {
    file mkdir td1/td2/td3
    file mkdir [file join $tmpspace td1]
    createfile [file join $tmpspace td1 tf1]
    file rename -force td1 $tmpspace
} -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": file already exists}
test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
    cleanup $tmpspace
} -constraints {notRoot xdev} -body {
    file mkdir td1/td2/td3
    file attributes td1/td2/td3 -permissions 0000
    file rename td1 $tmpspace
} -returnCodes error -cleanup {
    file attributes td1/td2/td3 -permissions 0755
    cleanup $tmpspace
} -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": "td1/td2/td3": permission denied}
test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} -setup {
    cleanup $tmpspace
} -constraints {notRoot xdev} -body {
    file mkdir td1/td2/td3
    file rename td1 $tmpspace
    glob td* [file join $tmpspace td1 t*]
} -result [file join $tmpspace td1 td2]
test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} -setup {
    cleanup $tmpspace
} -constraints {unix notRoot} -body {
    file mkdir foo/bar
    file attr foo -perm 040555
    file rename foo/bar $tmpspace
} -returnCodes error -cleanup {
    catch {file delete [file join $tmpspace bar]}
    catch {file attr foo -perm 040777}
    catch {file delete -force foo}
} -match glob -result {*: permission denied}
test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} -setup {
    cleanup $tmpspace
} -constraints {notRoot xdev} -body {
    file mkdir [file join $tmpspace td1]
    createfile [file join $tmpspace td1 tf1]
    file rename [file join $tmpspace td1 tf1] tf1
    list [file exists [file join $tmpspace td1 tf1]] [file exists tf1]
} -result {0 1}
test fCmd-6.32 {CopyRenameOneFile: copy} -constraints {notRoot} -setup {
    cleanup
} -returnCodes error -body {
    file copy tf1 tf2
} -result {error copying "tf1": no such file or directory}

test fCmd-7.1 {FileForceOption: none} -constraints {notRoot} -setup {
    cleanup
} -returnCodes error -body {
    file mkdir [file join tf1 tf2]
    file delete tf1
} -result {error deleting "tf1": directory not empty}
test fCmd-7.2 {FileForceOption: -force} -constraints {notRoot} -setup {
    cleanup
} -body {
    file mkdir [file join tf1 tf2]
    file delete -force tf1
} -result {}
test fCmd-7.3 {FileForceOption: --} -constraints {notRoot} -body {
    createfile -tf1
    file delete -- -tf1
} -result {}
test fCmd-7.4 {FileForceOption: bad option} -constraints {notRoot} -setup {
    createfile -tf1
} -body {
    file delete -tf1
} -returnCodes error -cleanup {
    file delete -- -tf1
} -result {bad option "-tf1": must be -force or --}
test fCmd-7.5 {FileForceOption: multiple times through loop} -setup {
    cleanup
} -constraints {notRoot} -body {
    createfile --
    createfile -force
    file delete -force -force -- -- -force
    glob -- -- -force
} -result {}

test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
    -constraints {unix notRoot knownBug} -body {
    # Labelled knownBug because it is dangerous [Bug: 3881]
    file mkdir td1
    file attr td1 -perm 040000
    file rename ~$user td1
} -returnCodes error -cleanup {
    file delete -force td1
} -result "error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied"
test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
	-constraints {unix notRoot} -body {
    string equal [file tail ~$user] ~$user
} -result 0
test fCmd-8.3 {file copy and path translation: ensure correct error} -body {
    file copy ~ [file join this file doesnt exist]
} -returnCodes error -result [subst \
	{error copying "~" to "[file join this file doesnt exist]": no such file or directory}]

test fCmd-9.1 {file rename: comprehensive: EACCES} -setup {
    cleanup
} -constraints {unix notRoot} -body {
    file mkdir td1
    file mkdir td2
    file attr td2 -perm 040000
    file rename td1 td2/
} -returnCodes error -cleanup {
    file delete -force td2
    file delete -force td1
} -result {error renaming "td1" to "td2/td1": permission denied}
test fCmd-9.2 {file rename: comprehensive: source doesn't exist} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file rename tf1 tf2
} -result {error renaming "tf1": no such file or directory}
test fCmd-9.3 {file rename: comprehensive: file to new name} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1
    createfile tf2
    testchmod 444 tf2
    file rename tf1 tf3
    file rename tf2 tf4
    list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
} -result {{tf3 tf4} 1 0}
test fCmd-9.4.a {file rename: comprehensive: dir to new name} -setup {
    cleanup
} -constraints {win win2000orXP testchmod} -body {
    file mkdir td1 td2
    testchmod 555 td2
    file rename td1 td3
    file rename td2 td4
    list [lsort [glob td*]] [file writable td3] [file writable td4]
} -cleanup {
    cleanup
} -result {{td3 td4} 1 0}
test fCmd-9.4.b {file rename: comprehensive: dir to new name} -setup {
    cleanup
} -constraints {unix notRoot testchmod notDarwin9} -body {
    file mkdir td1 td2
    testchmod 555 td2
    file rename td1 td3
    file rename td2 td4
    list [lsort [glob td*]] [file writable td3] [file writable td4]
} -cleanup {
    cleanup
} -result {{td3 td4} 1 0}
test fCmd-9.5 {file rename: comprehensive: file to self} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1 tf1
    createfile tf2 tf2
    testchmod 444 tf2
    file rename -force tf1 tf1
    file rename -force tf2 tf2
    list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
} -result {tf1 tf2 1 0}
test fCmd-9.6.a {file rename: comprehensive: dir to self} -setup {
    cleanup
} -constraints {win win2000orXP testchmod} -body {
    file mkdir td1
    file mkdir td2
    testchmod 555 td2
    file rename -force td1 .
    file rename -force td2 .
    list [lsort [glob td*]] [file writable td1] [file writable td2]
} -result {{td1 td2} 1 0}
test fCmd-9.6.b {file rename: comprehensive: dir to self} -setup {
    cleanup
} -constraints {unix notRoot testchmod} -body {
    file mkdir td1
    file mkdir td2
    testchmod 555 td2
    file rename -force td1 .
    file rename -force td2 .
    list [lsort [glob td*]] [file writable td1] [file writable td2]
} -result {{td1 td2} 1 0}
test fCmd-9.7 {file rename: comprehensive: file to existing file} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1
    createfile tf2
    createfile tfs1
    createfile tfs2
    createfile tfs3
    createfile tfs4
    createfile tfd1
    createfile tfd2
    createfile tfd3
    createfile tfd4
    testchmod 444 tfs3
    testchmod 444 tfs4
    testchmod 444 tfd2
    testchmod 444 tfd4
    set msg [list [catch {file rename tf1 tf2} msg] $msg]
    file rename -force tfs1 tfd1
    file rename -force tfs2 tfd2
    file rename -force tfs3 tfd3
    file rename -force tfs4 tfd4
    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
} -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
test fCmd-9.8 {file rename: comprehensive: dir to empty dir} -setup {
    cleanup
} -constraints {notRoot testchmod notNetworkFilesystem} -body {
    # Under unix, you can rename a read-only directory, but you can't move it
    # into another directory.
    file mkdir td1
    file mkdir [file join td2 td1]
    file mkdir tds1
    file mkdir tds2
    file mkdir tds3
    file mkdir tds4
    file mkdir [file join tdd1 tds1]
    file mkdir [file join tdd2 tds2]
    file mkdir [file join tdd3 tds3]
    file mkdir [file join tdd4 tds4]
    if {![testConstraint unix]} {
	testchmod 555 tds3
	testchmod 555 tds4
    }
    testchmod 555 [file join tdd2 tds2]
    testchmod 555 [file join tdd4 tds4]
    set msg [list [catch {file rename td1 td2} msg] $msg]
    file rename -force tds1 tdd1
    file rename -force tds2 tdd2
    file rename -force tds3 tdd3
    file rename -force tds4 tdd4
    if {[testConstraint unix]} {
	set w3 0
	set w4 0
    } else {
	set w3 [file writable [file join tdd3 tds3]]
	set w4 [file writable [file join tdd4 tds4]]
    }
    list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
    [file writable [file join tdd2 tds2]] $w3 $w4
} -result [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
# Test can hit EEXIST or EBUSY, depending on underlying filesystem
test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    file mkdir tds1
    file mkdir tds2
    file mkdir [file join tdd1 tds1 xxx]
    file mkdir [file join tdd2 tds2 xxx]
    if {!([testConstraint unix] || [testConstraint winVista])} {
	testchmod 555 tds2
    }
    set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
    set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
    if {[testConstraint unix] || [testConstraint winVista]} {
	set w2 0
    } else {
	set w2 [file writable tds2]
    }
    list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
} -match glob -result \
    [subst {{tdd1 tdd2 tds1 tds2} {1 {error renaming "tds1" to "[file join tdd1 tds1]": file *}} {1 {error renaming "tds2" to "[file join tdd2 tds2]": file *}} 1 0}]
test fCmd-9.10 {file rename: comprehensive: file to new name and dir} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1
    createfile tf2
    file mkdir td1
    testchmod 444 tf2
    file rename tf1 [file join td1 tf3]
    file rename tf2 [file join td1 tf4]
    list [glob tf*] [lsort [glob -directory td1 t*]] \
    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
} -result [subst {{} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    file mkdir td1
    file mkdir td2
    file mkdir td3
    if {!([testConstraint unix] || [testConstraint winVista])} {
	testchmod 555 td2
    }
    file rename td1 [file join td3 td3]
    file rename td2 [file join td3 td4]
    if {[testConstraint unix] || [testConstraint winVista]} {
        set w4 0
    } else {
	set w4 [file writable [file join td3 td4]]
    }
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
    [file writable [file join td3 td3]] $w4
} -result [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
test fCmd-9.12 {file rename: comprehensive: target exists} -setup {
    cleanup
} -constraints {notRoot testchmod notNetworkFilesystem} -body {
    file mkdir [file join td1 td2] [file join td2 td1]
    testchmod 555 [file join td2 td1]
    file mkdir [file join td3 td4] [file join td4 td3]
    file rename -force td3 td4
    list [file exists td3] [file exists [file join td4 td3 td4]] \
	[catch {file rename td1 td2} msg] $msg
} -cleanup {
    testchmod 755 [file join td2 td1]
} -result [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
# Test can hit EEXIST or EBUSY, depending on underlying filesystem
test fCmd-9.13 {file rename: comprehensive: can't overwrite target} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir [file join td1 td2] [file join td2 td1 td4]
    file rename -force td1 td2
} -returnCodes error -match glob -result \
    [subst {error renaming "td1" to "[file join td2 td1]": file *}]
test fCmd-9.14 {file rename: comprehensive: dir into self} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
} -result [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
test fCmd-9.14.1 {file rename: comprehensive: dir into self} -setup {
    cleanup
} -constraints {notRoot} -body {
    file mkdir td1
    file rename td1 td1x
    file rename td1x td1
    set msg "ok"
} -result {ok}
test fCmd-9.14.2 {file rename: comprehensive: dir into self} -setup {
    cleanup
    set dir [pwd]
} -constraints {nonPortable notRoot} -body {
    file mkdir td1
    cd td1
    file rename [file join .. td1] [file join .. td1x]
} -returnCodes error -cleanup {
    cd $dir
} -result [subst {error renaming "[file join .. td1]" to "[file join .. td1x]": permission denied}]
test fCmd-9.14.3 {file rename: comprehensive: dir into self} -setup {
    cleanup
    set dir [pwd]
} -constraints {notRoot} -body {
    file mkdir td1
    cd td1
    file rename [file join .. td1] [file join .. td1 foo]
} -returnCodes error -cleanup {
    cd $dir
} -result [subst {error renaming "[file join .. td1]" to "[file join .. td1 foo]": trying to rename a volume or move a directory into itself}]
test fCmd-9.15 {file rename: comprehensive: source and target incompatible} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir td1
    createfile tf1
    file rename -force td1 tf1
} -cleanup {
    cleanup
} -result {can't overwrite file "tf1" with directory "td1"}
test fCmd-9.16 {file rename: comprehensive: source and target incompatible} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir td1/tf1
    createfile tf1
    file rename -force tf1 td1
} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]

test fCmd-10.1 {file copy: comprehensive: source doesn't exist} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file copy tf1 tf2
} -result {error copying "tf1": no such file or directory}
test fCmd-10.2 {file copy: comprehensive: file to new name} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1 tf1
    createfile tf2 tf2
    testchmod 444 tf2
    file copy tf1 tf3
    file copy tf2 tf4
    list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
} -result {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
test fCmd-10.3 {file copy: comprehensive: dir to new name} -setup {
    cleanup
} -constraints {unix notRoot testchmod} -body {
    file mkdir [file join td1 tdx]
    file mkdir [file join td2 tdy]
    testchmod 555 td2
    file copy td1 td3
    file copy td2 td4
    list [lsort [glob td*]] [glob -directory td3 t*] \
	    [glob -directory td4 t*] [file writable td3] [file writable td4]
} -cleanup {
    testchmod 755 td2
    testchmod 755 td4
} -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0]
test fCmd-10.3.1 {file copy: comprehensive: dir to new name} -setup {
    cleanup
} -constraints {win notRoot testchmod} -body {
    # On Windows with ACLs, copying a directory is defined like this
    file mkdir [file join td1 tdx]
    file mkdir [file join td2 tdy]
    testchmod 555 td2
    file copy td1 td3
    file copy td2 td4
    list [lsort [glob td*]] [glob -directory td3 t*] \
	    [glob -directory td4 t*] [file writable td3] [file writable td4]
} -cleanup {
    testchmod 755 td2
    testchmod 755 td4
} -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 1]
test fCmd-10.4 {file copy: comprehensive: file to existing file} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1
    createfile tf2
    createfile tfs1
    createfile tfs2
    createfile tfs3
    createfile tfs4
    createfile tfd1
    createfile tfd2
    createfile tfd3
    createfile tfd4
    testchmod 444 tfs3
    testchmod 444 tfs4
    testchmod 444 tfd2
    testchmod 444 tfd4
    set msg [list [catch {file copy tf1 tf2} msg] $msg]
    file copy -force tfs1 tfd1
    file copy -force tfs2 tfd2
    file copy -force tfs3 tfd3
    file copy -force tfs4 tfd4
    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
} -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
test fCmd-10.5 {file copy: comprehensive: dir to empty dir} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    file mkdir td1
    file mkdir [file join td2 td1]
    file mkdir tds1
    file mkdir tds2
    file mkdir tds3
    file mkdir tds4
    file mkdir [file join tdd1 tds1]
    file mkdir [file join tdd2 tds2]
    file mkdir [file join tdd3 tds3]
    file mkdir [file join tdd4 tds4]
    testchmod 555 tds3
    testchmod 555 tds4
    testchmod 555 [file join tdd2 tds2]
    testchmod 555 [file join tdd4 tds4]
    set a1 [list [catch {file copy td1 td2} msg] $msg]
    set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
    set a3 [catch {file copy -force tds2 tdd2}]
    set a4 [catch {file copy -force tds3 tdd3}]
    set a5 [catch {file copy -force tds4 tdd4}]
    list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5
} -result [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4 tds1 tds2 tds3 tds4} {1 {error copying "td1" to "[file join td2 td1]": file already exists}} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} 1 1 1}]
test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} -setup {
    cleanup
} -constraints {notRoot unixOrPc testchmod} -body {
    file mkdir tds1
    file mkdir tds2
    file mkdir [file join tdd1 tds1 xxx]
    file mkdir [file join tdd2 tds2 xxx]
    testchmod 555 tds2
    set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
    set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
    list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
} -result [subst {{tdd1 tdd2 tds1 tds2} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} {1 {error copying "tds2" to "[file join tdd2 tds2]": file already exists}} 1 0}]
test fCmd-10.7 {file rename: comprehensive: file to new name and dir} -setup {
    cleanup
} -constraints {notRoot testchmod} -body {
    createfile tf1
    createfile tf2
    file mkdir td1
    testchmod 444 tf2
    file copy tf1 [file join td1 tf3]
    file copy tf2 [file join td1 tf4]
    list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
} -result [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} -setup {
    cleanup
} -constraints {unix notRoot testchmod} -body {
    file mkdir td1
    file mkdir td2
    file mkdir td3
    testchmod 555 td2
    file copy td1 [file join td3 td3]
    file copy td2 [file join td3 td4]
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
} -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
test fCmd-10.8.1 {file rename: comprehensive: dir to new name and dir} -setup {
    cleanup
} -constraints {win notRoot testchmod} -body {
    # On Windows with ACLs, copying a directory is defined like this
    file mkdir td1
    file mkdir td2
    file mkdir td3
    testchmod 555 td2
    file copy td1 [file join td3 td3]
    file copy td2 [file join td3 td4]
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
} -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 1}]
test fCmd-10.9 {file copy: comprehensive: source and target incompatible} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir td1
    createfile tf1
    file copy -force td1 tf1
} -result {can't overwrite file "tf1" with directory "td1"}
test fCmd-10.10 {file copy: comprehensive: source and target incompatible} -setup {
    cleanup
} -constraints {notRoot} -returnCodes error -body {
    file mkdir [file join td1 tf1]
    createfile tf1
    file copy -force tf1 td1
} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
test fCmd-10.11 {file copy: copy to empty file name} -setup {
    cleanup
} -returnCodes error -body {
    createfile tf1
    file copy tf1 ""
} -result {error copying "tf1" to "": no such file or directory}
test fCmd-10.12 {file rename: rename to empty file name} -setup {
    cleanup
} -returnCodes error -body {
    createfile tf1
    file rename tf1 ""
} -result {error renaming "tf1" to "": no such file or directory}
cleanup

# old tests

test fCmd-11.1 {TclFileRenameCmd: -- option} -constraints notRoot -setup {
    catch {file delete -force -- -tfa1}
} -body {
    set s [createfile -tfa1]
    file rename -- -tfa1 tfa2
    list [checkcontent tfa2 $s] [file exists -tfa1]
} -cleanup {
    file delete tfa2
} -result {1 0}
test fCmd-11.2 {TclFileRenameCmd: bad option} -constraints notRoot -setup {
    catch {file delete -force -- tfa1}
} -body {
    set s [createfile tfa1]
    list [catch {file rename -x tfa1 tfa2}] \
	[checkcontent tfa1 $s] [file exists tfa2]
} -cleanup {
    file delete tfa1
} -result {1 1 0}
test fCmd-11.3 {TclFileRenameCmd: bad \# args} -returnCodes error -body {
    file rename --
} -match glob -result *
test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints notRoot -body {
    global env
    unset env(HOME)
    catch { file rename tfa ~/foobar }
} -cleanup {
    set ::env(HOME) $temp
} -result 1
test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {notRoot} -body {
    createfile tfa1
    createfile tfa2
    createfile tfa3
    catch {file rename tfa1 tfa2 tfa3}
} -cleanup {
    file delete tfa1 tfa2 tfa3
} -result {1}
test fCmd-11.6 {TclFileRenameCmd: : single file into directory} -setup {
    catch {file delete -force -- tfa1 tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file mkdir tfad
    file rename tfa1 tfad
    list [checkcontent tfad/tfa1 $s] [file exists tfa1]
} -cleanup {
    file delete -force tfad
} -result {1 0}
test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} -setup {
    catch {file delete -force -- tfa1 tfa2 tfad}
} -constraints {notRoot} -body {
    set s1 [createfile tfa1]
    set s2 [createfile tfa2]
    file mkdir tfad
    file rename tfa1 tfa2 tfad
    list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
	[file exists tfa1] [file exists tfa2]
} -cleanup {
    file delete -force tfad
} -result {1 1 0 0}
test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa]
    file mkdir tfad
    file mkdir tfad/tfa
    list [catch {file rename tfa tfad}] [checkcontent tfa $s] [file isdir tfad]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}

#
# Coverage tests for renamefile() ;
#
test fCmd-12.1 {renamefile: source filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    catch {file rename ~/tfa1 tfa2}
} -cleanup {
    set ::env(HOME) $temp
} -result {1}
test fCmd-12.2 {renamefile: src filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    set s [createfile tfa1]
    file mkdir tfad
    catch {file rename tfa1 ~/tfa2 tfad}
} -cleanup {
    set ::env(HOME) $temp
    file delete -force tfad
} -result {1}
test fCmd-12.3 {renamefile: stat failing on source} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    list [catch {file rename tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
} -result {1 0 0}
test fCmd-12.4 {renamefile: error renaming file to directory} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s1 [createfile tfa]
    file mkdir tfad
    file mkdir tfad/tfa
    list [catch {file rename tfa tfad}] [checkcontent tfa $s1] \
	[file isdir tfad/tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}
test fCmd-12.5 {renamefile: error renaming directory to file} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa
    file mkdir tfad
    set s [createfile tfad/tfa]
    list [catch {file rename tfa tfad}] [checkcontent tfad/tfa $s] \
	[file isdir tfad] [file isdir tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1 1}
test fCmd-12.6 {renamefile: TclRenameFile succeeding} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file rename tfa1 tfa2
    list [checkcontent tfa2 $s] [file exists tfa1]
} -cleanup {
    file delete tfa2
} -result {1 0}
test fCmd-12.7 {renamefile: renaming directory into offspring} -setup {
    catch {file delete -force -- tfad}
} -constraints {notRoot} -body {
    file mkdir tfad
    file mkdir tfad/dir
    catch {file rename tfad tfad/dir}
} -cleanup {
    file delete -force tfad
} -result {1}
test fCmd-12.8 {renamefile: generic error} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    file mkdir tfa/dir
    file attributes tfa -permissions 0555
    catch {file rename tfa/dir tfa2}
} -cleanup {
    catch {file attributes tfa -permissions 0777}
    file delete -force tfa
} -result {1}
test fCmd-12.9 {renamefile: moving a file across volumes} -setup {
    cleanup $tmpspace
} -constraints {unix notRoot} -body {
    set s [createfile tfa]
    file rename tfa $tmpspace
    list [checkcontent [file join $tmpspace tfa] $s] [file exists tfa]
} -cleanup {
    cleanup $tmpspace
} -result {1 0}
test fCmd-12.10 {renamefile: moving a directory across volumes} -setup {
    cleanup $tmpspace
} -constraints {xdev notRoot} -body {
    file mkdir tfad
    set s [createfile tfad/a]
    file rename tfad $tmpspace
    list [checkcontent [file join $tmpspace tfad a] $s] [file exists tfad]
} -cleanup {
    cleanup $tmpspace
} -result {1 0}

#
# Coverage tests for TclCopyFilesCmd()
#
test fCmd-13.1 {TclCopyFilesCmd: -force option} -constraints notRoot -setup {
    catch {file delete -force -- tfa1}
} -body {
    set s [createfile tfa1]
    file copy -force  tfa1 tfa2
    list [checkcontent tfa2 $s] [checkcontent tfa1 $s]
} -cleanup {
    file delete tfa1 tfa2
} -result {1 1}
test fCmd-13.2 {TclCopyFilesCmd: -- option} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa1}
} -body {
    set s [createfile -tfa1]
    file copy --  -tfa1 tfa2
    list [checkcontent tfa2 $s] [checkcontent -tfa1 $s]
} -cleanup {
    file delete -- -tfa1 tfa2
} -result {1 1}
test fCmd-13.3 {TclCopyFilesCmd: bad option} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa1}
} -body {
    set s [createfile tfa1]
    list [catch {file copy -x tfa1 tfa2}] \
	[checkcontent tfa1 $s] [file exists tfa2]
} -cleanup {
    file delete tfa1
} -result {1 1 0}
test fCmd-13.4 {TclCopyFilesCmd: bad \# args} -constraints {notRoot} -body {
    file copy --
} -returnCodes error -match glob -result *
test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} -setup {
    set temp $::env(HOME)
} -body {
    global env
    unset env(HOME)
    catch { file copy tfa ~/foobar }
} -cleanup {
    set ::env(HOME) $temp
} -result {1}
test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {notRoot} -body {
    createfile tfa1
    createfile tfa2
    createfile tfa3
    catch {file copy tfa1 tfa2 tfa3}
} -cleanup {
    file delete tfa1 tfa2 tfa3
} -result {1}
test fCmd-13.7 {TclCopyFilesCmd: single file into directory} -setup {
    catch {file delete -force -- tfa1 tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file mkdir tfad
    file copy tfa1 tfad
    list [checkcontent tfad/tfa1 $s] [checkcontent tfa1 $s]
} -cleanup {
    file delete -force tfad tfa1
} -result {1 1}
test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} -setup {
    catch {file delete -force -- tfa1 tfa2 tfad}
} -constraints {notRoot} -body {
    set s1 [createfile tfa1]
    set s2 [createfile tfa2]
    file mkdir tfad
    file copy tfa1 tfa2 tfad
    list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
	[checkcontent tfa1 $s1] [checkcontent tfa2 $s2]
} -cleanup {
    file delete -force tfad tfa1 tfa2
} -result {1 1 1 1}
test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa]
    file mkdir tfad
    file mkdir tfad/tfa
    list [catch {file copy tfa tfad}] [checkcontent tfa $s] \
	[file isdir tfad/tfa] [file isdir tfad]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1 1}

#
# Coverage tests for copyfile()
#
test fCmd-14.1 {copyfile: source filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    catch {file copy ~/tfa1 tfa2}
} -cleanup {
    set ::env(HOME) $temp
} -result {1}
test fCmd-14.2 {copyfile: dst filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    set s [createfile tfa1]
    file mkdir tfad
    list [catch {file copy tfa1 ~/tfa2 tfad}] [checkcontent tfad/tfa1 $s]
} -cleanup {
    set ::env(HOME) $temp
    file delete -force tfa1 tfad
} -result {1 1}
test fCmd-14.3 {copyfile: stat failing on source} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints notRoot -body {
    list [catch {file copy tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
} -result {1 0 0}
test fCmd-14.4 {copyfile: error copying file to directory} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s1 [createfile tfa]
    file mkdir tfad
    file mkdir tfad/tfa
    list [catch {file copy tfa tfad}] [checkcontent tfa $s1] \
	[file isdir tfad] [file isdir tfad/tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1 1}
test fCmd-14.5 {copyfile: error copying directory to file} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa
    file mkdir tfad
    set s [createfile tfad/tfa]
    list [catch {file copy tfa tfad}] [checkcontent tfad/tfa $s] \
	[file isdir tfad] [file isdir tfa]
} -cleanup {
     file delete -force tfa tfad
} -result {1 1 1 1}
test fCmd-14.6 {copyfile: copy file succeeding} -constraints notRoot -setup {
    catch {file delete -force -- tfa tfa2}
} -body {
    set s [createfile tfa]
    file copy tfa tfa2
    list [checkcontent tfa $s] [checkcontent tfa2 $s]
} -cleanup {
    file delete tfa tfa2
} -result {1 1}
test fCmd-14.7 {copyfile: copy directory succeeding} -setup {
    catch {file delete -force -- tfa tfa2}
} -constraints {notRoot} -body {
    file mkdir tfa
    set s [createfile tfa/file]
    file copy tfa tfa2
    list [checkcontent tfa/file $s] [checkcontent tfa2/file $s]
} -cleanup {
    file delete -force tfa tfa2
} -result {1 1}
test fCmd-14.8 {copyfile: copy directory failing} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa/dir/a/b/c
    file attributes tfa/dir -permissions 0000
    catch {file copy tfa tfa2}
} -cleanup {
    file attributes tfa/dir -permissions 0777
    file delete -force tfa tfa2
} -result {1}

#
# Coverage tests for TclMkdirCmd()
#
test fCmd-15.1 {TclMakeDirsCmd: target filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    catch {file mkdir ~/tfa}
} -cleanup {
    set ::env(HOME) $temp
} -result {1}
#
# Can Tcl_SplitPath return argc == 0? If so them we need a test for that code.
#
test fCmd-15.2 {TclMakeDirsCmd - one directory} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    file mkdir tfa
    file isdirectory tfa
} -cleanup {
    file delete tfa
} -result {1}
test fCmd-15.3 {TclMakeDirsCmd: - two directories} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    file mkdir tfa1 tfa2
    list [file isdirectory tfa1] [file isdirectory tfa2]
} -cleanup {
    file delete tfa1 tfa2
} -result {1 1}
test fCmd-15.4 {TclMakeDirsCmd - stat failing} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    createfile tfa/file
    file attributes tfa -permissions 0000
    catch {file mkdir tfa/file}
} -cleanup {
    file attributes tfa -permissions 0777
    file delete -force tfa
} -result {1}
test fCmd-15.5 {TclMakeDirsCmd: - making a directory several levels deep} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    file mkdir tfa/a/b/c
    file isdir tfa/a/b/c
} -cleanup {
    file delete -force tfa
} -result {1}
test fCmd-15.6 {TclMakeDirsCmd: - trying to overwrite a file} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    set s [createfile tfa]
    list [catch {file mkdir tfa}] [file isdir tfa] [file exists tfa] \
	[checkcontent tfa $s]
} -cleanup {
    file delete tfa
} -result {1 0 1 1}
test fCmd-15.7 {TclMakeDirsCmd - making several directories} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    file mkdir tfa1 tfa2/a/b/c
    list [file isdir tfa1] [file isdir tfa2/a/b/c]
} -cleanup {
    file delete -force tfa1 tfa2
} -result {1 1}
test fCmd-15.8 {TclFileMakeDirsCmd: trying to create an existing dir} -body {
    file mkdir tfa
    file mkdir tfa
    file isdir tfa
} -constraints {notRoot} -cleanup {
    file delete tfa
} -result {1}

# Coverage tests for TclDeleteFilesCommand()
test fCmd-16.1 {test the -- argument} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa}
} -body {
    createfile tfa
    file delete -- tfa
    file exists tfa
} -result 0
test fCmd-16.2 {test the -force and -- arguments} -constraints notRoot -setup {
    catch {file delete -force -- tfa}
} -body {
    createfile tfa
    file delete -force -- tfa
    file exists tfa
} -result 0
test fCmd-16.3 {test bad option} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa}
} -body {
    createfile tfa
    catch {file delete -dog tfa}
} -cleanup {
    file delete tfa
} -result {1}
test fCmd-16.4 {accept zero files (TIP 323)} -body {
    file delete
} -result {}
test fCmd-16.5 {accept zero files (TIP 323)} -body {
    file delete --
} -result {}
test fCmd-16.6 {delete: source filename translation failing} -setup {
    set temp $::env(HOME)
} -constraints {notRoot} -body {
    global env
    unset env(HOME)
    catch {file delete ~/tfa}
} -cleanup {
    set ::env(HOME) $temp
} -result {1}
test fCmd-16.7 {remove a non-empty directory without -force} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    file mkdir tfa
    createfile tfa/a
    catch {file delete tfa}
} -cleanup {
    file delete -force tfa
} -result {1}
test fCmd-16.8 {remove a normal file} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa}
} -body {
    file mkdir tfa
    createfile tfa/a
    catch {file delete tfa}
} -cleanup {
    file delete -force tfa
} -result {1}
test fCmd-16.9 {error while deleting file} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    createfile tfa/a
    file attributes tfa -permissions 0555
    catch {file delete tfa/a}
    #######
    #######  If any directory in a tree that is being removed does not have
    #######  write permission, the process will fail! This is also the case
    #######  with "rm -rf"
    #######
} -cleanup {
    file attributes tfa -permissions 0777
    file delete -force tfa
} -result {1}
test fCmd-16.10 {deleting multiple files} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -body {
    createfile tfa1
    createfile tfa2
    file delete tfa1 tfa2
    list [file exists tfa1] [file exists tfa2]
} -result {0 0}
test fCmd-16.11 {TclFileDeleteCmd: removing a nonexistant file} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    file delete tfa
} -result {}

# More coverage tests for mkpath()
test fCmd-17.1 {mkdir stat failing on target but not ENOENT} -setup {
     catch {file delete -force -- tfa1}
} -constraints {unix notRoot} -body {
     file mkdir tfa1
     file attributes tfa1 -permissions 0555
     catch {file mkdir tfa1/tfa2}
} -cleanup {
     file attributes tfa1 -permissions 0777
     file delete -force tfa1
} -result {1}
test fCmd-17.2 {mkdir several levels deep - relative} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    file mkdir tfa/a/b
    file isdir tfa/a/b
} -cleanup {
    file delete tfa/a/b tfa/a tfa
} -result 1
test fCmd-17.3 {mkdir several levels deep - absolute} -setup {
    catch {file delete -force -- tfa}
} -constraints {notRoot} -body {
    set f [file join [pwd] tfa a]
    file mkdir $f
    file isdir $f
} -cleanup {
    file delete $f [file join [pwd] tfa]
} -result {1}

#
# Functionality tests for TclFileRenameCmd()
#
test fCmd-18.1 {TclFileRenameCmd: rename (first form) in the same directory} \
	-setup {
    catch {file delete -force -- tfad}
    set savedDir [pwd]
} -constraints {notRoot} -body {
    file mkdir tfad/dir
    cd tfad/dir
    set s [createfile foo]
    file rename  foo bar
    file rename bar ./foo
    file rename ./foo bar
    file rename ./bar ./foo
    file rename foo ../dir/bar
    file rename ../dir/bar ./foo
    file rename ../../tfad/dir/foo ../../tfad/dir/bar
    file rename [file join [pwd] bar] foo
    file rename foo [file join [pwd] bar]
    list [checkcontent bar $s] [file exists foo]
} -cleanup {
    cd $savedDir
    file delete -force tfad
} -result {1 0}
test fCmd-18.2 {TclFileRenameCmd: single dir to nonexistant} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    file mkdir tfa1
    file rename tfa1 tfa2
    list [file exists tfa2] [file exists tfa1]
} -cleanup {
    file delete tfa2
} -result {1 0}
test fCmd-18.3 {TclFileRenameCmd: mixed dirs and files into directory} -setup {
    catch {file delete -force -- tfa1 tfad1 tfad2}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file mkdir tfad1 tfad2
    file rename tfa1 tfad1 tfad2
    list [checkcontent tfad2/tfa1 $s] [file isdir tfad2/tfad1] \
	[file exists tfa1] [file exists tfad1]
} -cleanup {
    file delete tfad2/tfa1
    file delete -force tfad2
} -result {1 1 0 0}
test fCmd-18.4 {TclFileRenameCmd: attempt to replace non-dir with dir} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa]
    file mkdir tfad
    list [catch {file rename tfad tfa}] [checkcontent tfa $s] [file isdir tfad]
} -cleanup {
    file delete tfa tfad
} -result {1 1 1}
test fCmd-18.5 {TclFileRenameCmd: attempt to replace dir with non-dir} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa]
    file mkdir tfad/tfa
    list [catch {file rename tfa tfad}] [checkcontent tfa $s] \
	[file isdir tfad/tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}
#
# On Windows there is no easy way to determine if two files are the same
#
test fCmd-18.6 {TclFileRenameCmd: rename a file to itself} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    set s [createfile tfa]
    list [catch {file rename tfa tfa}] [checkcontent tfa $s]
} -cleanup {
    file delete tfa
} -result {1 1}
test fCmd-18.7 {TclFileRenameCmd: rename dir on top of another empty dir w/o -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa tfad/tfa
    list [catch {file rename tfa tfad}] [file isdir tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1}
test fCmd-18.8 {TclFileRenameCmd: rename dir on top of another empty dir w/ -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot notNetworkFilesystem} -body {
    file mkdir tfa tfad/tfa
    file rename -force tfa tfad
    file isdir tfa
} -cleanup {
    file delete -force tfad
} -result 0
test fCmd-18.9 {TclFileRenameCmd: rename dir on top of a non-empty dir w/o -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa tfad/tfa/file
    list [catch {file rename tfa tfad}] [file isdir tfa] \
	[file isdir tfad/tfa/file]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}
test fCmd-18.10 {TclFileRenameCmd: rename dir on top of a non-empty dir w/ -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot notNetworkFilesystem} -body {
    file mkdir tfa tfad/tfa/file
    list [catch {file rename -force tfa tfad}] [file isdir tfa] \
	[file isdir tfad/tfa/file]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}
test fCmd-18.11 {TclFileRenameCmd: rename a non-existant file} -setup {
    catch {file delete -force -- tfa1}
} -constraints {notRoot} -body {
    list [catch {file rename tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
} -result {1 0 0}
test fCmd-18.12 {TclFileRenameCmd : rename a symbolic link to file} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {unix notRoot} -body {
    set s [createfile tfa1]
    file link -symbolic tfa2 tfa1
    file rename tfa2 tfa3
    file type tfa3
} -cleanup {
    file delete tfa1 tfa3
} -result link
test fCmd-18.13 {TclFileRenameCmd : rename a symbolic link to dir} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {unix notRoot} -body {
    file mkdir tfa1
    file link -symbolic tfa2 tfa1
    file rename tfa2 tfa3
    file type tfa3
} -cleanup {
    file delete tfa1 tfa3
} -result link
test fCmd-18.14 {TclFileRenameCmd : rename a path with sym link} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {unix notRoot} -body {
    file mkdir tfa1/a/b/c/d
    file mkdir tfa2
    set f [file join [pwd] tfa1/a/b]
    set f2 [file join [pwd] {tfa2/b alias}]
    file link -symbolic $f2 $f
    file rename {tfa2/b alias/c} tfa3
    list [file isdir tfa3] [file exists tfa1/a/b/c]
} -cleanup {
    file delete -force tfa1 tfa2 tfa3
} -result {1 0}
test fCmd-18.15 {TclFileRenameCmd : rename a file to a symlink dir} -setup {
    catch {file delete -force -- tfa1 tfa2 tfalink}
} -constraints {unix notRoot} -body {
    file mkdir tfa1
    set s [createfile tfa2]
    file link -symbolic tfalink tfa1
    file rename tfa2 tfalink
    checkcontent tfa1/tfa2 $s
} -cleanup {
    file delete -force tfa1 tfalink
} -result {1}
test fCmd-18.16 {TclFileRenameCmd: rename a dangling symlink} -setup {
    catch {file delete -force -- tfa1 tfalink}
} -constraints {unix notRoot} -body {
    file mkdir tfa1
    file link -symbolic tfalink tfa1
    file delete tfa1
    file rename tfalink tfa2
    file type tfa2
} -cleanup {
    file delete tfa2
} -result link

#
# Coverage tests for TclUnixRmdir
#
test fCmd-19.1 {remove empty directory} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa}
} -body {
    file mkdir tfa
    file delete tfa
    file exists tfa
} -result {0}
test fCmd-19.2 {rmdir error besides EEXIST} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    file mkdir tfa/a
    file attributes tfa -permissions 0555
    catch {file delete tfa/a}
} -cleanup {
    file attributes tfa -permissions 0777
    file delete -force tfa
} -result {1}
test fCmd-19.3 {recursive remove} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa}
} -body {
    file mkdir tfa
    file mkdir tfa/a
    file delete -force tfa
    file exists tfa
} -result {0}

#
# TclUnixDeleteFile and TraversalDelete are covered by tests from the
# TclDeleteFilesCmd suite
#

#
# Coverage tests for TraverseUnixTree(), called from TclDeleteFilesCmd
#
test fCmd-20.1 {TraverseUnixTree : failure opening a subdirectory directory} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    file mkdir tfa/a
    file attributes tfa/a -permissions 0000
    catch {file delete -force tfa}
} -cleanup {
    file attributes tfa/a -permissions 0777
    file delete -force tfa
} -result {1}
test fCmd-20.2 {TraverseUnixTree : recursive delete of large directory: Bug 1034337} -setup {
    catch {file delete -force -- tfa}
} -constraints {unix notRoot} -body {
    file mkdir tfa
    for {set i 1} {$i <= 300} {incr i} {
	createfile tfa/testfile_$i
    }
    file delete -force tfa
} -cleanup {
    while {[catch {file delete -force tfa}]} {}
} -result {}

#
# Feature testing for TclCopyFilesCmd
#
test fCmd-21.1 {copy : single file to nonexistant} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file copy tfa1 tfa2
    list [checkcontent tfa2 $s] [checkcontent tfa1 $s]
} -cleanup {
    file delete tfa1 tfa2
} -result {1 1}
test fCmd-21.2 {copy : single dir to nonexistant} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    file mkdir tfa1
    file copy tfa1 tfa2
    list [file isdir tfa2] [file isdir tfa1]
} -cleanup {
    file delete tfa1 tfa2
} -result {1 1}
test fCmd-21.3 {copy : single file into directory} -setup {
    catch {file delete -force -- tfa1 tfad}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    file mkdir tfad
    file copy tfa1 tfad
    list [checkcontent tfad/tfa1 $s] [checkcontent tfa1 $s]
} -cleanup {
    file delete -force tfa1 tfad
} -result {1 1}
test fCmd-21.4 {copy : more than one source and target is not a directory} -setup {
    catch {file delete -force -- tfa1 tfa2 tfa3}
} -constraints {notRoot} -body {
    createfile tfa1
    createfile tfa2
    createfile tfa3
    catch {file copy tfa1 tfa2 tfa3}
} -cleanup {
    file delete tfa1 tfa2 tfa3
} -result {1}
test fCmd-21.5 {copy : multiple files into directory} -constraints {notRoot} -setup {
    catch {file delete -force -- tfa1 tfa2 tfad}
} -body {
    set s1 [createfile tfa1]
    set s2 [createfile tfa2]
    file mkdir tfad
    file copy tfa1 tfa2 tfad
    list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
	[checkcontent tfa1 $s1] [checkcontent tfa2 $s2]
} -cleanup {
    file delete -force tfa1 tfa2 tfad
} -result {1 1 1 1}
test fCmd-21.6 {copy: mixed dirs and files into directory} -setup {
    catch {file delete -force -- tfa1 tfad1 tfad2}
} -constraints {notRoot notFileSharing} -body {
    set s [createfile tfa1]
    file mkdir tfad1 tfad2
    file copy tfa1 tfad1 tfad2
    list [checkcontent [file join tfad2 tfa1] $s] \
	[file isdir [file join tfad2 tfad1]] \
	[checkcontent tfa1 $s] [file isdir tfad1]
} -cleanup {
    file delete -force tfa1 tfad1 tfad2
} -result {1 1 1 1}
test fCmd-21.7.1 {TclCopyFilesCmd: copy a dangling link} -setup {
    catch {file delete -force tfad1 tfalink tfalink2}
} -constraints {unix notRoot dontCopyLinks} -body {
    file mkdir tfad1
    file link -symbolic tfalink tfad1
    file delete tfad1
    file copy tfalink tfalink2
} -returnCodes error -cleanup {
    file delete -force tfalink tfalink2
} -result {error copying "tfalink": the target of this link doesn't exist}
test fCmd-21.7.2 {TclCopyFilesCmd: copy a dangling link} -setup {
    catch {file delete -force tfad1 tfalink tfalink2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file link -symbolic tfalink tfad1
    file delete tfad1
    file copy tfalink tfalink2
    file type tfalink2
} -cleanup {
    file delete tfalink tfalink2
} -result link
test fCmd-21.8.1 {TclCopyFilesCmd: copy a link} -setup {
    catch {file delete -force tfad1 tfalink tfalink2}
} -constraints {unix notRoot dontCopyLinks} -body {
    file mkdir tfad1
    file link -symbolic tfalink tfad1
    file copy tfalink tfalink2
    list [file type tfalink] [file type tfalink2] [file isdir tfad1]
} -cleanup {
    file delete -force tfad1 tfalink tfalink2
} -result {link directory 1}
test fCmd-21.8.2 {TclCopyFilesCmd: copy a link} -setup {
    catch {file delete -force tfad1 tfalink tfalink2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file link -symbolic tfalink tfad1
    file copy tfalink tfalink2
    list [file type tfalink] [file type tfalink2] [file isdir tfad1]
} -cleanup {
    file delete -force tfad1 tfalink tfalink2
} -result {link link 1}
test fCmd-21.9 {TclCopyFilesCmd: copy dir with a link in it} -setup {
    catch {file delete -force tfad1 tfad2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file link -symbolic tfad1/tfalink "[pwd]/tfad1"
    file copy tfad1 tfad2
    file type tfad2/tfalink
} -cleanup {
    file delete -force tfad1 tfad2
} -result link
test fCmd-21.10 {TclFileCopyCmd: copy dir on top of another empty dir w/o -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa [file join tfad tfa]
    list [catch {file copy tfa tfad}] [file isdir tfa]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1}
test fCmd-21.11 {TclFileCopyCmd: copy dir on top of a dir w/o -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa [file join tfad tfa file]
    list [catch {file copy tfa tfad}] [file isdir tfa] \
	[file isdir [file join tfad tfa file]]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}
test fCmd-21.12 {TclFileCopyCmd: copy dir on top of a non-empty dir w/ -force} -setup {
    catch {file delete -force -- tfa tfad}
} -constraints {notRoot} -body {
    file mkdir tfa [file join tfad tfa file]
    list [catch {file copy -force tfa tfad}] [file isdir tfa] \
	[file isdir [file join tfad tfa file]]
} -cleanup {
    file delete -force tfa tfad
} -result {1 1 1}

#
# Coverage testing for TclpRenameFile
#
test fCmd-22.1 {TclpRenameFile: rename and overwrite in a single dir} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    set s2 [createfile tfa2 q]
    set result [catch {file rename tfa1 tfa2}]
    file rename -force tfa1 tfa2
    lappend result [checkcontent tfa2 $s]
} -cleanup {
    file delete [glob tfa1 tfa2]
} -result {1 1}
test fCmd-22.2 {TclpRenameFile: attempt to overwrite itself} -setup {
    catch {file delete -force -- tfa1}
} -constraints {unix notRoot} -body {
    set s [createfile tfa1]
    file rename -force tfa1 tfa1
    checkcontent tfa1 $s
} -cleanup {
    file delete tfa1
} -result {1}
test fCmd-22.3 {TclpRenameFile: rename dir to existing dir} -setup {
    catch {file delete -force -- d1 tfad}
} -constraints {notRoot} -body {
    file mkdir d1 [file join tfad d1]
    list [catch {file rename d1 tfad}] [file isdir d1] \
	[file isdir [file join tfad d1]]
} -cleanup {
    file delete -force d1 tfad
} -result {1 1 1}
test fCmd-22.4 {TclpRenameFile: rename dir to dir several levels deep} -setup {
    catch {file delete -force -- d1 tfad}
} -constraints {notRoot} -body {
    file mkdir d1 [file join tfad a b c]
    file rename d1 [file join tfad a b c d1]
    list [file isdir d1] [file isdir [file join tfad a b c d1]]
} -cleanup {
    file delete -force [glob d1 tfad]
} -result {0 1}
#
# TclMacCopyFile needs to be redone.
#
test fCmd-22.5 {TclMacCopyFile: copy and overwrite in a single dir} -setup {
    catch {file delete -force -- tfa1 tfa2}
} -constraints {notRoot} -body {
    set s [createfile tfa1]
    set s2 [createfile tfa2 q]
    set result [catch {file copy tfa1 tfa2}]
    file copy -force tfa1 tfa2
    lappend result [checkcontent tfa2 $s] [checkcontent tfa1 $s]
} -cleanup {
    file delete tfa1 tfa2
} -result {1 1 1}

#
# TclMacMkdir - basic cases are covered elsewhere.
# Error cases are not covered.
#

#
# TclMacRmdir
# Error cases are not covered.
#
test fCmd-23.1 {TclMacRmdir: trying to remove a nonempty directory} -setup {
    catch {file delete -force -- tfad}
} -constraints {notRoot} -body {
    file mkdir [file join tfad dir]
    list [catch {file delete tfad}] [file delete -force tfad]
} -cleanup {
    catch {file delete -force tfad}
} -result {1 {}}

#
# TclMacDeleteFile
# Error cases are not covered.
#
test fCmd-24.1 {TclMacDeleteFile: deleting a normal file} -setup {
    catch {file delete -force -- tfa1}
} -constraints {notRoot} -body {
    createfile tfa1
    file delete tfa1
    file exists tfa1
} -cleanup {
    catch {file delete -force tfa1}
} -result {0}

#
# TclMacCopyDirectory
# Error cases are not covered.
#
test fCmd-25.1 {TclMacCopyDirectory: copying a normal directory} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {notRoot notFileSharing} -body {
    file mkdir [file join tfad1 a b c]
    file copy tfad1 tfad2
    list [file isdir [file join tfad1 a b c]] \
	[file isdir [file join tfad2 a b c]]
} -cleanup {
    file delete -force tfad1 tfad2
} -result {1 1}
test fCmd-25.2 {TclMacCopyDirectory: copying a short path normal directory} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {notRoot notFileSharing} -body {
    file mkdir tfad1
    file copy tfad1 tfad2
    list [file isdir tfad1] [file isdir tfad2]
} -cleanup {
    file delete tfad1 tfad2
} -result {1 1}
test fCmd-25.3 {TclMacCopyDirectory: copying dirs between different dirs} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {notRoot notFileSharing} -body {
    file mkdir [file join tfad1 x y z]
    file mkdir [file join tfad2 dir]
    file copy tfad1 [file join tfad2 dir]
    list [file isdir [file join tfad1 x y z]] \
	[file isdir [file join tfad2 dir tfad1 x y z]]
} -cleanup {
    file delete -force tfad1 tfad2
} -result {1 1}

#
# Functionality tests for TclDeleteFilesCmd
#
test fCmd-26.1 {TclDeleteFilesCmd: delete symlink} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file link -symbolic tfalink tfad1
    file delete tfalink
    list [file isdir tfad1] [file exists tfalink]
} -cleanup {
    file delete tfad1
    catch {file delete tfalink}
} -result {1 0}
test fCmd-26.2 {TclDeleteFilesCmd: delete dir with symlink} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file mkdir tfad2
    file link -symbolic [file join tfad2 link] [file join .. tfad1]
    file delete -force tfad2
    list [file isdir tfad1] [file exists tfad2]
} -cleanup {
    file delete tfad1
} -result {1 0}
test fCmd-26.3 {TclDeleteFilesCmd: delete dangling symlink} -setup {
    catch {file delete -force -- tfad1 tfad2}
} -constraints {unix notRoot} -body {
    file mkdir tfad1
    file link -symbolic tfad2 tfad1
    file delete tfad1
    file delete tfad2
    list [file exists tfad1] [file exists tfad2]
} -result {0 0}

# There is no fCmd-27.1
test fCmd-27.2 {TclFileAttrsCmd - Tcl_TranslateFileName fails} -setup {
    set platform [testgetplatform]
} -constraints {testsetplatform} -body {
    testsetplatform unix
    file attributes ~_totally_bogus_user
} -returnCodes error -cleanup {
    testsetplatform $platform
} -result {user "_totally_bogus_user" doesn't exist}
test fCmd-27.3 {TclFileAttrsCmd - all attributes} -setup {
    catch {file delete -force -- foo.tmp}
} -body {
    createfile foo.tmp
    file attributes foo.tmp
    # Must be non-empty result
} -cleanup {
    file delete -force -- foo.tmp
} -match glob -result {?*}
test fCmd-27.4 {TclFileAttrsCmd - getting one option} -setup {
    catch {file delete -force -- foo.tmp}
} -body {
    createfile foo.tmp
    set attrs [file attributes foo.tmp]
    file attributes foo.tmp {*}[lindex $attrs 0]
    # Any successful result will do
} -cleanup {
    file delete -force -- foo.tmp
} -match glob -result *
test fCmd-27.5 {TclFileAttrsCmd - setting one option} -setup {
    catch {file delete -force -- foo.tmp}
} -constraints {foundGroup} -body {
    createfile foo.tmp
    set attrs [file attributes foo.tmp]
    file attributes foo.tmp {*}[lrange $attrs 0 1]
} -cleanup {
    file delete -force -- foo.tmp
} -result {}
test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} -setup {
    catch {file delete -force -- foo.tmp}
} -constraints {foundGroup} -body {
    createfile foo.tmp
    set attrs [file attributes foo.tmp]
    file attributes foo.tmp {*}[lrange $attrs 0 3]
} -cleanup {
    file delete -force -- foo.tmp
} -result {}

if {
    [testConstraint win] &&
    ([string index $tcl_platform(osVersion) 0] < 5
     || [lindex [file system [temporaryDirectory]] 1] ne "NTFS")
} then {
    testConstraint linkDirectory 0
    testConstraint linkFile 0
}

test fCmd-28.1 {file link} -returnCodes error -body {
    file link
} -result {wrong # args: should be "file link ?-linktype? linkname ?target?"}
test fCmd-28.2 {file link} -returnCodes error -body {
    file link a b c d
} -result {wrong # args: should be "file link ?-linktype? linkname ?target?"}
test fCmd-28.3 {file link} -returnCodes error -body {
    file link abc b c
} -result {bad switch "abc": must be -symbolic or -hard}
test fCmd-28.4 {file link} -returnCodes error -body {
    file link -abc b c
} -result {bad switch "-abc": must be -symbolic or -hard}
cd [workingDirectory]
makeDirectory abc.dir
makeDirectory abc2.dir
makeFile contents abc.file
makeFile contents abc2.file
cd [temporaryDirectory]
test fCmd-28.5 {file link: source already exists} -setup {
    cd [temporaryDirectory]
} -constraints {linkDirectory} -body {
    file link abc.dir abc2.dir
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "abc.dir": that path already exists}
test fCmd-28.6 {file link: unsupported operation} -setup {
    cd [temporaryDirectory]
} -constraints {linkDirectory win} -body {
    file link -hard abc.link abc.dir
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "abc.link" pointing to "abc.dir": illegal operation on a directory}
test fCmd-28.7 {file link: source already exists} -setup {
    cd [temporaryDirectory]
} -constraints {linkFile} -body {
    file link abc.file abc2.file
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "abc.file": that path already exists}
test fCmd-28.8 {file link} -constraints {linkFile win} -setup {
    cd [temporaryDirectory]
} -body {
    file link -symbolic abc.link abc.file
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "abc.link" pointing to "abc.file": not a directory}
test fCmd-28.9 {file link: success with file} -constraints {linkFile} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -body {
    file link abc.link abc.file
} -cleanup {
    cd [workingDirectory]
} -result abc.file
test fCmd-28.9.1 {file link: success with file} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkFile win} -body {
    file stat abc.file arr
    set res $arr(nlink)
    lappend res [catch {file link abc.link abc.file} msg] $msg
    file stat abc.file arr
    lappend res $arr(nlink)
} -cleanup {
    cd [workingDirectory]
} -result {1 0 abc.file 2}
cd [temporaryDirectory]
catch {file delete -force abc.link}
cd [workingDirectory]
test fCmd-28.10 {file link: linking to nonexistent path} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link abc.link abc2.doesnt
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "abc.link": target "abc2.doesnt" doesn't exist}
test fCmd-28.10.1 {file link: linking to nonexistent path} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link doesnt/abc.link abc.dir
} -returnCodes error -cleanup {
    cd [workingDirectory]
} -result {could not create new link "doesnt/abc.link": no such file or directory}
test fCmd-28.11 {file link: success with directory} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link abc.link abc.dir
} -cleanup {
    cd [workingDirectory]
} -result abc.dir
test fCmd-28.12 {file link: cd into a link} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link abc.link abc.dir
    set orig [pwd]
    cd abc.link
    set dir [pwd]
    cd ..
    set up [pwd]
    cd $orig
    # Now '$up' should be either $orig or [file dirname abc.dir], depending on
    # whether 'cd' actually moves to the destination of a link, or simply
    # treats the link as a directory. (On windows the former, on unix the
    # latter, I believe)
    if {
	([file normalize $up] ne [file normalize $orig]) &&
	([file normalize $up] ne [file normalize [file dirname abc.dir]])
    } then {
	return "wrong directory with 'cd abc.link ; cd ..': \
		\"[file normalize $up]\" should be \"[file normalize $orig]\"\
		or \"[file normalize [file dirname abc.dir]]\""
    } else {
	return "ok"
    }
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result ok
test fCmd-28.13 {file link} -constraints {linkDirectory} -setup {
    cd [temporaryDirectory]
    file link abc.link abc.dir
} -body {
    # duplicate link throws error
    file link abc.link abc.dir
} -returnCodes error -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result {could not create new link "abc.link": that path already exists}
test fCmd-28.14 {file link: deletes link not dir} -setup {
    cd [temporaryDirectory]
} -constraints {linkDirectory} -body {
    file delete -force abc.link
    list [file exists abc.link] [file exists abc.dir]
} -cleanup {
    cd [workingDirectory]
} -result {0 1}
test fCmd-28.15.1 {file link: copies link not dir} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory dontCopyLinks} -body {
    file link abc.link abc.dir
    file copy abc.link abc2.link
    # abc2.linkdir was a copy of a link to a dir, so it should end up as a
    # directory, not a link (links trace to endpoint).
    list [file type abc2.link] [file tail [file link abc.link]]
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result {directory abc.dir}
test fCmd-28.15.2 {file link: copies link not dir} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link abc.link abc.dir
    file copy abc.link abc2.link
    list [file type abc2.link] [file tail [file link abc2.link]]
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result {link abc.dir}
cd [temporaryDirectory]
file delete -force abc.link
file delete -force abc2.link
cd abc.dir
file delete -force abc.file
file delete -force abc2.file
cd ..
file copy abc.file abc.dir
file copy abc2.file abc.dir
cd [workingDirectory]
test fCmd-28.16 {file link: glob inside link} -setup {
    cd [temporaryDirectory]
    file delete -force abc.link
} -constraints {linkDirectory} -body {
    file link abc.link abc.dir
    lsort [glob -dir abc.link -tails *]
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result {abc.file abc2.file}
test fCmd-28.17 {file link: glob -type l} -setup {
    cd [temporaryDirectory]
    file link abc.link abc.dir
} -constraints {linkDirectory} -body {
    glob -dir [pwd] -type l -tails abc*
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result {abc.link}
test fCmd-28.18 {file link: glob -type d} -constraints linkDirectory -setup {
    cd [temporaryDirectory]
    file link abc.link abc.dir
} -body {
    lsort [glob -dir [pwd] -type d -tails abc*]
} -cleanup {
    file delete -force abc.link
    cd [workingDirectory]
} -result [lsort [list abc.link abc.dir abc2.dir]]
test fCmd-28.19 {file link: relative paths} -setup {
    cd [temporaryDirectory]
} -constraints {win linkDirectory} -body {
    file mkdir d1/d2/d3
    file link d1/l2 d1/d2
} -cleanup {
    catch {file delete -force d1}
    cd [workingDirectory]
} -result d1/d2
test fCmd-28.20 {file link: relative paths} -setup {
    cd [temporaryDirectory]
} -constraints {unix linkDirectory} -body {
    file mkdir d1/d2/d3
    file link d1/l2 d1/d2
} -returnCodes error -cleanup {
    catch {file delete -force d1}
    cd [workingDirectory]
} -result {could not create new link "d1/l2": target "d1/d2" doesn't exist}
test fCmd-28.21 {file link: relative paths} -setup {
    cd [temporaryDirectory]
} -constraints {unix linkDirectory} -body {
    file mkdir d1/d2/d3
    file link d1/l2 d2
} -cleanup {
    catch {file delete -force d1}
    cd [workingDirectory]
} -result d2
test fCmd-28.22 {file link: relative paths} -setup {
    cd [temporaryDirectory]
} -constraints {unix linkDirectory} -body {
    file mkdir d1/d2/d3
    catch {file delete -force d1/l2}
    file link d1/l2 d2/d3
} -cleanup {
    catch {file delete -force d1}
    cd [workingDirectory]
} -result d2/d3
try {
    cd [temporaryDirectory]
    file delete -force abc.link
    file delete -force d1/d2
    file delete -force d1
} finally {
    cd [workingDirectory]
}
removeFile abc2.file
removeFile abc.file
removeDirectory abc2.dir
removeDirectory abc.dir

test fCmd-29.1 {weird memory corruption fault} -body {
    open [file join ~a_totally_bogus_user_id/foo bar]
} -returnCodes error -match glob -result *

test fCmd-30.1 {file writable on 'My Documents'} -setup {
    # Get the localized version of the folder name by looking in the registry.
    set mydocsname [registry get {HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders} Personal]
} -constraints {win reg} -body {
    file writable $mydocsname
} -result 1
test fCmd-30.2 {file readable on 'NTUSER.DAT'} -constraints {win} -body {
    expr {[info exists env(USERPROFILE)]
          && [file exists $env(USERPROFILE)/NTUSER.DAT]
          && [file readable $env(USERPROFILE)/NTUSER.DAT]}
} -result {1}
test fCmd-30.3 {file readable on 'pagefile.sys'} -constraints {win} -body {
    set r {}
    if {[info exists env(SystemDrive)]} {
        set path $env(SystemDrive)/pagefile.sys
        lappend r exists [file exists $path]
        lappend r readable [file readable $path]
        lappend r stat [catch {file stat $path a} e] $e
    }
    return $r
} -result {exists 1 readable 0 stat 0 {}}

# cleanup
cleanup
if {[testConstraint unix]} {
    removeDirectory tcl[pid] /tmp
}
::tcltest::cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End: