move tests from tospaths to tos, fixes #9671
Also, change some of `echo`s to `doAssert`.
This commit is contained in:
parent
28cb81ea87
commit
f0be575ed1
2 changed files with 111 additions and 142 deletions
|
|
@ -1,13 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''true
|
output: '''
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
All:
|
All:
|
||||||
__really_obscure_dir_name/are.x
|
__really_obscure_dir_name/are.x
|
||||||
__really_obscure_dir_name/created
|
__really_obscure_dir_name/created
|
||||||
|
|
@ -27,31 +19,13 @@ __really_obscure_dir_name/created
|
||||||
__really_obscure_dir_name/dirs
|
__really_obscure_dir_name/dirs
|
||||||
__really_obscure_dir_name/some
|
__really_obscure_dir_name/some
|
||||||
__really_obscure_dir_name/test
|
__really_obscure_dir_name/test
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
false
|
|
||||||
true
|
|
||||||
true
|
|
||||||
Raises
|
Raises
|
||||||
Raises
|
Raises
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
true
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
# test os path creation, iteration, and deletion
|
# test os path creation, iteration, and deletion
|
||||||
|
|
||||||
import os, strutils
|
import os, strutils, pathnorm
|
||||||
|
|
||||||
block fileOperations:
|
block fileOperations:
|
||||||
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
||||||
|
|
@ -60,17 +34,17 @@ block fileOperations:
|
||||||
let dname = "__really_obscure_dir_name"
|
let dname = "__really_obscure_dir_name"
|
||||||
|
|
||||||
createDir(dname)
|
createDir(dname)
|
||||||
echo dirExists(dname)
|
doAssert dirExists(dname)
|
||||||
|
|
||||||
# Test creating files and dirs
|
# Test creating files and dirs
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
createDir(dname/dir)
|
createDir(dname/dir)
|
||||||
echo dirExists(dname/dir)
|
doAssert dirExists(dname/dir)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
let fh = open(dname/file, fmReadWrite)
|
let fh = open(dname/file, fmReadWrite)
|
||||||
fh.close()
|
fh.close()
|
||||||
echo fileExists(dname/file)
|
doAssert fileExists(dname/file)
|
||||||
|
|
||||||
echo "All:"
|
echo "All:"
|
||||||
|
|
||||||
|
|
@ -93,23 +67,23 @@ block fileOperations:
|
||||||
# Test removal of files dirs
|
# Test removal of files dirs
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
removeDir(dname/dir)
|
removeDir(dname/dir)
|
||||||
echo dirExists(dname/dir)
|
doAssert: not dirExists(dname/dir)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
removeFile(dname/file)
|
removeFile(dname/file)
|
||||||
echo fileExists(dname/file)
|
doAssert: not fileExists(dname/file)
|
||||||
|
|
||||||
removeDir(dname)
|
removeDir(dname)
|
||||||
echo dirExists(dname)
|
doAssert: not dirExists(dname)
|
||||||
|
|
||||||
# createDir should create recursive directories
|
# createDir should create recursive directories
|
||||||
createDir(dirs[0] / dirs[1])
|
createDir(dirs[0] / dirs[1])
|
||||||
echo dirExists(dirs[0] / dirs[1]) # true
|
doAssert dirExists(dirs[0] / dirs[1]) # true
|
||||||
removeDir(dirs[0])
|
removeDir(dirs[0])
|
||||||
|
|
||||||
# createDir should properly handle trailing separator
|
# createDir should properly handle trailing separator
|
||||||
createDir(dname / "")
|
createDir(dname / "")
|
||||||
echo dirExists(dname) # true
|
doAssert dirExists(dname) # true
|
||||||
removeDir(dname)
|
removeDir(dname)
|
||||||
|
|
||||||
# createDir should raise IOError if the path exists
|
# createDir should raise IOError if the path exists
|
||||||
|
|
@ -138,10 +112,10 @@ block fileOperations:
|
||||||
copyDir("a", "../dest/a")
|
copyDir("a", "../dest/a")
|
||||||
removeDir("a")
|
removeDir("a")
|
||||||
|
|
||||||
echo dirExists("../dest/a/b")
|
doAssert dirExists("../dest/a/b")
|
||||||
echo fileExists("../dest/a/b/file.txt")
|
doAssert fileExists("../dest/a/b/file.txt")
|
||||||
|
|
||||||
echo fileExists("../dest/a/b/c/fileC.txt")
|
doAssert fileExists("../dest/a/b/c/fileC.txt")
|
||||||
removeDir("../dest")
|
removeDir("../dest")
|
||||||
|
|
||||||
# test copyDir:
|
# test copyDir:
|
||||||
|
|
@ -152,8 +126,8 @@ block fileOperations:
|
||||||
copyDir("a/", "../dest/a/")
|
copyDir("a/", "../dest/a/")
|
||||||
removeDir("a")
|
removeDir("a")
|
||||||
|
|
||||||
echo dirExists("../dest/a/b")
|
doAssert dirExists("../dest/a/b")
|
||||||
echo fileExists("../dest/a/file.txt")
|
doAssert fileExists("../dest/a/file.txt")
|
||||||
removeDir("../dest")
|
removeDir("../dest")
|
||||||
|
|
||||||
import times
|
import times
|
||||||
|
|
@ -165,9 +139,9 @@ block modificationTime:
|
||||||
setLastModificationTime("a", tm)
|
setLastModificationTime("a", tm)
|
||||||
|
|
||||||
when defined(macosx):
|
when defined(macosx):
|
||||||
echo "true"
|
doAssert true
|
||||||
else:
|
else:
|
||||||
echo getLastModificationTime("a") == tm
|
doAssert getLastModificationTime("a") == tm
|
||||||
removeFile("a")
|
removeFile("a")
|
||||||
|
|
||||||
block walkDirRec:
|
block walkDirRec:
|
||||||
|
|
@ -265,3 +239,97 @@ block splitFile:
|
||||||
doAssert splitFile("a/..") == ("a", "..", "")
|
doAssert splitFile("a/..") == ("a", "..", "")
|
||||||
|
|
||||||
# execShellCmd is tested in tosproc
|
# execShellCmd is tested in tosproc
|
||||||
|
|
||||||
|
block ospaths:
|
||||||
|
doAssert unixToNativePath("") == ""
|
||||||
|
doAssert unixToNativePath(".") == $CurDir
|
||||||
|
doAssert unixToNativePath("..") == $ParDir
|
||||||
|
doAssert isAbsolute(unixToNativePath("/"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/", "a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a", "a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a/b"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a/b", "a"))
|
||||||
|
doAssert unixToNativePath("a/b") == joinPath("a", "b")
|
||||||
|
|
||||||
|
when defined(macos):
|
||||||
|
doAssert unixToNativePath("./") == ":"
|
||||||
|
doAssert unixToNativePath("./abc") == ":abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "::abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == ":::abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "abc:def"
|
||||||
|
elif doslikeFileSystem:
|
||||||
|
doAssert unixToNativePath("./") == ".\\"
|
||||||
|
doAssert unixToNativePath("./abc") == ".\\abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "..\\abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == "..\\..\\abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "a:\\abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "a:\\abc\\def"
|
||||||
|
else:
|
||||||
|
#Tests for unix
|
||||||
|
doAssert unixToNativePath("./") == "./"
|
||||||
|
doAssert unixToNativePath("./abc") == "./abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "../abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == "../../abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "/abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "/abc/def"
|
||||||
|
|
||||||
|
block extractFilenameTest:
|
||||||
|
doAssert extractFilename("") == ""
|
||||||
|
when defined(posix):
|
||||||
|
doAssert extractFilename("foo/bar") == "bar"
|
||||||
|
doAssert extractFilename("foo/bar.txt") == "bar.txt"
|
||||||
|
doAssert extractFilename("foo/") == ""
|
||||||
|
doAssert extractFilename("/") == ""
|
||||||
|
when doslikeFileSystem:
|
||||||
|
doAssert extractFilename(r"foo\bar") == "bar"
|
||||||
|
doAssert extractFilename(r"foo\bar.txt") == "bar.txt"
|
||||||
|
doAssert extractFilename(r"foo\") == ""
|
||||||
|
doAssert extractFilename(r"C:\") == ""
|
||||||
|
|
||||||
|
block lastPathPartTest:
|
||||||
|
doAssert lastPathPart("") == ""
|
||||||
|
when defined(posix):
|
||||||
|
doAssert lastPathPart("foo/bar.txt") == "bar.txt"
|
||||||
|
doAssert lastPathPart("foo/") == "foo"
|
||||||
|
doAssert lastPathPart("/") == ""
|
||||||
|
when doslikeFileSystem:
|
||||||
|
doAssert lastPathPart(r"foo\bar.txt") == "bar.txt"
|
||||||
|
doAssert lastPathPart(r"foo\") == "foo"
|
||||||
|
|
||||||
|
template canon(x): untyped = normalizePath(x, '/')
|
||||||
|
doAssert canon"/foo/../bar" == "/bar"
|
||||||
|
doAssert canon"foo/../bar" == "bar"
|
||||||
|
|
||||||
|
doAssert canon"/f/../bar///" == "/bar"
|
||||||
|
doAssert canon"f/..////bar" == "bar"
|
||||||
|
|
||||||
|
doAssert canon"../bar" == "../bar"
|
||||||
|
doAssert canon"/../bar" == "/../bar"
|
||||||
|
|
||||||
|
doAssert canon("foo/../../bar/") == "../bar"
|
||||||
|
doAssert canon("./bla/blob/") == "bla/blob"
|
||||||
|
doAssert canon(".hiddenFile") == ".hiddenFile"
|
||||||
|
doAssert canon("./bla/../../blob/./zoo.nim") == "../blob/zoo.nim"
|
||||||
|
|
||||||
|
doAssert canon("C:/file/to/this/long") == "C:/file/to/this/long"
|
||||||
|
doAssert canon("") == ""
|
||||||
|
doAssert canon("foobar") == "foobar"
|
||||||
|
doAssert canon("f/////////") == "f"
|
||||||
|
|
||||||
|
doAssert relativePath("/foo/bar//baz.nim", "/foo", '/') == "bar/baz.nim"
|
||||||
|
doAssert normalizePath("./foo//bar/../baz", '/') == "foo/baz"
|
||||||
|
|
||||||
|
doAssert relativePath("/Users/me/bar/z.nim", "/Users/other/bad", '/') == "../../me/bar/z.nim"
|
||||||
|
|
||||||
|
doAssert relativePath("/Users/me/bar/z.nim", "/Users/other", '/') == "../me/bar/z.nim"
|
||||||
|
doAssert relativePath("/Users///me/bar//z.nim", "//Users/", '/') == "me/bar/z.nim"
|
||||||
|
doAssert relativePath("/Users/me/bar/z.nim", "/Users/me", '/') == "bar/z.nim"
|
||||||
|
doAssert relativePath("", "/users/moo", '/') == ""
|
||||||
|
doAssert relativePath("foo", "", '/') == "foo"
|
||||||
|
|
||||||
|
doAssert joinPath("usr", "") == unixToNativePath"usr/"
|
||||||
|
doAssert joinPath("", "lib") == "lib"
|
||||||
|
doAssert joinPath("", "/lib") == unixToNativePath"/lib"
|
||||||
|
doAssert joinPath("usr/", "/lib") == unixToNativePath"usr/lib"
|
||||||
|
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
discard """
|
|
||||||
output: ""
|
|
||||||
"""
|
|
||||||
# test the ospaths module
|
|
||||||
|
|
||||||
import os, pathnorm
|
|
||||||
|
|
||||||
doAssert unixToNativePath("") == ""
|
|
||||||
doAssert unixToNativePath(".") == $CurDir
|
|
||||||
doAssert unixToNativePath("..") == $ParDir
|
|
||||||
doAssert isAbsolute(unixToNativePath("/"))
|
|
||||||
doAssert isAbsolute(unixToNativePath("/", "a"))
|
|
||||||
doAssert isAbsolute(unixToNativePath("/a"))
|
|
||||||
doAssert isAbsolute(unixToNativePath("/a", "a"))
|
|
||||||
doAssert isAbsolute(unixToNativePath("/a/b"))
|
|
||||||
doAssert isAbsolute(unixToNativePath("/a/b", "a"))
|
|
||||||
doAssert unixToNativePath("a/b") == joinPath("a", "b")
|
|
||||||
|
|
||||||
when defined(macos):
|
|
||||||
doAssert unixToNativePath("./") == ":"
|
|
||||||
doAssert unixToNativePath("./abc") == ":abc"
|
|
||||||
doAssert unixToNativePath("../abc") == "::abc"
|
|
||||||
doAssert unixToNativePath("../../abc") == ":::abc"
|
|
||||||
doAssert unixToNativePath("/abc", "a") == "abc"
|
|
||||||
doAssert unixToNativePath("/abc/def", "a") == "abc:def"
|
|
||||||
elif doslikeFileSystem:
|
|
||||||
doAssert unixToNativePath("./") == ".\\"
|
|
||||||
doAssert unixToNativePath("./abc") == ".\\abc"
|
|
||||||
doAssert unixToNativePath("../abc") == "..\\abc"
|
|
||||||
doAssert unixToNativePath("../../abc") == "..\\..\\abc"
|
|
||||||
doAssert unixToNativePath("/abc", "a") == "a:\\abc"
|
|
||||||
doAssert unixToNativePath("/abc/def", "a") == "a:\\abc\\def"
|
|
||||||
else:
|
|
||||||
#Tests for unix
|
|
||||||
doAssert unixToNativePath("./") == "./"
|
|
||||||
doAssert unixToNativePath("./abc") == "./abc"
|
|
||||||
doAssert unixToNativePath("../abc") == "../abc"
|
|
||||||
doAssert unixToNativePath("../../abc") == "../../abc"
|
|
||||||
doAssert unixToNativePath("/abc", "a") == "/abc"
|
|
||||||
doAssert unixToNativePath("/abc/def", "a") == "/abc/def"
|
|
||||||
|
|
||||||
block extractFilenameTest:
|
|
||||||
doAssert extractFilename("") == ""
|
|
||||||
when defined(posix):
|
|
||||||
doAssert extractFilename("foo/bar") == "bar"
|
|
||||||
doAssert extractFilename("foo/bar.txt") == "bar.txt"
|
|
||||||
doAssert extractFilename("foo/") == ""
|
|
||||||
doAssert extractFilename("/") == ""
|
|
||||||
when doslikeFileSystem:
|
|
||||||
doAssert extractFilename(r"foo\bar") == "bar"
|
|
||||||
doAssert extractFilename(r"foo\bar.txt") == "bar.txt"
|
|
||||||
doAssert extractFilename(r"foo\") == ""
|
|
||||||
doAssert extractFilename(r"C:\") == ""
|
|
||||||
|
|
||||||
block lastPathPartTest:
|
|
||||||
doAssert lastPathPart("") == ""
|
|
||||||
when defined(posix):
|
|
||||||
doAssert lastPathPart("foo/bar.txt") == "bar.txt"
|
|
||||||
doAssert lastPathPart("foo/") == "foo"
|
|
||||||
doAssert lastPathPart("/") == ""
|
|
||||||
when doslikeFileSystem:
|
|
||||||
doAssert lastPathPart(r"foo\bar.txt") == "bar.txt"
|
|
||||||
doAssert lastPathPart(r"foo\") == "foo"
|
|
||||||
|
|
||||||
template canon(x): untyped = normalizePath(x, '/')
|
|
||||||
doAssert canon"/foo/../bar" == "/bar"
|
|
||||||
doAssert canon"foo/../bar" == "bar"
|
|
||||||
|
|
||||||
doAssert canon"/f/../bar///" == "/bar"
|
|
||||||
doAssert canon"f/..////bar" == "bar"
|
|
||||||
|
|
||||||
doAssert canon"../bar" == "../bar"
|
|
||||||
doAssert canon"/../bar" == "/../bar"
|
|
||||||
|
|
||||||
doAssert canon("foo/../../bar/") == "../bar"
|
|
||||||
doAssert canon("./bla/blob/") == "bla/blob"
|
|
||||||
doAssert canon(".hiddenFile") == ".hiddenFile"
|
|
||||||
doAssert canon("./bla/../../blob/./zoo.nim") == "../blob/zoo.nim"
|
|
||||||
|
|
||||||
doAssert canon("C:/file/to/this/long") == "C:/file/to/this/long"
|
|
||||||
doAssert canon("") == ""
|
|
||||||
doAssert canon("foobar") == "foobar"
|
|
||||||
doAssert canon("f/////////") == "f"
|
|
||||||
|
|
||||||
doAssert relativePath("/foo/bar//baz.nim", "/foo", '/') == "bar/baz.nim"
|
|
||||||
doAssert normalizePath("./foo//bar/../baz", '/') == "foo/baz"
|
|
||||||
|
|
||||||
doAssert relativePath("/Users/me/bar/z.nim", "/Users/other/bad", '/') == "../../me/bar/z.nim"
|
|
||||||
|
|
||||||
doAssert relativePath("/Users/me/bar/z.nim", "/Users/other", '/') == "../me/bar/z.nim"
|
|
||||||
doAssert relativePath("/Users///me/bar//z.nim", "//Users/", '/') == "me/bar/z.nim"
|
|
||||||
doAssert relativePath("/Users/me/bar/z.nim", "/Users/me", '/') == "bar/z.nim"
|
|
||||||
doAssert relativePath("", "/users/moo", '/') == ""
|
|
||||||
doAssert relativePath("foo", "", '/') == "foo"
|
|
||||||
|
|
||||||
doAssert joinPath("usr", "") == unixToNativePath"usr/"
|
|
||||||
doAssert joinPath("", "lib") == "lib"
|
|
||||||
doAssert joinPath("", "/lib") == unixToNativePath"/lib"
|
|
||||||
doAssert joinPath("usr/", "/lib") == unixToNativePath"usr/lib"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue