Skip to content

Commit

Permalink
Fixes #802, #803 and #3775 - genscript issues (#7677)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
genotrance authored and Araq committed Apr 25, 2018
1 parent b34580f commit e931f3b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion doc/advopt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/flags/tgenscript.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
discard """
file: "tgenscript.nim"
"""

echo "--genscript"
2 changes: 1 addition & 1 deletion tests/testament/backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions tests/testament/categories.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion tests/testament/htmlgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 20 additions & 5 deletions tests/testament/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import

const
resultsFile = "testresults.html"
jsonFile = "testresults.json"
#jsonFile = "testresults.json" # not used
Usage = """Usage:
tester [options] command [arguments]
Expand Down Expand Up @@ -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" &
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e931f3b

Please sign in to comment.