Skip to content

Commit c4e6f84

Browse files
authored
Introduces testEntryPoint (#1380)
1 parent 411d337 commit c4e6f84

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

nimble-guide/docs/nimble-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
`js`.
5757
* ``paths`` - A list of relative paths that will be expanded on `nimble.paths` and the search paths options to the compiler.
5858
* ``entryPoints`` - A list of relative paths to nim files that will be used by the `nimlangserver` as project entry points. Useful for test files like `tall.nim`
59+
*``testEntryPoint`` - A relative path to the test file that contains imported tests (i.e. `tall.nim`).
5960
**Default**: `c`.
6061

6162

src/nimble.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,13 @@ proc test(options: Options) =
17961796
files = toSeq(walkDir(getCurrentDir() / "tests"))
17971797
tests, failures: int
17981798

1799+
if pkgInfo.testEntryPoint != "" :
1800+
if fileExists(pkgInfo.testEntryPoint):
1801+
displayInfo("Using test entry point: " & pkgInfo.testEntryPoint, HighPriority)
1802+
files = @[(kind: pcFile, path: pkgInfo.testEntryPoint)]
1803+
else:
1804+
raise nimbleError("Test entry point not found: " & pkgInfo.testEntryPoint)
1805+
17991806
if files.len < 1:
18001807
display("Warning:", "No tests found!", Warning, HighPriority)
18011808
return

src/nimblepkg/nimscriptapi.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var
2424
srcDir*: string ## The package's source directory.
2525
binDir*: string ## The package's binary directory.
2626
backend*: string ## The package's backend.
27+
testEntryPoint*: string ## The package's test entry point.
2728

2829
skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*,
2930
installExt*, bin*, paths*, entryPoints*: seq[string] = @[] ## Nimble metadata.
@@ -117,6 +118,8 @@ template printSeqIfLen(varName) =
117118
printSeqIfLen(astToStr(varName), varName)
118119

119120
proc printPkgInfo(): string =
121+
#Notice this functions is called by the wrapper to store the package info as a ini file.
122+
#We should instead just use the declarative parser to parse the variables of the nimble file.
120123
if backend.len == 0:
121124
backend = "c"
122125

@@ -138,7 +141,7 @@ proc printPkgInfo(): string =
138141
printIfLen srcDir
139142
printIfLen binDir
140143
printIfLen backend
141-
144+
printIfLen testEntryPoint
142145
printSeqIfLen skipDirs
143146
printSeqIfLen skipFiles
144147
printSeqIfLen skipExt

src/nimblepkg/packageinfotypes.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ type
7979
entryPoints*: seq[string] #useful for tools like the lsp.
8080
features*: Table[string, seq[PkgTuple]] #features requires defined in the nimble file. Declarative parser + SAT solver only.
8181
activeFeatures*: Table[PkgTuple, seq[string]] #features that dependencies of this package have activated. #i.e. requires package[feature1, feature2]
82-
82+
testEntryPoint*: string ## The entry point for the test task.
83+
8384
Package* = object ## Definition of package from packages.json.
8485
# Required fields in a package.
8586
name*: string

src/nimblepkg/packageparser.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
212212
result.paths.add(ev.value.multiSplit)
213213
of "entrypoints":
214214
result.entryPoints.add(ev.value.multiSplit)
215+
of "testentrypoint":
216+
result.testEntryPoint = ev.value
215217
else:
216218
raise nimbleError("Invalid field: " & ev.key)
217219
of "deps", "dependencies":

0 commit comments

Comments
 (0)