Skip to content

Commit

Permalink
Merge nim-lang#62
Browse files Browse the repository at this point in the history
62: add string fields for target command and extension r=saem a=saem

- previously the were consts, and undocumtented, now they're funcs
  and marked for inlining
- changed whitelist to
- minor formatting to something less archaic

minor items while looking into nim-lang#61.

Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
  • Loading branch information
bors[bot] and saem committed Nov 15, 2021
2 parents bde7f75 + 43c09ba commit e157e7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
26 changes: 19 additions & 7 deletions testament/specs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,23 @@ proc getCmd*(s: TSpec): string =
else:
result = s.cmd

const
targetToExt*: array[TTarget, string] = ["nim.c", "nim.cpp", "nim.m", "js"]
targetToCmd*: array[TTarget, string] = ["c", "cpp", "objc", "js"]

proc defaultOptions*(a: TTarget): string =
func ext*(t: TTarget): string {.inline.} =
## read-only field providing the extension string for the given target
case t:
of targetC: "nim.c"
of targetCpp: "nim.cpp"
of targetObjC: "nim.m"
of targetJS: "js"

func cmd*(t: TTarget): string {.inline.} =
## read-only field providing the command string for the given target
case t:
of targetC: "c"
of targetCpp: "cpp"
of targetObjC: "objc"
of targetJS: "js"

func defaultOptions*(a: TTarget): string {.inline.} =
case a
of targetJS: "-d:nodejs"
# once we start testing for `nim js -d:nimbrowser` (eg selenium or similar),
Expand Down Expand Up @@ -263,10 +275,10 @@ proc parseSpec*(filename: string): TSpec =
case e.kind
of cfgKeyValuePair:
let key = e.key.normalize
const whiteListMulti = ["disabled", "ccodecheck"]
const allowMultipleOccurences = ["disabled", "ccodecheck"]
## list of flags that are correctly handled when passed multiple times
## (instead of being overwritten)
if key notin whiteListMulti:
if key notin allowMultipleOccurences:
doAssert key notin flags, $(key, filename)
flags.incl key
case key
Expand Down
6 changes: 4 additions & 2 deletions testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ proc isNimRepoTests(): bool =

type
Category = distinct string

TResults = object
total, passed, failedButAllowed, skipped: int
## xxx rename passed to passedOrAllowedFailure
data: string

TTest = object
name: string
cat: Category
Expand Down Expand Up @@ -161,7 +163,7 @@ proc prepareTestCmd(cmdTemplate, filename, options, nimcache: string,
if nimcache.len > 0: options.add(" --nimCache:$#" % nimcache.quoteShell)
options.add ' ' & extraOptions
# we avoid using `parseCmdLine` which is buggy, refs bug #14343
result = cmdTemplate % ["target", targetToCmd[target],
result = cmdTemplate % ["target", target.cmd,
"options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir(), "nim", compilerPrefix]

Expand Down Expand Up @@ -405,7 +407,7 @@ proc generatedFile(test: TTest, target: TTarget): string =
result = test.name.changeFileExt("js")
else:
let (_, name, _) = test.name.splitFile
let ext = targetToExt[target]
let ext = target.ext
result = nimcacheDir(test.name, test.options, target) / "@m" & name.changeFileExt(ext)

proc needsCodegenCheck(spec: TSpec): bool =
Expand Down

0 comments on commit e157e7c

Please sign in to comment.