From 3249f16d85c2adee46e283e060ce6d1e31464d06 Mon Sep 17 00:00:00 2001 From: Clay Sweetser Date: Sat, 1 Mar 2014 17:41:50 -0500 Subject: [PATCH 1/3] Integrated 'babel' with testament --- tests/testament/categories.nim | 70 +++++++++++++++++++++++++++++++++- tests/testament/specs.nim | 2 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 442dd12123..0f6c247165 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -222,9 +222,75 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) = else: testNoSpec r, makeTest(test, options, cat, actionCompile) +# ----------------------------- babel ---------------------------------------- + +let + babelExe = findExe("babel") + babelDir = getHomeDir() / ".babel" + packageDir = babelDir / "pkgs" + packageIndex = babelDir / "packages.json" + +proc waitForExitEx(p: PProcess): int = + var outp: PStream = outputStream(p) + var line = newStringOfCap(120).TaintedString + while true: + if outp.readLine(line): + discard + else: + result = peekExitCode(p) + if result != -1: break + close(p) + +proc getPackageDir(package: string): string = + ## TODO - Replace this with dom's version comparison magic. + var commandOutput = execCmdEx("babel path $#" % package) + if commandOutput.exitCode != quitSuccess: + return "" + else: + result = commandOutput[0] + +iterator listPackages(listAll = false): tuple[name, url: string] = + let packageList = parseFile(packageIndex) + + for package in packageList.items(): + let + name = package["name"].str + url = package["url"].str + isCorePackage = "nimrod-code" in normalize(url) + if isCorePackage or listAll: + yield (name, url) + +proc testBabelPackages(r: var TResults, options: string, cat: Category) = + if babelExe == "": + quit("Cannot run babel tests: Babel binary not found.", quitFailure) + + if execCmd("$# update" % babelExe) == quitFailure: + quit("Cannot run babel tests: Babel update failed.") + + for name, url in listPackages(): + var test = makeTest(name, options, cat) + echo(url) + let + installProcess = startProcess(babelExe, "", ["install", "-y", name]) + installStatus = waitForExitEx(installProcess) + installProcess.close + if installStatus != quitSuccess: + r.addResult(test, "", "", reInstallFailed) + continue + + let + buildPath = getPackageDir(name)[0.. -3] + let + buildProcess = startProcess(babelExe, buildPath, ["build"]) + buildStatus = waitForExitEx(buildProcess) + buildProcess.close + if buildStatus != quitSuccess: + r.addResult(test, "", "", reBuildFailed) + r.addResult(test, "", "", reSuccess) + # ---------------------------------------------------------------------------- -const AdditionalCategories = ["debugger", "tools", "examples", "stdlib"] +const AdditionalCategories = ["debugger", "tools", "examples", "stdlib", "babel"] proc `&.?`(a, b: string): string = # candidate for the stdlib? @@ -264,6 +330,8 @@ proc processCategory(r: var TResults, cat: Category, options: string) = compileExample(r, "examples/*.nim", options, cat) compileExample(r, "examples/gtk/*.nim", options, cat) compileExample(r, "examples/talk/*.nim", options, cat) + of "babel": + testBabelPackages(r, options, cat) else: for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"): testSpec r, makeTest(name, options, cat) diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim index e97015946d..f7982127fa 100644 --- a/tests/testament/specs.nim +++ b/tests/testament/specs.nim @@ -28,6 +28,8 @@ type reCodegenFailure, reCodeNotFound, reExeNotFound, + reInstallFailed # package installation failed + reBuildFailed # package building failed reIgnored, # test is ignored reSuccess # test was successful TTarget* = enum From 269bf8e334bd9edfe86b2923fffa157cf35f668d Mon Sep 17 00:00:00 2001 From: Clay Sweetser Date: Mon, 3 Mar 2014 06:26:22 -0500 Subject: [PATCH 2/3] Removed babel package tests from those run when 'all' is specified. --- tests/testament/categories.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 0f6c247165..9dc51567dc 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -290,7 +290,7 @@ proc testBabelPackages(r: var TResults, options: string, cat: Category) = # ---------------------------------------------------------------------------- -const AdditionalCategories = ["debugger", "tools", "examples", "stdlib", "babel"] +const AdditionalCategories = ["debugger", "tools", "examples", "stdlib"] proc `&.?`(a, b: string): string = # candidate for the stdlib? From 9620893d7201184a8635931aee9c684dea0bc5b9 Mon Sep 17 00:00:00 2001 From: Clay Sweetser Date: Mon, 3 Mar 2014 17:53:47 -0500 Subject: [PATCH 3/3] Allowed specification of what babel packages to install via new categories - 'babel-core', 'babel-extra', and 'babel-all' --- tests/testament/categories.nim | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 9dc51567dc..bf65d26dee 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -223,6 +223,10 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) = testNoSpec r, makeTest(test, options, cat, actionCompile) # ----------------------------- babel ---------------------------------------- +type PackageFilter = enum + pfCoreOnly + pfExtraOnly + pfAll let babelExe = findExe("babel") @@ -249,7 +253,7 @@ proc getPackageDir(package: string): string = else: result = commandOutput[0] -iterator listPackages(listAll = false): tuple[name, url: string] = +iterator listPackages(filter: PackageFilter): tuple[name, url: string] = let packageList = parseFile(packageIndex) for package in packageList.items(): @@ -257,18 +261,25 @@ iterator listPackages(listAll = false): tuple[name, url: string] = name = package["name"].str url = package["url"].str isCorePackage = "nimrod-code" in normalize(url) - if isCorePackage or listAll: + case filter: + of pfCoreOnly: + if isCorePackage: + yield (name, url) + of pfExtraOnly: + if not isCorePackage: + yield (name, url) + of pfAll: yield (name, url) -proc testBabelPackages(r: var TResults, options: string, cat: Category) = +proc testBabelPackages(r: var TResults, cat: Category, filter: PackageFilter) = if babelExe == "": quit("Cannot run babel tests: Babel binary not found.", quitFailure) if execCmd("$# update" % babelExe) == quitFailure: quit("Cannot run babel tests: Babel update failed.") - for name, url in listPackages(): - var test = makeTest(name, options, cat) + for name, url in listPackages(filter): + var test = makeTest(name, "", cat) echo(url) let installProcess = startProcess(babelExe, "", ["install", "-y", name]) @@ -290,7 +301,7 @@ proc testBabelPackages(r: var TResults, options: string, cat: Category) = # ---------------------------------------------------------------------------- -const AdditionalCategories = ["debugger", "tools", "examples", "stdlib"] +const AdditionalCategories = ["debugger", "tools", "examples", "stdlib", "babel-core"] proc `&.?`(a, b: string): string = # candidate for the stdlib? @@ -330,8 +341,12 @@ proc processCategory(r: var TResults, cat: Category, options: string) = compileExample(r, "examples/*.nim", options, cat) compileExample(r, "examples/gtk/*.nim", options, cat) compileExample(r, "examples/talk/*.nim", options, cat) - of "babel": - testBabelPackages(r, options, cat) + of "babel-core": + testBabelPackages(r, cat, pfCoreOnly) + of "babel-extra": + testBabelPackages(r, cat, pfExtraOnly) + of "babel-all": + testBabelPackages(r, cat, pfAll) else: for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"): testSpec r, makeTest(name, options, cat)