Fixes #802, #803 and #3775 - genscript issues (#7677)

* Fixes #802, #803 and #3775 - genscript issues

* Test case for genscript

* Test script

* Verify on Linux

* Update categories.nim

* Fix merge

* Improve test framework

* Windows fixes
This commit is contained in:
genotrance
2018-04-25 03:52:32 -05:00
committed by Andreas Rumpf
parent b34580fd5b
commit e931f3b5a9
8 changed files with 57 additions and 12 deletions

View File

@@ -652,6 +652,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "genscript", "gendeps":
expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optGenScript)
incl(gGlobalOptions, optCompileOnly)
of "colors": processOnOffSwitchG({optUseColors}, arg, pass, info)
of "lib":
expectArg(switch, arg, pass, info)

View File

@@ -470,8 +470,9 @@ proc execExternalProgram*(cmd: string, msg = hintExecuting) =
proc generateScript(projectFile: string, script: Rope) =
let (dir, name, ext) = splitFile(projectFile)
writeRope(script, dir / addFileExt("compile_" & name,
writeRope(script, getNimcacheDir() / addFileExt("compile_" & name,
platform.OS[targetOS].scriptExt))
copyFile(libpath / "nimbase.h", getNimcacheDir() / "nimbase.h")
proc getOptSpeed(c: TSystemCC): string =
result = getConfigVar(c, ".options.speed")

View File

@@ -35,7 +35,8 @@ Advanced options:
--noLinking compile Nim and generated files but do not link
--noMain do not generate a main procedure
--genScript generate a compile script (in the 'nimcache'
subdirectory named 'compile_$$project$$scriptext')
subdirectory named 'compile_$$project$$scriptext'),
implies --compileOnly
--genDeps generate a '.deps' file containing the dependencies
--os:SYMBOL set the target operating system (cross-compilation)
--cpu:SYMBOL set the target processor (cross-compilation)

View File

@@ -0,0 +1,5 @@
discard """
file: "tgenscript.nim"
"""
echo "--genscript"

View File

@@ -13,7 +13,7 @@ type
CommitId = distinct string
proc `$`*(id: MachineId): string {.borrow.}
proc `$`(id: CommitId): string {.borrow.}
#proc `$`(id: CommitId): string {.borrow.} # not used
var
thisMachine: MachineId

View File

@@ -63,6 +63,26 @@ proc compileRodFiles(r: var TResults, cat: Category, options: string) =
test "gtkex1", true
test "gtkex2"
# --------------------- flags tests -------------------------------------------
proc flagTests(r: var TResults, cat: Category, options: string) =
# --genscript
const filename = "tests"/"flags"/"tgenscript"
const genopts = " --genscript"
let nimcache = nimcacheDir(filename, genopts, targetC)
testSpec r, makeTest(filename, genopts, cat)
when defined(windows):
testExec r, makeTest(filename, " cmd /c cd " & nimcache &
" && compile_tgenscript.bat", cat)
when defined(linux):
testExec r, makeTest(filename, " sh -c \"cd " & nimcache &
" && sh compile_tgenscript.sh\"", cat)
# Run
testExec r, makeTest(filename, " " & nimcache / "tgenscript", cat)
# --------------------- DLL generation tests ----------------------------------
proc safeCopyFile(src, dest: string) =
@@ -323,7 +343,7 @@ var nimbleDir = getEnv("NIMBLE_DIR").string
if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
let
nimbleExe = findExe("nimble")
packageDir = nimbleDir / "pkgs"
#packageDir = nimbleDir / "pkgs" # not used
packageIndex = nimbleDir / "packages.json"
proc waitForExitEx(p: Process): int =
@@ -407,9 +427,9 @@ proc `&.?`(a, b: string): string =
# candidate for the stdlib?
result = if b.startswith(a): b else: a & b
proc `&?.`(a, b: string): string =
#proc `&?.`(a, b: string): string = # not used
# candidate for the stdlib?
result = if a.endswith(b): a else: a & b
#result = if a.endswith(b): a else: a & b
proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
let test = "tests" & DirSep &.? cat.string / test
@@ -429,6 +449,8 @@ proc processCategory(r: var TResults, cat: Category, options: string) =
jsTests(r, cat, options)
of "dll":
dllTests(r, cat, options)
of "flags":
flagTests(r, cat, options)
of "gc":
gcTests(r, cat, options)
of "longgc":

View File

@@ -121,7 +121,7 @@ proc generateAllTestsContent(outfile: File, allResults: AllTests,
proc generateHtml*(filename: string, onlyFailing: bool) =
let
currentTime = getTime().getLocalTime()
currentTime = getTime().local()
timestring = htmlQuote format(currentTime, "yyyy-MM-dd HH:mm:ss 'UTC'zzz")
var outfile = open(filename, fmWrite)

View File

@@ -16,7 +16,7 @@ import
const
resultsFile = "testresults.html"
jsonFile = "testresults.json"
#jsonFile = "testresults.json" # not used
Usage = """Usage:
tester [options] command [arguments]
@@ -150,11 +150,11 @@ proc initResults: TResults =
result.skipped = 0
result.data = ""
proc readResults(filename: string): TResults =
result = marshal.to[TResults](readFile(filename).string)
#proc readResults(filename: string): TResults = # not used
# result = marshal.to[TResults](readFile(filename).string)
proc writeResults(filename: string, r: TResults) =
writeFile(filename, $$r)
#proc writeResults(filename: string, r: TResults) = # not used
# writeFile(filename, $$r)
proc `$`(x: TResults): string =
result = ("Tests passed: $1 / $3 <br />\n" &
@@ -404,6 +404,21 @@ proc testC(r: var TResults, test: TTest) =
if exitCode != 0: given.err = reExitCodesDiffer
if given.err == reSuccess: inc(r.passed)
proc testExec(r: var TResults, test: TTest) =
# runs executable or script, just goes by exit code
inc(r.total)
let (outp, errC) = execCmdEx(test.options.strip())
var given: TSpec
specDefaults(given)
if errC == 0:
given.err = reSuccess
else:
given.err = reExitCodesDiffer
given.msg = outp.string
if given.err == reSuccess: inc(r.passed)
r.addResult(test, targetC, "", given.msg, given.err)
proc makeTest(test, options: string, cat: Category, action = actionCompile,
env: string = ""): TTest =
# start with 'actionCompile', will be overwritten in the spec: