mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
* Implement Unix file regularity check * update std/dirs also
This commit is contained in:
@@ -4,7 +4,7 @@ discard """
|
||||
"""
|
||||
|
||||
import os, strutils
|
||||
import std/syncio
|
||||
import std/[syncio, assertions]
|
||||
# Cases
|
||||
# 1 - String : Existing File : Symlink true
|
||||
# 2 - String : Existing File : Symlink false
|
||||
@@ -127,10 +127,37 @@ proc testGetFileInfo =
|
||||
echo pcLinkToDir
|
||||
echo pcLinkToFile
|
||||
|
||||
doAssert dirInfo.isRegular == true
|
||||
doAssert fileInfo.isRegular == true
|
||||
when defined(posix):
|
||||
doAssert linkDirInfo.isRegular == true
|
||||
doAssert linkFileInfo.isRegular == true
|
||||
|
||||
removeDir(dirPath)
|
||||
removeFile(filePath)
|
||||
when defined(posix):
|
||||
removeFile(linkDirPath)
|
||||
removeFile(linkFilePath)
|
||||
|
||||
# Test that `isRegular` is set correctly
|
||||
block:
|
||||
when defined(posix):
|
||||
let
|
||||
tmp = getTempDir()
|
||||
fifoPath = tmp / "test-fifo"
|
||||
linkFifoPath = tmp / "test-link-fifo"
|
||||
|
||||
doAssert execShellCmd("mkfifo " & fifoPath) == 0
|
||||
createSymlink(fifoPath, linkFifoPath)
|
||||
|
||||
let
|
||||
fifoInfo = getFileInfo(fifoPath)
|
||||
linkFifoInfo = getFileInfo(linkFifoPath)
|
||||
|
||||
doAssert fifoInfo.isRegular == false
|
||||
doAssert linkFifoInfo.isRegular == false
|
||||
|
||||
removeFile(fifoPath)
|
||||
removeFile(linkFifoPath)
|
||||
|
||||
testGetFileInfo()
|
||||
|
||||
@@ -344,6 +344,8 @@ block walkDirRec:
|
||||
|
||||
removeDir("walkdir_test")
|
||||
|
||||
import std/sequtils
|
||||
|
||||
block: # walkDir
|
||||
doAssertRaises(OSError):
|
||||
for a in walkDir("nonexistent", checkDir = true): discard
|
||||
@@ -358,6 +360,21 @@ block: # walkDir
|
||||
doAssert k == pcLinkToDir
|
||||
removeDir("walkdir_test")
|
||||
|
||||
when defined(posix):
|
||||
block walkDirRegular:
|
||||
createDir("walkdir_test")
|
||||
doAssert execShellCmd("mkfifo walkdir_test/fifo") == 0
|
||||
createSymlink("fifo", "walkdir_test/fifo_link")
|
||||
let withSpecialFiles = toSeq(walkDir("walkdir_test", relative = true))
|
||||
doAssert (withSpecialFiles.len == 2 and
|
||||
(pcFile, "fifo") in withSpecialFiles and
|
||||
(pcLinkToFile, "fifo_link") in withSpecialFiles)
|
||||
# now Unix special files are excluded from walkdir output:
|
||||
let onlyRegularFiles = toSeq(walkDir("walkdir_test", relative = true,
|
||||
onlyRegular = true))
|
||||
doAssert onlyRegularFiles.len == 0
|
||||
removeDir("walkdir_test")
|
||||
|
||||
block normalizedPath:
|
||||
doAssert normalizedPath("") == ""
|
||||
block relative:
|
||||
@@ -708,8 +725,6 @@ block: # isAdmin
|
||||
# In Azure on POSIX tests run as a normal user
|
||||
if isAzure and defined(posix): doAssert not isAdmin()
|
||||
|
||||
import std/sequtils
|
||||
|
||||
when doslikeFileSystem:
|
||||
import std/private/ntpath
|
||||
|
||||
|
||||
Reference in New Issue
Block a user