Skip to content

Commit

Permalink
clean testament runs (nim-lang#2)
Browse files Browse the repository at this point in the history
* remove nimble packages
* remove unused code
* tests are green on my machine :D
  • Loading branch information
saem committed Oct 23, 2021
1 parent bb62740 commit bce8b4a
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 467 deletions.
2 changes: 1 addition & 1 deletion testament/azure.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Look at license.txt for more info.
# All rights reserved.

import base64, json, httpclient, os, strutils, uri
import std/[base64, json, httpclient, os, strutils, uri]
import specs

const
Expand Down
123 changes: 2 additions & 121 deletions testament/categories.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

# included from testament.nim

import important_packages
import std/strformat
from std/sequtils import filterIt
import std/private/gitutils

const
specialCategories = [
Expand Down Expand Up @@ -223,12 +222,6 @@ proc testNimInAction(r: var TResults, cat: Category, options: string) =
template test(filename: untyped) =
testSpec r, makeTest(filename, options, cat)

template testJS(filename: untyped) =
testSpec r, makeTest(filename, options, cat), {targetJS}

template testCPP(filename: untyped) =
testSpec r, makeTest(filename, options, cat), {targetCpp}

let tests = [
"niminaction/Chapter1/various1",
"niminaction/Chapter2/various2",
Expand All @@ -247,8 +240,7 @@ proc testNimInAction(r: var TResults, cat: Category, options: string) =
"niminaction/Chapter6/WikipediaStats/parallel_counts",
"niminaction/Chapter6/WikipediaStats/race_condition",
"niminaction/Chapter6/WikipediaStats/sequential_counts",
"niminaction/Chapter6/WikipediaStats/unguarded_access",
"niminaction/Chapter8/sdl/sdl_test"
"niminaction/Chapter6/WikipediaStats/unguarded_access"
]

when false:
Expand Down Expand Up @@ -292,10 +284,6 @@ proc testNimInAction(r: var TResults, cat: Category, options: string) =
# Run the tests.
for testfile in tests:
test "tests/" & testfile & ".nim"
let jsFile = "tests/niminaction/Chapter8/canvas/canvas_test.nim"
testJS jsFile
let cppFile = "tests/niminaction/Chapter8/sfml/sfml_test.nim"
testCPP cppFile

# ------------------------- manyloc -------------------------------------------

Expand Down Expand Up @@ -366,120 +354,15 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
testObj.spec.action = actionCompile
testSpec r, testObj

# ----------------------------- nimble ----------------------------------------
proc listPackagesAll(): seq[NimblePackage] =
var nimbleDir = getEnv("NIMBLE_DIR")
if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
let packageIndex = nimbleDir / "packages_official.json"
let packageList = parseFile(packageIndex)
proc findPackage(name: string): JsonNode =
for a in packageList:
if a["name"].str == name: return a
for pkg in important_packages.packages.items:
var pkg = pkg
if pkg.url.len == 0:
let pkg2 = findPackage(pkg.name)
if pkg2 == nil:
raise newException(ValueError, "Cannot find package '$#'." % pkg.name)
pkg.url = pkg2["url"].str
result.add pkg

proc listPackages(packageFilter: string): seq[NimblePackage] =
let pkgs = listPackagesAll()
if packageFilter.len != 0:
# xxx document `packageFilter`, seems like a bad API,
# at least should be a regex; a substring match makes no sense.
result = pkgs.filterIt(packageFilter in it.name)
else:
if testamentData0.batchArg == "allowed_failures":
result = pkgs.filterIt(it.allowFailure)
elif testamentData0.testamentNumBatch == 0:
result = pkgs
else:
let pkgs2 = pkgs.filterIt(not it.allowFailure)
for i in 0..<pkgs2.len:
if i mod testamentData0.testamentNumBatch == testamentData0.testamentBatch:
result.add pkgs2[i]

proc makeSupTest(test, options: string, cat: Category, debugInfo = ""): TTest =
result.cat = cat
result.name = test
result.options = options
result.debugInfo = debugInfo
result.startTime = epochTime()

import std/private/gitutils

proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string) =
let nimbleExe = findExe("nimble")
doAssert nimbleExe != "", "Cannot run nimble tests: Nimble binary not found."
doAssert execCmd("$# update" % nimbleExe) == 0, "Cannot run nimble tests: Nimble update failed."
let packageFileTest = makeSupTest("PackageFileParsed", "", cat)
let packagesDir = "pkgstemp"
createDir(packagesDir)
var errors = 0
try:
let pkgs = listPackages(packageFilter)
for i, pkg in pkgs:
inc r.total
var test = makeSupTest(pkg.name, "", cat, "[$#/$#] " % [$i, $pkgs.len])
let buildPath = packagesDir / pkg.name
template tryCommand(cmd: string, workingDir2 = buildPath, reFailed = reInstallFailed, maxRetries = 1): string =
var outp: string
let ok = retryCall(maxRetry = maxRetries, backoffDuration = 10.0):
var status: int
(outp, status) = execCmdEx(cmd, workingDir = workingDir2)
status == QuitSuccess
if not ok:
if pkg.allowFailure:
inc r.passed
inc r.failedButAllowed
addResult(r, test, targetC, "", cmd & "\n" & outp, reFailed, allowFailure = pkg.allowFailure)
continue
outp

if not dirExists(buildPath):
discard tryCommand("git clone $# $#" % [pkg.url.quoteShell, buildPath.quoteShell], workingDir2 = ".", maxRetries = 3)
if not pkg.useHead:
discard tryCommand("git fetch --tags", maxRetries = 3)
let describeOutput = tryCommand("git describe --tags --abbrev=0")
discard tryCommand("git checkout $#" % [describeOutput.strip.quoteShell])
discard tryCommand("nimble install --depsOnly -y", maxRetries = 3)
discard tryCommand(pkg.cmd, reFailed = reBuildFailed)
inc r.passed
r.addResult(test, targetC, "", "", reSuccess, allowFailure = pkg.allowFailure)

errors = r.total - r.passed
if errors == 0:
r.addResult(packageFileTest, targetC, "", "", reSuccess)
else:
r.addResult(packageFileTest, targetC, "", "", reBuildFailed)

except JsonParsingError:
errors = 1
r.addResult(packageFileTest, targetC, "", "Invalid package file", reBuildFailed)
raise
except ValueError:
errors = 1
r.addResult(packageFileTest, targetC, "", "Unknown package", reBuildFailed)
raise # bug #18805
finally:
if errors == 0: removeDir(packagesDir)

# ---------------- IC tests ---------------------------------------------

proc icTests(r: var TResults; testsDir: string, cat: Category, options: string;
isNavigatorTest: bool) =
const
tooltests = ["compiler/nim.nim"]
writeOnly = " --incremental:writeonly "
readOnly = " --incremental:readonly "
incrementalOn = " --incremental:on -d:nimIcIntegrityChecks "
navTestConfig = " --ic:on -d:nimIcNavigatorTests --hint:Conf:off --warnings:off "

template test(x: untyped) =
testSpecWithNimcache(r, makeRawTest(file, x & options, cat), nimcache)

template editedTest(x: untyped) =
var test = makeTest(file, x & options, cat)
if isNavigatorTest:
Expand Down Expand Up @@ -695,8 +578,6 @@ proc processCategory(r: var TResults, cat: Category,
compileExample(r, "examples/*.nim", options, cat)
compileExample(r, "examples/gtk/*.nim", options, cat)
compileExample(r, "examples/talk/*.nim", options, cat)
of "nimble-packages":
testNimblePackages(r, cat, options)
of "niminaction":
testNimInAction(r, cat, options)
of "ic":
Expand Down
167 changes: 0 additions & 167 deletions testament/important_packages.nim

This file was deleted.

21 changes: 12 additions & 9 deletions testament/specs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ type TestamentData* = ref object
testamentNumBatch*: int
testamentBatch*: int

let testamentData0* = TestamentData()

var compilerPrefix* = findExe("nim")
# global mutable state for funsies
var
compilerPrefix* = findExe("nim")
skips*: seq[string]

let isTravis* = existsEnv("TRAVIS")
let isAppVeyor* = existsEnv("APPVEYOR")
let isAzure* = existsEnv("TF_BUILD")
let testamentData0* = TestamentData()

var skips*: seq[string]
# environment related predicates
let
isTravis* = existsEnv("TRAVIS")
isAppVeyor* = existsEnv("APPVEYOR")
isAzure* = existsEnv("TF_BUILD")

type
TTestAction* = enum
Expand Down Expand Up @@ -88,8 +91,8 @@ type
targets*: set[TTarget]
matrix*: seq[string]
nimout*: string
nimoutFull*: bool # whether nimout is all compiler output or a subset
parseErrors*: string # when the spec definition is invalid, this is not empty.
nimoutFull*: bool # whether nimout is all compiler output or a subset
parseErrors*: string # when the spec definition is invalid, this is not empty.
unjoinable*: bool
unbatchable*: bool
# whether this test can be batchable via `NIM_TESTAMENT_BATCH`; only very
Expand Down
Loading

0 comments on commit bce8b4a

Please sign in to comment.