mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
move tests from tospaths to tos, fixes #9671
Also, change some of `echo`s to `doAssert`.
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
discard """
|
||||
output: '''true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
output: '''
|
||||
All:
|
||||
__really_obscure_dir_name/are.x
|
||||
__really_obscure_dir_name/created
|
||||
@@ -27,31 +19,13 @@ __really_obscure_dir_name/created
|
||||
__really_obscure_dir_name/dirs
|
||||
__really_obscure_dir_name/some
|
||||
__really_obscure_dir_name/test
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
true
|
||||
true
|
||||
Raises
|
||||
Raises
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
|
||||
'''
|
||||
"""
|
||||
# test os path creation, iteration, and deletion
|
||||
|
||||
import os, strutils
|
||||
import os, strutils, pathnorm
|
||||
|
||||
block fileOperations:
|
||||
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
||||
@@ -60,17 +34,17 @@ block fileOperations:
|
||||
let dname = "__really_obscure_dir_name"
|
||||
|
||||
createDir(dname)
|
||||
echo dirExists(dname)
|
||||
doAssert dirExists(dname)
|
||||
|
||||
# Test creating files and dirs
|
||||
for dir in dirs:
|
||||
createDir(dname/dir)
|
||||
echo dirExists(dname/dir)
|
||||
doAssert dirExists(dname/dir)
|
||||
|
||||
for file in files:
|
||||
let fh = open(dname/file, fmReadWrite)
|
||||
fh.close()
|
||||
echo fileExists(dname/file)
|
||||
doAssert fileExists(dname/file)
|
||||
|
||||
echo "All:"
|
||||
|
||||
@@ -93,23 +67,23 @@ block fileOperations:
|
||||
# Test removal of files dirs
|
||||
for dir in dirs:
|
||||
removeDir(dname/dir)
|
||||
echo dirExists(dname/dir)
|
||||
doAssert: not dirExists(dname/dir)
|
||||
|
||||
for file in files:
|
||||
removeFile(dname/file)
|
||||
echo fileExists(dname/file)
|
||||
doAssert: not fileExists(dname/file)
|
||||
|
||||
removeDir(dname)
|
||||
echo dirExists(dname)
|
||||
doAssert: not dirExists(dname)
|
||||
|
||||
# createDir should create recursive directories
|
||||
createDir(dirs[0] / dirs[1])
|
||||
echo dirExists(dirs[0] / dirs[1]) # true
|
||||
doAssert dirExists(dirs[0] / dirs[1]) # true
|
||||
removeDir(dirs[0])
|
||||
|
||||
# createDir should properly handle trailing separator
|
||||
createDir(dname / "")
|
||||
echo dirExists(dname) # true
|
||||
doAssert dirExists(dname) # true
|
||||
removeDir(dname)
|
||||
|
||||
# createDir should raise IOError if the path exists
|
||||
@@ -138,10 +112,10 @@ block fileOperations:
|
||||
copyDir("a", "../dest/a")
|
||||
removeDir("a")
|
||||
|
||||
echo dirExists("../dest/a/b")
|
||||
echo fileExists("../dest/a/b/file.txt")
|
||||
doAssert dirExists("../dest/a/b")
|
||||
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")
|
||||
|
||||
# test copyDir:
|
||||
@@ -152,8 +126,8 @@ block fileOperations:
|
||||
copyDir("a/", "../dest/a/")
|
||||
removeDir("a")
|
||||
|
||||
echo dirExists("../dest/a/b")
|
||||
echo fileExists("../dest/a/file.txt")
|
||||
doAssert dirExists("../dest/a/b")
|
||||
doAssert fileExists("../dest/a/file.txt")
|
||||
removeDir("../dest")
|
||||
|
||||
import times
|
||||
@@ -165,9 +139,9 @@ block modificationTime:
|
||||
setLastModificationTime("a", tm)
|
||||
|
||||
when defined(macosx):
|
||||
echo "true"
|
||||
doAssert true
|
||||
else:
|
||||
echo getLastModificationTime("a") == tm
|
||||
doAssert getLastModificationTime("a") == tm
|
||||
removeFile("a")
|
||||
|
||||
block walkDirRec:
|
||||
@@ -265,3 +239,97 @@ block splitFile:
|
||||
doAssert splitFile("a/..") == ("a", "..", "")
|
||||
|
||||
# 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"
|
||||
Reference in New Issue
Block a user