Skip to content

Commit

Permalink
sync: support --track-dir
Browse files Browse the repository at this point in the history
Previously the test file path was always derived from the working
directory.
  • Loading branch information
ee7 committed Jan 26, 2021
1 parent 47ce56b commit 4f3ff45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/sync/exercises.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ proc status*(exercise: Exercise): ExerciseStatus =
proc hasCanonicalData*(exercise: Exercise): bool =
exercise.testCases.len > 0

proc testsFile(exercise: Exercise): string =
getCurrentDir() / "exercises" / exercise.slug / ".meta" / "tests.toml"
proc testsFile(exercise: Exercise, trackDir: string): string =
trackDir / "exercises" / exercise.slug / ".meta" / "tests.toml"

proc toToml(exercise: Exercise): string =
result.add("[canonical-tests]\n")
Expand All @@ -89,8 +89,8 @@ proc toToml(exercise: Exercise): string =
result.add(&"\n# {testCase.description}")
result.add(&"\n\"{testCase.uuid}\" = {isIncluded}\n")

proc writeTestsToml*(exercise: Exercise) =
let testsPath = testsFile(exercise)
proc writeTestsToml*(exercise: Exercise, trackDir: string) =
let testsPath = testsFile(exercise, trackDir)
createDir(testsPath.parentDir())

let contents = toToml(exercise)
Expand Down
11 changes: 6 additions & 5 deletions src/sync/sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ proc syncDecision(testCase: ExerciseTestCase, mode: Mode): SyncDecision =
of modeChoose:
chooseSyncDecision(testCase)

proc sync(exercise: Exercise, mode: Mode): Exercise =
proc sync(exercise: Exercise, conf: Conf): Exercise =
result = exercise

let mode = conf.action.mode
case mode
of modeInclude:
logNormal(&"[info] {exercise.slug}: included {exercise.tests.missing.len} missing test cases")
Expand Down Expand Up @@ -100,13 +101,13 @@ proc sync(exercise: Exercise, mode: Mode): Exercise =

result.tests = initExerciseTests(included, excluded, missing)

writeTestsToml(result)
writeTestsToml(result, conf.trackDir)

proc sync(exercises: seq[Exercise], mode: Mode): seq[Exercise] =
proc sync(exercises: seq[Exercise], conf: Conf): seq[Exercise] =
for exercise in exercises:
case exercise.status
of exOutOfSync:
result.add(sync(exercise, mode))
result.add(sync(exercise, conf))
of exInSync:
logDetailed(&"[skip] {exercise.slug} is up-to-date")
of exNoCanonicalData:
Expand All @@ -116,7 +117,7 @@ proc sync*(conf: Conf) =
logNormal("Syncing exercises...")

let exercises = findExercises(conf)
let syncedExercises = sync(exercises, conf.action.mode)
let syncedExercises = sync(exercises, conf)

if syncedExercises.anyIt(it.status == exOutOfSync):
logNormal("[warn] some exercises are still missing test cases")
Expand Down

0 comments on commit 4f3ff45

Please sign in to comment.