ic navigator tests (#17735)

* IC navigator: first basic test
This commit is contained in:
Andreas Rumpf 2021-04-16 12:20:43 +02:00 • committed by GitHub
commit 606288974f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 14 deletions

1
.gitignore vendored
View file

@ -82,6 +82,7 @@ tweeter_test.db
/tests/megatest.nim /tests/megatest.nim
/tests/ic/*_temp.nim /tests/ic/*_temp.nim
/tests/navigator/*_temp.nim
/outputExpected.txt /outputExpected.txt

View file

@ -494,7 +494,8 @@ proc loadError(err: RodFileError; filename: AbsoluteFile; config: ConfigRef;) =
of includeFileChanged: of includeFileChanged:
rawMessage(config, warnFileChanged, filename.string) rawMessage(config, warnFileChanged, filename.string)
else: else:
echo "Error: ", $err, " loading file: ", filename.string rawMessage(config, warnCannotOpenFile, filename.string & " reason: " & $err)
#echo "Error: ", $err, " loading file: ", filename.string
proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef; proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef;
ignoreConfig = false): RodFileError = ignoreConfig = false): RodFileError =

View file

@ -79,7 +79,7 @@ proc usage(c: var NavContext; info: PackedLineInfo; isDecl: bool) =
file = os.extractFilename file file = os.extractFilename file
toLocation(m, file, info.line.int, info.col.int + ColOffset) toLocation(m, file, info.line.int, info.col.int + ColOffset)
if not c.alreadyEmitted.containsOrIncl(m): if not c.alreadyEmitted.containsOrIncl(m):
echo (if isDecl: "def" else: "usage"), c.outputSep, m msgWriteln c.g.config, (if isDecl: "def" else: "usage") & c.outputSep & m
proc list(c: var NavContext; tree: PackedTree; sym: ItemId) = proc list(c: var NavContext; tree: PackedTree; sym: ItemId) =
for i in 0..high(tree.nodes): for i in 0..high(tree.nodes):

View file

@ -483,24 +483,27 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string) =
# ---------------- IC tests --------------------------------------------- # ---------------- IC tests ---------------------------------------------
proc icTests(r: var TResults; testsDir: string, cat: Category, options: string) = proc icTests(r: var TResults; testsDir: string, cat: Category, options: string;
isNavigatorTest: bool) =
const const
tooltests = ["compiler/nim.nim", "tools/nimgrep.nim"] tooltests = ["compiler/nim.nim", "tools/nimgrep.nim"]
writeOnly = " --incremental:writeonly " writeOnly = " --incremental:writeonly "
readOnly = " --incremental:readonly " readOnly = " --incremental:readonly "
incrementalOn = " --incremental:on -d:nimIcIntegrityChecks " incrementalOn = " --incremental:on -d:nimIcIntegrityChecks "
navTestConfig = " --ic:on --defusages -d:nimIcNavigatorTests --hint[Conf]:off --warnings:off "
template test(x: untyped) = template test(x: untyped) =
testSpecWithNimcache(r, makeRawTest(file, x & options, cat), nimcache) testSpecWithNimcache(r, makeRawTest(file, x & options, cat), nimcache)
template editedTest(x: untyped) = template editedTest(x: untyped) =
var test = makeTest(file, x & options, cat) var test = makeTest(file, x & options, cat)
if isNavigatorTest:
test.spec.action = actionCompile
test.spec.targets = {getTestSpecTarget()} test.spec.targets = {getTestSpecTarget()}
testSpecWithNimcache(r, test, nimcache) testSpecWithNimcache(r, test, nimcache)
const tempExt = "_temp.nim" const tempExt = "_temp.nim"
for it in walkDirRec(testsDir / "ic"): for it in walkDirRec(testsDir):
# for it in ["tests/ic/timports.nim"]: # debugging: to try a specific test
if isTestFile(it) and not it.endsWith(tempExt): if isTestFile(it) and not it.endsWith(tempExt):
let nimcache = nimcacheDir(it, options, getTestSpecTarget()) let nimcache = nimcacheDir(it, options, getTestSpecTarget())
removeDir(nimcache) removeDir(nimcache)
@ -510,10 +513,10 @@ proc icTests(r: var TResults; testsDir: string, cat: Category, options: string)
let file = it.replace(".nim", tempExt) let file = it.replace(".nim", tempExt)
writeFile(file, fragment) writeFile(file, fragment)
let oldPassed = r.passed let oldPassed = r.passed
editedTest incrementalOn editedTest(if isNavigatorTest: navTestConfig else: incrementalOn)
if r.passed != oldPassed+1: break if r.passed != oldPassed+1: break
when false: if not isNavigatorTest and false:
for file in tooltests: for file in tooltests:
let nimcache = nimcacheDir(file, options, getTestSpecTarget()) let nimcache = nimcacheDir(file, options, getTestSpecTarget())
removeDir(nimcache) removeDir(nimcache)
@ -528,7 +531,7 @@ proc icTests(r: var TResults; testsDir: string, cat: Category, options: string)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
const AdditionalCategories = ["debugger", "examples", "lib", "ic"] const AdditionalCategories = ["debugger", "examples", "lib", "ic", "navigator"]
const MegaTestCat = "megatest" const MegaTestCat = "megatest"
proc `&.?`(a, b: string): string = proc `&.?`(a, b: string): string =
@ -695,7 +698,9 @@ proc processCategory(r: var TResults, cat: Category,
of "niminaction": of "niminaction":
testNimInAction(r, cat, options) testNimInAction(r, cat, options)
of "ic": of "ic":
icTests(r, testsDir, cat, options) icTests(r, testsDir / cat2, cat, options, isNavigatorTest=false)
of "navigator":
icTests(r, testsDir / cat2, cat, options, isNavigatorTest=true)
of "untestable": of "untestable":
# These require special treatment e.g. because they depend on a third party # These require special treatment e.g. because they depend on a third party
# dependency; see `trunner_special` which runs some of those. # dependency; see `trunner_special` which runs some of those.

View file

@ -157,8 +157,8 @@ proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
"options", options, "file", filename.quoteShell, "options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir(), "nim", compilerPrefix]) "filedir", filename.getFileDir(), "nim", compilerPrefix])
proc callCompiler(cmdTemplate, filename, options, nimcache: string, proc callNimCompiler(cmdTemplate, filename, options, nimcache: string,
target: TTarget, extraOptions = ""): TSpec = target: TTarget, extraOptions = ""): TSpec =
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target, let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target,
extraOptions) extraOptions)
result.cmd = quoteShellCommand(c) result.cmd = quoteShellCommand(c)
@ -465,11 +465,11 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
test.startTime = epochTime() test.startTime = epochTime()
case expected.action case expected.action
of actionCompile: of actionCompile:
var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target, var given = callNimCompiler(expected.getCmd, test.name, test.options, nimcache, target,
extraOptions = " --stdout --hint[Path]:off --hint[Processing]:off") extraOptions = " --stdout --hint[Path]:off --hint[Processing]:off")
compilerOutputTests(test, target, given, expected, r) compilerOutputTests(test, target, given, expected, r)
of actionRun: of actionRun:
var given = callCompiler(expected.getCmd, test.name, test.options, var given = callNimCompiler(expected.getCmd, test.name, test.options,
nimcache, target, extraOptions) nimcache, target, extraOptions)
if given.err != reSuccess: if given.err != reSuccess:
r.addResult(test, target, "", "$ " & given.cmd & '\n' & given.nimout, given.err) r.addResult(test, target, "", "$ " & given.cmd & '\n' & given.nimout, given.err)
@ -523,7 +523,7 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
else: else:
compilerOutputTests(test, target, given, expected, r) compilerOutputTests(test, target, given, expected, r)
of actionReject: of actionReject:
var given = callCompiler(expected.getCmd, test.name, test.options, var given = callNimCompiler(expected.getCmd, test.name, test.options,
nimcache, target) nimcache, target)
cmpMsgs(r, expected, given, test, target) cmpMsgs(r, expected, given, test, target)

33
tests/navigator/tnav1.nim Normal file
View file

@ -0,0 +1,33 @@
discard """
cmd: "nim check $options --track:$file,12,7 $file"
nimout: '''def tnav1_temp.nim(11, 10)
usage tnav1_temp.nim(12, 8)
'''
"""
import std / [times]
proc foo(x: int) =
echo x
foo(3)
echo "yes", 1 != 3
#!EDIT!#
discard """
cmd: "nim check $options --track:$file,15,2 $file"
nimout: '''def tnav1_temp.nim(12, 6)
usage tnav1_temp.nim(15, 1)
'''
"""
import std / [times]
proc foo(x: int) =
echo x
foo(3)
echo "yes", 1 != 3