summary refs log tree commit diff stats
path: root/testament/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-01-20 05:04:08 -0800
committerGitHub <noreply@github.com>2021-01-20 14:04:08 +0100
commit2b5841cd2b096624987d7cd1aa217088447076b7 (patch)
tree2543121f46b3a1796d5a9a62502490bb49a4f5a9 /testament/lib
parent00d9176e91c4a44ed2ccd8dd19c29e9f3d0f6ace (diff)
downloadNim-2b5841cd2b096624987d7cd1aa217088447076b7.tar.gz
fix testament regression: installed testament works again with testament r path (#16767)
* fix testament regression: installed testament works again with testament r path

* fixup
Diffstat (limited to 'testament/lib')
-rw-r--r--testament/lib/stdtest/specialpaths.nim19
1 files changed, 18 insertions, 1 deletions
diff --git a/testament/lib/stdtest/specialpaths.nim b/testament/lib/stdtest/specialpaths.nim
index 42f656d76..dc5cc2064 100644
--- a/testament/lib/stdtest/specialpaths.nim
+++ b/testament/lib/stdtest/specialpaths.nim
@@ -24,13 +24,30 @@ const
     # robust way to derive other paths here
     # 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
+  testsFname* = "tests"
   stdlibDir* = nimRootDir / "lib"
   systemPath* = stdlibDir / "system.nim"
-  testsDir* = nimRootDir / "tests"
+  testsDir* = nimRootDir / testsFname
   buildDir* = nimRootDir / "build"
     ## refs #10268: all testament generated files should go here to avoid
     ## 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:
   # sanity check
   doAssert fileExists(systemPath)