Skip to content

Commit

Permalink
sync: rename check to sync, and update to update_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Jun 20, 2021
1 parent dde8bbd commit ff19da4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
7 changes: 2 additions & 5 deletions src/configlet.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import std/posix
import "."/[cli, generate/generate, lint/lint, logger, sync/check, sync/update, uuid/uuid]
import "."/[cli, generate/generate, lint/lint, logger, sync/sync, uuid/uuid]

proc main =
onSignal(SIGTERM):
Expand All @@ -15,10 +15,7 @@ proc main =
of actLint:
lint(conf)
of actSync:
if conf.action.update:
update(conf)
else:
check(conf)
sync(conf)
of actUuid:
uuid(conf.action.num)
of actGenerate:
Expand Down
15 changes: 11 additions & 4 deletions src/sync/check.nim → src/sync/sync.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import std/[os, sequtils, sets, strformat]
import ".."/[cli, logger]
import "."/[exercises, probspecs]
import "."/[exercises, probspecs, update_tests]

proc contentsAfterFirstHeader(path: string): string =
result = newStringOfCap(getFileSize(path))
Expand Down Expand Up @@ -112,7 +112,7 @@ proc explain(syncKind: SyncKind): string =
of skMetadata: "have unsynced metadata"
of skTests: "are missing test cases"

proc check*(conf: Conf) =
proc sync*(conf: Conf) =
logNormal("Checking exercises...")

let probSpecsDir = initProbSpecsDir(conf)
Expand All @@ -133,7 +133,10 @@ proc check*(conf: Conf) =
checkMetadata(exercises, seenUnsynced)

if skTests in conf.action.scope:
checkTests(exercises, seenUnsynced)
if conf.action.update:
updateTests(exercises, conf, seenUnsynced)
else:
checkTests(exercises, seenUnsynced)
finally:
if conf.action.probSpecsDir.len == 0:
removeDir(probSpecsDir)
Expand All @@ -143,5 +146,9 @@ proc check*(conf: Conf) =
logNormal(&"[warn] some exercises {explain(syncKind)}")
quit(QuitFailure)
else:
logNormal("All exercises are up-to-date!")
if conf.action.scope == {SyncKind.low .. SyncKind.high}:
logNormal("All exercises are up to date!")
else:
for syncKind in conf.action.scope:
logNormal(&"All {syncKind} are up to date!")
quit(QuitSuccess)
25 changes: 10 additions & 15 deletions src/sync/update.nim → src/sync/update_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,18 @@ proc syncIfNeeded(exercise: Exercise, conf: Conf): bool =
logDetailed(&"[skip] {exercise.slug} does not have canonical data")
true

proc update*(conf: Conf) =
logNormal("Syncing exercises...")
proc updateTests*(exercises: seq[Exercise], conf: Conf,
seenUnsynced: var set[SyncKind]) =
logNormal("Updating tests...")

var everyExerciseIsSynced = true
let probSpecsDir = initProbSpecsDir(conf)
try:
for exercise in findExercises(conf, probSpecsDir):
let isExerciseSynced = syncIfNeeded(exercise, conf)
if not isExerciseSynced:
everyExerciseIsSynced = false
finally:
if conf.action.probSpecsDir.len == 0:
removeDir(probSpecsDir)

for exercise in exercises:
let isExerciseSynced = syncIfNeeded(exercise, conf)
if not isExerciseSynced:
everyExerciseIsSynced = false

if everyExerciseIsSynced:
logNormal("All exercises are synced!")
quit(QuitSuccess)
seenUnsynced.excl skTests
else:
logNormal("[warn] some exercises are still missing test cases")
quit(QuitFailure)
seenUnsynced.incl skTests
18 changes: 10 additions & 8 deletions tests/test_binary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ Checking exercises...
[warn] some exercises are missing test cases
"""

test "`sync --update --mode=include` exits with 0 and includes the expected test cases":
test "`sync --update --mode=include --tests` exits with 0 and includes the expected test cases":
execAndCheck(0):
execCmdEx(&"{binaryPath} -t {trackDir} sync --update -mi -o -p {psDir}")
execCmdEx(&"{binaryPath} -t {trackDir} sync --update -mi -o -p {psDir} --tests")

check outp == """
Syncing exercises...
Checking exercises...
Updating tests...
[info] anagram: included 1 missing test case
[info] diffie-hellman: included 1 missing test case
[info] grade-school: included 1 missing test case
Expand All @@ -137,7 +138,7 @@ Syncing exercises...
[info] luhn: included 1 missing test case
[info] prime-factors: included 5 missing test cases
[info] react: included 14 missing test cases
All exercises are synced!
All tests are up to date!
"""

const expectedDiffOutput = """
Expand Down Expand Up @@ -464,13 +465,14 @@ All exercises are synced!

check outp.conciseDiff() == expectedDiffOutput

test "after syncing, another `sync --update --mode=include` performs no changes":
test "after syncing, another `sync --update --mode=include --tests` performs no changes":
execAndCheck(0):
execCmdEx(&"{binaryPath} -t {trackDir} sync --update -mi -o -p {psDir}")
execCmdEx(&"{binaryPath} -t {trackDir} sync --update -mi -o -p {psDir} --tests")

check outp == """
Syncing exercises...
All exercises are synced!
Checking exercises...
Updating tests...
All tests are up to date!
"""

test "after syncing, a `sync` without `--update` shows that tests are up to date":
Expand Down

0 comments on commit ff19da4

Please sign in to comment.