Skip to content

Commit

Permalink
[testament] compile/run compiler/**
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 18, 2019
1 parent 2039dad commit 9c1f294
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compiler/btrees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ when isMainModule:
st.add("www.yahoo.com", "216.109.118.65")

assert st.getOrDefault("www.cs.princeton.edu") == "abc"
assert st.getOrDefault("www.harvardsucks.com") == nil
assert st.getOrDefault("www.harvardsucks.com") == ""

assert st.getOrDefault("www.simpsons.com") == "209.052.165.60"
assert st.getOrDefault("www.apple.com") == "17.112.152.32"
Expand Down
2 changes: 1 addition & 1 deletion compiler/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


# In fact the grammar is generated from this file:
when isMainModule:
when isMainModule and not defined(testing):
# Leave a note in grammar.txt that it is generated:
#| # This file is generated by compiler/parser.nim.
import pegs
Expand Down
78 changes: 69 additions & 9 deletions testament/categories.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,29 +401,39 @@ proc compileExample(r: var TResults, pattern, options: string, cat: Category) =
test.spec.action = actionCompile
testSpec r, test

proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
var files: seq[string]

proc isValid(file: string): bool =
type TestMeta = object
skip: bool
optionCompile: string

type ProcGetTestMeta = proc(file: string, testMeta: var TestMeta)

proc testLibGeneric(r: var TResults, pattern, options: string, cat: Category, getTestMeta: ProcGetTestMeta) =
var files: seq[string]
proc isValidGeneric(file: string): bool =
for dir in parentDirs(file, inclusive = false):
if dir.lastPathPart in ["includes", "nimcache"]:
# eg: lib/pure/includes/osenv.nim gives: Error: This is an include file for os.nim!
return false
let name = extractFilename(file)
if name.splitFile.ext != ".nim": return false
for namei in disabledFiles:
# because of `LockFreeHash.nim` which has case
if namei.cmpPaths(name) == 0: return false
return true

for testFile in os.walkDirRec(pattern):
if isValid(testFile):
files.add testFile
# Nim BUG: Error: 'continue' cannot have a label
# if not isValidGeneric(testFile): continue
# files.add testFile
if isValidGeneric(testFile): files.add testFile

files.sort # reproducible order
for testFile in files:
var options2 = options
let contents = readFile(testFile).string
var testObj = makeTest(testFile, options, cat)
var testMeta: TestMeta
getTestMeta(testFile, testMeta)
if testMeta.skip: continue
options2.add " " & testMeta.optionCompile
var testObj = makeTest(testFile, options2, cat)
#[
todo:
this logic is fragile:
Expand All @@ -436,6 +446,54 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
testObj.spec.action = actionCompile
testSpec r, testObj

proc testCompilerlib(r: var TResults, pattern, options: string, cat: Category) =
proc getTestMeta(file: string, testMeta: var TestMeta) =
let contents = readFile(file).string
if contents.contains("# included from "): # hack; need something more robust
testMeta.skip = true
return

# todo: reduce list below by making appropriate adjustments
let excluded = """
vmhooks
canonicalizer
vmops
ccgliterals
nimfix/nimfix
canonicalizer
ccgliterals
closureiters
debuginfo
forloops
hlo
lambdalifting
evalffi
jstypes
packagehandling
"""
for a in excluded.split:
if a.len == 0: continue # IMPROVE: cf splitRemoveComments
let file2 = unixToNativePath("compiler/" & (a & ".nim"))
if file == file2:
testMeta.skip = true
return

case file
of "compiler/layouter.nim": testMeta.optionCompile = " -d:nimPretty"
else: discard
testLibGeneric(r, pattern, options, cat, getTestMeta)

proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
proc getTestMeta(file: string, testMeta: var TestMeta) =
let name = extractFilename(file)
for namei in disabledFiles:
# because of `LockFreeHash.nim` which has case
if namei.cmpPaths(name) == 0:
testMeta.skip = true
return

testLibGeneric(r, pattern, options, cat, getTestMeta)

# ----------------------------- nimble ----------------------------------------
type
PackageFilter = enum
Expand Down Expand Up @@ -688,6 +746,8 @@ proc processCategory(r: var TResults, cat: Category, options, testsDir: string,
of "lib":
testStdlib(r, "lib/pure/", options, cat)
testStdlib(r, "lib/packages/docutils/", options, cat)
of "compilerlib":
testCompilerlib(r, "compiler/", options, cat)
of "examples":
compileExample(r, "examples/*.nim", options, cat)
compileExample(r, "examples/gtk/*.nim", options, cat)
Expand Down
4 changes: 3 additions & 1 deletion testament/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ proc callCompiler(cmdTemplate, filename, options: string,
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir()])
if verboseCommands:
echo (msg: "callCompiler", command: c.quoteShellCommand)
var p = startProcess(command=c[0], args=c[1 .. ^1],
options={poStdErrToStdOut, poUsePath})
let outp = p.outputStream
Expand Down Expand Up @@ -236,7 +238,7 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
# test.name is easier to find than test.name.extractFilename
# A bit hacky but simple and works with tests/testament/tshouldfail.nim
var name = test.name.replace(DirSep, '/')
name.add " " & $target & test.options
name.add " " & $target & " " & $test.spec.action & " " & test.options

let duration = epochTime() - test.startTime
let durationStr = duration.formatFloat(ffDecimal, precision = 8).align(11)
Expand Down

0 comments on commit 9c1f294

Please sign in to comment.