fix testament regression: installed testament works again with testament r path (#16767)
* fix testament regression: installed testament works again with testament r path * fixup
This commit is contained in:
parent
00d9176e91
commit
2b5841cd2b
3 changed files with 31 additions and 11 deletions
|
|
@ -24,13 +24,30 @@ const
|
||||||
# robust way to derive other paths here
|
# robust way to derive other paths here
|
||||||
# We don't depend on PATH so this is robust to having multiple nim binaries
|
# We don't depend on PATH so this is robust to having multiple nim binaries
|
||||||
nimRootDir* = sourcePath.parentDir.parentDir.parentDir.parentDir ## root of Nim repo
|
nimRootDir* = sourcePath.parentDir.parentDir.parentDir.parentDir ## root of Nim repo
|
||||||
|
testsFname* = "tests"
|
||||||
stdlibDir* = nimRootDir / "lib"
|
stdlibDir* = nimRootDir / "lib"
|
||||||
systemPath* = stdlibDir / "system.nim"
|
systemPath* = stdlibDir / "system.nim"
|
||||||
testsDir* = nimRootDir / "tests"
|
testsDir* = nimRootDir / testsFname
|
||||||
buildDir* = nimRootDir / "build"
|
buildDir* = nimRootDir / "build"
|
||||||
## refs #10268: all testament generated files should go here to avoid
|
## refs #10268: all testament generated files should go here to avoid
|
||||||
## polluting .gitignore
|
## polluting .gitignore
|
||||||
|
|
||||||
|
proc splitTestFile*(file: string): tuple[cat: string, path: string] =
|
||||||
|
## At least one directory is required in the path, to use as a category name
|
||||||
|
runnableExamples:
|
||||||
|
doAssert splitTestFile("tests/fakedir/tfakename.nim") == ("fakedir", "tests/fakedir/tfakename.nim".unixToNativePath)
|
||||||
|
for p in file.parentDirs(inclusive = false):
|
||||||
|
let parent = p.parentDir
|
||||||
|
if parent.lastPathPart == testsFname:
|
||||||
|
result.cat = p.lastPathPart
|
||||||
|
let dir = getCurrentDir()
|
||||||
|
if file.isRelativeTo(dir):
|
||||||
|
result.path = file.relativePath(dir)
|
||||||
|
else:
|
||||||
|
result.path = file
|
||||||
|
return result
|
||||||
|
doAssert false, "file must match this pattern: '/pathto/tests/dir/**/tfile.nim', got: '" & file & "'"
|
||||||
|
|
||||||
static:
|
static:
|
||||||
# sanity check
|
# sanity check
|
||||||
doAssert fileExists(systemPath)
|
doAssert fileExists(systemPath)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import
|
||||||
from std/sugar import dup
|
from std/sugar import dup
|
||||||
import compiler/nodejs
|
import compiler/nodejs
|
||||||
import lib/stdtest/testutils
|
import lib/stdtest/testutils
|
||||||
|
from lib/stdtest/specialpaths import splitTestFile
|
||||||
|
|
||||||
var useColors = true
|
var useColors = true
|
||||||
var backendLogging = true
|
var backendLogging = true
|
||||||
|
|
@ -791,16 +792,9 @@ proc main() =
|
||||||
p.next
|
p.next
|
||||||
processPattern(r, pattern, p.cmdLineRest.string, simulate)
|
processPattern(r, pattern, p.cmdLineRest.string, simulate)
|
||||||
of "r", "run":
|
of "r", "run":
|
||||||
# "/pathto/tests/stdlib/nre/captures.nim" -> "stdlib" + "tests/stdlib/nre/captures.nim"
|
var subPath = p.key
|
||||||
var subPath = p.key.string
|
let (cat, path) = splitTestFile(subPath)
|
||||||
let nimRoot = currentSourcePath / "../.."
|
processSingleTest(r, cat.Category, p.cmdLineRest, path, gTargets, targetsSet)
|
||||||
# makes sure points to this regardless of cwd or which nim is used to compile this.
|
|
||||||
doAssert(dirExists(nimRoot/testsDir), nimRoot/testsDir & " doesn't exist!") # sanity check
|
|
||||||
if subPath.isAbsolute: subPath = subPath.relativePath(nimRoot)
|
|
||||||
# at least one directory is required in the path, to use as a category name
|
|
||||||
let pathParts = subPath.relativePath(testsDir).split({DirSep, AltSep})
|
|
||||||
let cat = Category(pathParts[0])
|
|
||||||
processSingleTest(r, cat, p.cmdLineRest.string, subPath, gTargets, targetsSet)
|
|
||||||
of "html":
|
of "html":
|
||||||
generateHtml(resultsFile, optFailing)
|
generateHtml(resultsFile, optFailing)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
9
tests/testament/tspecialpaths.nim
Normal file
9
tests/testament/tspecialpaths.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import stdtest/specialpaths
|
||||||
|
import std/os
|
||||||
|
block: # splitTestFile
|
||||||
|
doAssert splitTestFile("tests/fakedir/tfakename.nim") == ("fakedir", "tests/fakedir/tfakename.nim".unixToNativePath)
|
||||||
|
doAssert splitTestFile("/pathto/tests/fakedir/tfakename.nim") == ("fakedir", "/pathto/tests/fakedir/tfakename.nim".unixToNativePath)
|
||||||
|
doAssert splitTestFile(getCurrentDir() / "tests/fakedir/tfakename.nim") == ("fakedir", "tests/fakedir/tfakename.nim".unixToNativePath)
|
||||||
|
doAssert splitTestFile(getCurrentDir() / "sub/tests/fakedir/tfakename.nim") == ("fakedir", "sub/tests/fakedir/tfakename.nim".unixToNativePath)
|
||||||
|
doAssertRaises(AssertionDefect): discard splitTestFile("testsbad/fakedir/tfakename.nim")
|
||||||
|
doAssertRaises(AssertionDefect): discard splitTestFile("tests/tfakename.nim")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue