From 4414dafd5e59096b10b4b371430c9502f354394f Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 17 Sep 2016 19:10:03 +0200 Subject: [PATCH 1/2] tests: add more tests for getFileInfo() --- tests/stdlib/tgetfileinfo.nim | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/stdlib/tgetfileinfo.nim b/tests/stdlib/tgetfileinfo.nim index 8a0538a5f..780853afc 100644 --- a/tests/stdlib/tgetfileinfo.nim +++ b/tests/stdlib/tgetfileinfo.nim @@ -1,5 +1,5 @@ discard """ - output: "" + output: "pcDir\npcFile\npcLinkToDir\npcLinkToFile\n" """ import os, strutils @@ -93,4 +93,34 @@ proc testGetFileInfo = discard #echo("Handle : Invalid File : Success") + # Test kind for files, directories and symlinks. + block: + let + tmp = getTempDir() + dirPath = tmp / "test-dir" + filePath = tmp / "test-file" + linkDirPath = tmp / "test-link-dir" + linkFilePath = tmp / "test-link-file" + + createDir(dirPath) + writeFile(filePath, "") + createSymlink(dirPath, linkDirPath) + createSymlink(filePath, linkFilePath) + + let + dirInfo = getFileInfo(dirPath) + fileInfo = getFileInfo(filePath) + linkDirInfo = getFileInfo(linkDirPath, followSymlink = false) + linkFileInfo = getFileInfo(linkFilePath, followSymlink = false) + + echo dirInfo.kind + echo fileInfo.kind + echo linkDirInfo.kind + echo linkFileInfo.kind + + removeDir(dirPath) + removeFile(filePath) + removeFile(linkDirPath) + removeFile(linkFilePath) + testGetFileInfo() From a85e954b5d690b0305d2abaff04cd6d4098029f1 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 24 Oct 2016 20:18:49 +0200 Subject: [PATCH 2/2] make tgetfileinfo work on Windows --- tests/stdlib/tgetfileinfo.nim | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/stdlib/tgetfileinfo.nim b/tests/stdlib/tgetfileinfo.nim index 780853afc..1c897b702 100644 --- a/tests/stdlib/tgetfileinfo.nim +++ b/tests/stdlib/tgetfileinfo.nim @@ -104,23 +104,31 @@ proc testGetFileInfo = createDir(dirPath) writeFile(filePath, "") - createSymlink(dirPath, linkDirPath) - createSymlink(filePath, linkFilePath) + when defined(posix): + createSymlink(dirPath, linkDirPath) + createSymlink(filePath, linkFilePath) let dirInfo = getFileInfo(dirPath) fileInfo = getFileInfo(filePath) - linkDirInfo = getFileInfo(linkDirPath, followSymlink = false) - linkFileInfo = getFileInfo(linkFilePath, followSymlink = false) + when defined(posix): + let + linkDirInfo = getFileInfo(linkDirPath, followSymlink = false) + linkFileInfo = getFileInfo(linkFilePath, followSymlink = false) echo dirInfo.kind echo fileInfo.kind - echo linkDirInfo.kind - echo linkFileInfo.kind + when defined(posix): + echo linkDirInfo.kind + echo linkFileInfo.kind + else: + echo pcLinkToDir + echo pcLinkToFile removeDir(dirPath) removeFile(filePath) - removeFile(linkDirPath) - removeFile(linkFilePath) + when defined(posix): + removeFile(linkDirPath) + removeFile(linkFilePath) testGetFileInfo()