summary refs log tree commit diff stats
path: root/tests/stdlib/tpathnorm.nim
Commit message (Collapse)AuthorAgeFilesLines
* make more standard libraries work with `nimPreviewSlimSystem` (#20343)ringabout2022-09-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * make more standard libraries work with `nimPreviewSlimSystem` * typo * part two * Delete specutils.nim * fixes more tests * more fixes * fixes tests * fixes three more tests * add formatfloat import * fix * last
* Add improved Windows UNC path support in std/os (#20281)havardjohn2022-09-031-0/+34
* Add improved Windows UNC path support in std/os Original issue: `std/os.createDir` tries to create every component of the given path as a directory. The problem is that `createDir` interprets every backslash/slash as a path separator. For a UNC path this is incorrect. E.g. one UNC form is `\\Server\Volume\Path`. It's an error to create the `\\Server` directory, as well as creating `\\Server\Volume`. Add `ntpath.nim` module with `splitDrive` proc. This implements UNC path parsing as implemented in the Python `ntpath.py` module. The following UNC forms are supported: * `\\Server\Volume\Path` * `\\?\Volume\Path` * `\\?\UNC\Server\Volume\Path` Improves support for UNC paths in various procs in `std/os`: --- * pathnorm.addNormalizePath * Issue: This had incomplete support for UNC paths * The UNC prefix (first 2 characters of a UNC path) was assumed to be exactly `\\`, but it can be `//` and `\/`, etc. as well * Also, the UNC prefix must be normalized to the `dirSep` argument of `addNormalizePath` * Resolution: Changed to account for different UNC prefixes, and normalizing the prefixes according to `dirSep` * Affected procs that get tests: `relativePath`, `joinPath` * Issue: The server/volume part of UNC paths can be stripped when normalizing `..` path components * This error should be negligable, so ignoring this * splitPath * Now make sure the UNC drive is not split; return the UNC drive as `head` if the UNC drive is the only component of the path * Consequently fixes `extractFilename`, `lastPathPart` * parentDir / `/../` * Strip away drive before working on the path, prepending the drive after all work is done - prevents stripping UNC components * Return empty string if drive component is the only component; this is the behavior for POSIX paths as well * Alternative implementation: Just call something like `pathnorm.normalizePath(path & "/..")` for the whole proc - maybe too big of a change * tailDir * If drive is present in path, just split that from path and return path * parentDirs iterator * Uses `parentDir` for going backwards * When going forwards, first `splitDrive`, yield the drive field, and then iterate over path field as normal * splitFile * Make sure path parsing stops at end of drive component * createDir * Fixed by skipping drive part before creating directories * Alternative implementation: use `parentDirs` iterator instead of iterating over characters * Consequence is that it will try to create the root directory * isRootDir * Changed to treat UNC drive alone as root (e.g. "//?/c:" is root) * This change prevents the empty string being yielded by the `parentDirs` iterator with `fromRoot = false` * Internal `sameRoot` * The "root" refers to the drive, so `splitDrive` can be used here This adds UNC path support to all procs that could use it in std/os. I don't think any more work has to be done to support UNC paths. For the future, I believe the path handling code can be refactored due to duplicate code. There are multiple ways of manipulating paths, such as manually searching string for path separator and also having a path normalizer (pathnorm.nim). If all path manipulation used `pathnorm.nim`, and path component splitting used `parentDirs` iterator, then a lot of code could be removed. Tests --- Added test file for `pathnorm.nim` and `ntpath.nim`. `pathnorm.normalizePath` has no tests, so I'm adding a few unit tests. `ntpath.nim` contains tests copied from Python's test suite. Added integration tests to `tos.nim` that tests UNC paths. Removed incorrect `relativePath` runnableExamples from being tested on Windows: --- `relativePath("/Users///me/bar//z.nim", "//Users/", '/') == "me/bar/z.nim"` This is incorrect on Windows because the `/` and `//` are not the same root. `/` (or `\`) is expanded to the drive in the current working directory (e.g. `C:\`). `//` (or `\\`), however, are the first two characters of a UNC path. The following holds true for normal Windows installations: * `dirExists("/Users") != dirExists("//Users")` * `dirExists("\\Users") != dirExists("\\\\Users")` Fixes #19103 Questions: --- * Should the `splitDrive` proc be in `os.nim` instead with copyright notice above the proc? * Is it fine to put most of the new tests into the `runnableExamples` section of the procs in std/os? * [skipci] Apply suggestions from code review Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * [skip ci] Update lib/pure/os.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * Move runnableExamples tests in os.nim to tos.nim * tests/topt_no_cursor: Change from using splitFile to splitDrive `splitFile` can no longer be used in the test, because it generates different ARC code on Windows and Linux. This replaces `splitFile` with `splitDrive`, because it generates same ARC code on Windows and Linux, and returns a tuple. I assume the test wants a proc that returns a tuple. * Drop copyright attribute to Python Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
c48813e79d87429ca'>3473c63a ^
15936c91 ^
c6520d96 ^
9dcbec39 ^
c6520d96 ^

c6034af3 ^
2b250717 ^
c6520d96 ^


af023b32 ^

2b250717 ^
c6520d96 ^

af023b32 ^


9dcbec39 ^
c6520d96 ^

b8515e8a ^



3473c63a ^
15936c91 ^
b24eb476 ^
af023b32 ^



2efceef6 ^
a89c1bed ^
b8348923 ^
b24eb476 ^
23d3a022 ^
c6520d96 ^
4234040b ^
795f5244 ^
b8348923 ^
59874868 ^

c6520d96 ^

d160a8e1 ^
5497090a ^
7e9c6925 ^
b8348923 ^



1ead3562 ^
192d59d3 ^




d160a8e1 ^
57699011 ^



d160a8e1 ^
9edabeaa ^
1ead3562 ^
192d59d3 ^




9edabeaa ^


93d4cc93 ^



1211a3ab ^
1fb0cf9e ^
c6034af3 ^
1b76245c ^
49659e72 ^
3076bab4 ^
9f7f62ed ^
49659e72 ^
a55bbd06 ^
f4647409 ^
1fb0cf9e ^
f4647409 ^

93d4cc93 ^

f4647409 ^
93d4cc93 ^
f4647409 ^




b8348923 ^

1211a3ab ^
1fb0cf9e ^
b8348923 ^
758e0fc6 ^
c36eb25c ^


8dccf184 ^
c36eb25c ^
192d59d3 ^
c36eb25c ^


f7c58ffd ^




a0b9fa55 ^
c36eb25c ^

192d59d3 ^
c36eb25c ^
9dcbec39 ^
c36eb25c ^
f7c58ffd ^











93d4cc93 ^
f7c58ffd ^



758e0fc6 ^

8dccf184 ^

1211a3ab ^
8dccf184 ^






192d59d3 ^

8dccf184 ^

192d59d3 ^

8dccf184 ^


1e76d01d ^
5c0e5492 ^
1e76d01d ^
192d59d3 ^
1e76d01d ^
d63cddea ^
1e76d01d ^
192d59d3 ^
1e76d01d ^


7284d503 ^

88be3dbc ^
1ead3562 ^
192d59d3 ^



23d3a022 ^
7e9c6925 ^
23d3a022 ^
7e9c6925 ^
af023b32 ^


23d3a022 ^






af023b32 ^
23d3a022 ^

af023b32 ^
88be3dbc ^
1ead3562 ^
192d59d3 ^



23d3a022 ^

07d35c4a ^
23d3a022 ^
07d35c4a ^
1848b18f ^

a55bbd06 ^
795f5244 ^
b8515e8a ^
a55bbd06 ^
b8515e8a ^
2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^
1ad3fe9e ^
9dcbec39 ^
18e626df ^

3473c63a ^
15936c91 ^

9dcbec39 ^
15936c91 ^

fb85b3b4 ^
3473c63a ^
15936c91 ^
090cad5c ^
bb7142db ^
9dcbec39 ^
fb85b3b4 ^

b8515e8a ^



3473c63a ^
15936c91 ^
b24eb476 ^
263e6b2a ^
18e626df ^
2b250717 ^
46026f62 ^

3473c63a ^
15936c91 ^

15936c91 ^
2b250717 ^
551d155c ^

090cad5c ^
9f7f62ed ^


fb1fcbc9 ^

a55bbd06 ^


7e9c6925 ^
3377364a ^
9f7f62ed ^



3377364a ^
93d4cc93 ^








9f7f62ed ^
93d4cc93 ^
9f7f62ed ^
7e9c6925 ^

b8348923 ^
34068eb3 ^
93d4cc93 ^


91ec4681 ^
93d4cc93 ^
b8348923 ^
93d4cc93 ^
b8348923 ^


34068eb3 ^
91ec4681 ^




23d3a022 ^
91ec4681 ^



93d4cc93 ^




cb48c5d7 ^





23d3a022 ^
cb48c5d7 ^

23d3a022 ^
cb48c5d7 ^
551d155c ^
5f98a10c ^
1ead3562 ^
23d3a022 ^

551d155c ^
23d3a022 ^
551d155c ^
051c4738 ^
5f98a10c ^
1ead3562 ^
23d3a022 ^

551d155c ^
23d3a022 ^
a55bbd06 ^
fb85b3b4 ^
5f98a10c ^
1ead3562 ^
fb85b3b4 ^
23d3a022 ^
fb85b3b4 ^
23d3a022 ^
fb85b3b4 ^
5c6840b8 ^


1ead3562 ^
192d59d3 ^
192d59d3 ^
5c6840b8 ^


991d76f3 ^
1848b18f ^
991d76f3 ^
1ead3562 ^
192d59d3 ^
192d59d3 ^
1848b18f ^
991d76f3 ^
1848b18f ^

991d76f3 ^
a55bbd06 ^
991d76f3 ^
b8515e8a ^
991d76f3 ^

2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^
1ad3fe9e ^
9dcbec39 ^
46026f62 ^

3473c63a ^
15936c91 ^

9dcbec39 ^
991d76f3 ^

3473c63a ^
15936c91 ^
090cad5c ^
991d76f3 ^
9dcbec39 ^
fb85b3b4 ^

fc19980d ^

0d219477 ^


fc19980d ^
b8515e8a ^


991d76f3 ^
3473c63a ^
15936c91 ^
b24eb476 ^
18e626df ^
2b250717 ^
18e626df ^

3473c63a ^
15936c91 ^

15936c91 ^
2b250717 ^
551d155c ^

9f7f62ed ^
991d76f3 ^


59874868 ^
991d76f3 ^
6e793202 ^
6c96a437 ^
a89c1bed ^
991d76f3 ^

59874868 ^
a55bbd06 ^
c8a58cdc ^
991d76f3 ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
991d76f3 ^

551d155c ^
9393ccc8 ^
551d155c ^
991d76f3 ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
23d3a022 ^

551d155c ^
23d3a022 ^
551d155c ^
0d219477 ^


192d59d3 ^

0d219477 ^
192d59d3 ^
0d219477 ^
c8a58cdc ^


1ead3562 ^
192d59d3 ^
23d3a022 ^
c8a58cdc ^
23d3a022 ^
c8a58cdc ^



795f5244 ^
b8515e8a ^
c8a58cdc ^
b8515e8a ^
2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^

9dcbec39 ^
c8a58cdc ^

b8515e8a ^



3473c63a ^
15936c91 ^

2b250717 ^
18e626df ^

cfb142b9 ^
15936c91 ^
c8a58cdc ^

e74a2940 ^




991d76f3 ^
e74a2940 ^
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