Sha256: 160da1a5f9b7bd2ac83e9b490e44906d1a9ba7c54fb333dd2bcdc6460f630b4f

Contents?: true

Size: 1.25 KB

Versions: 396

Compression:

Stored size: 1.25 KB

Contents

import
  os, osproc, re, strutils

type TTestResult = tuple[exercise: string, exitCode: int]

proc determineModuleName(testFilePath: string): string =
  let
    errorMsg = osproc.execCmdEx("nim c --verbosity=0 " & testFilePath).output
    quotedWords = re.findAll(errorMsg, re"\'\w+\'")
  quotedWords[high(quotedWords)][1 .. ^2]

proc runTest(testFilePath: string): TTestResult =
  let
    moduleName = determineModuleName(testFilePath)
    exerciseDirPath = os.splitPath(testFilePath)[0]
    exerciseName = os.splitPath(exerciseDirPath)[1]
    examplePath = os.joinPath(exerciseDirPath, "example.nim")
    modulePath = os.joinPath(exerciseDirPath, moduleName & ".nim")
  os.moveFile(examplePath, modulePath)
  echo "### " & exerciseName & " ###"
  let exitCode = osproc.execCmd("nim c -r --verbosity=0 " & testFilePath)
  os.moveFile(modulePath, examplePath)
  (exerciseName, exitCode)

when isMainModule:
  var failures: seq[string] = @[]
  for dir in os.walkDir("./exercises"):
    for file in os.walkFiles(os.joinPath(dir.path, "*_test.nim")):
      let (exercise, exitCode) = runTest(file)
      if exitCode != 0:
        failures.add(exercise)

  if failures.len == 0:
    echo "SUCCESS"
  else:
    echo "FAILURES: " & strutils.join(failures, ", ")
    programResult = 1

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.179 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.178 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.177 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.176 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.175 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.174 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.173 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.172 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.171 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.170 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.169 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.167 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.166 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.165 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.164 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.163 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.162 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.161 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.160 tracks/nim/_test/check_exercises.nim