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.119 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.118 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.117 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.116 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.115 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.114 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.113 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.111 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.110 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.109 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.108 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.107 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.106 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.105 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.104 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.103 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.102 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.101 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.100 tracks/nim/_test/check_exercises.nim
trackler-2.2.1.99 tracks/nim/_test/check_exercises.nim