Skip to content

Commit

Permalink
sync: ignore track-deprecated practice exercises (#682)
Browse files Browse the repository at this point in the history
Before this commit, `configlet sync` operated on every practice exercise
in the track-level `config.json` file, even if the exercise had a
`status` of `deprecated`.

For example, if only `accumulate` and `binary` are deprecated on the
track, and `word-count` has unsynced tests, we might see:

    $ configlet sync
    Updating cached 'problem-specifications' data...
    Checking exercises...
    [warn] docs: instructions unsynced: accumulate
    [warn] metadata: unsynced: binary
    [warn] accumulate: missing 6 test cases
           - accumulate empty (64d97c14-36dd-44a8-9621-2cecebd6ed23)
           - accumulate squares (00008ed2-4651-4929-8c08-8b4dbd70872e)
           - accumulate upcases (551016da-4396-4cae-b0ec-4c3a1a264125)
           - accumulate reversed strings (cdf95597-b6ec-4eac-a838-3480d13d0d05)
           - accumulate recursively (bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb)
           - accumulate recursively (0b357334-4cad-49e1-a741-425202edfc7c)
    [warn] word-count: missing 1 test case
           - quotation for word with apostrophe (6d00f1db-901c-4bec-9829-d20eb3044557)
    [warn] some exercises have unsynced docs
    [warn] some exercises have unsynced metadata
    [warn] some exercises are missing test cases

With this commit, `configlet sync` ignores practice exercises that are
deprecated on the track:

    $ configlet sync
    Updating cached 'problem-specifications' data...
    Checking exercises...
    [warn] word-count: missing 1 test case
           - quotation for word with apostrophe (6d00f1db-901c-4bec-9829-d20eb3044557)
    [warn] some exercises are missing test cases

Note that `configlet sync` will still operate on an exercise that is
deprecated only in problem-specifications.

Fixes: #518
  • Loading branch information
ee7 committed Oct 27, 2022
1 parent ac74536 commit 891c626
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/sync/sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type
func init*(T: typedesc[TrackExerciseSlugs], exercises: Exercises): T =
T(
`concept`: getSlugs(exercises.`concept`),
practice: getSlugs(exercises.practice)
practice: getSlugs(exercises.practice, withDeprecated = false)
)

proc getSlugs*(exercises: Exercises, conf: Conf,
Expand Down
10 changes: 6 additions & 4 deletions src/sync/sync_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ proc postHook*(e: ConceptExercise | PracticeExercise) =
stderr.writeLine msg
quit 1

func getSlugs*(e: seq[ConceptExercise] | seq[PracticeExercise]): seq[Slug] =
func getSlugs*(e: seq[ConceptExercise] | seq[PracticeExercise],
withDeprecated = true): seq[Slug] =
## Returns a seq of the slugs in `e`, in alphabetical order.
result = newSeq[Slug](e.len)
for i, item in e:
result[i] = item.slug
result = newSeqOfCap[Slug](e.len)
for item in e:
if withDeprecated or item.status != sDeprecated:
result.add item.slug
sort result

func truncateAndAdd*(s: var string, truncateLen: int, slug: Slug) =
Expand Down
12 changes: 8 additions & 4 deletions src/sync/tracks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func testsPath*(trackDir: TrackDir, slug: PracticeExerciseSlug): string =
joinPath(trackDir.string, "exercises", "practice", slug.string, ".meta",
"tests.toml")

proc getPracticeExerciseSlugs(trackDir: TrackDir): seq[PracticeExerciseSlug] =
proc getPracticeExerciseSlugs(trackDir: TrackDir,
withDeprecated: bool): seq[PracticeExerciseSlug] =
## Parses the root `config.json` file in `trackDir` and returns a seq of its
## Practice Exercise slugs, in alphabetical order.
let configFile = trackDir / "config.json"
Expand All @@ -40,8 +41,10 @@ proc getPracticeExerciseSlugs(trackDir: TrackDir): seq[PracticeExerciseSlug] =
result = newSeqOfCap[PracticeExerciseSlug](practiceExercises.len)

for exercise in practiceExercises:
if exercise.hasKey("slug"):
if exercise["slug"].kind == JString:
if exercise.hasKey("slug") and exercise["slug"].kind == JString:
if withDeprecated or not exercise.hasKey("status") or
exercise["status"].kind != JString or
exercise["status"].getStr() != "deprecated":
let slug = exercise["slug"].getStr()
result.add PracticeExerciseSlug(slug)
else:
Expand Down Expand Up @@ -101,7 +104,8 @@ iterator findPracticeExercises*(conf: Conf): PracticeExercise {.inline.} =
let trackDir = TrackDir(conf.trackDir)
let userExercise = PracticeExerciseSlug(conf.action.exercise)

let practiceExerciseSlugs = getPracticeExerciseSlugs(trackDir)
let practiceExerciseSlugs = getPracticeExerciseSlugs(trackDir,
withDeprecated = false)

for slug in practiceExerciseSlugs:
if userExercise.len == 0 or userExercise == slug:
Expand Down
7 changes: 1 addition & 6 deletions tests/test_binary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ proc testsForSync(binaryPath: static string) =
bodyUnsyncedMetadata = """
[warn] metadata: unsynced: acronym
[warn] metadata: unsynced: armstrong-numbers
[warn] metadata: unsynced: binary
[warn] metadata: unsynced: collatz-conjecture
[warn] metadata: unsynced: darts
[warn] metadata: unsynced: grade-school
Expand Down Expand Up @@ -452,7 +451,7 @@ proc testsForSync(binaryPath: static string) =
const expectedOutput = fmt"""
{header}
{bodyUnsyncedMetadata}
Updated the metadata for 14 Practice Exercises
Updated the metadata for 13 Practice Exercises
{footerSyncedMetadata}
""".unindent()
const expectedDiff = """
Expand All @@ -464,10 +463,6 @@ proc testsForSync(binaryPath: static string) =
+++ exercises/practice/armstrong-numbers/.meta/config.json
- "blurb": "Determine if a number is an Armstrong number",
+ "blurb": "Determine if a number is an Armstrong number.",
--- exercises/practice/binary/.meta/config.json
+++ exercises/practice/binary/.meta/config.json
- "blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles",
+ "blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.",
--- exercises/practice/collatz-conjecture/.meta/config.json
+++ exercises/practice/collatz-conjecture/.meta/config.json
- "blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tracks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc main =

test "returns the expected number of exercises":
check:
practiceExercises.len == 68
practiceExercises.len == 67

test "returns the expected object for `hello-world`":
const expectedHelloWorld =
Expand All @@ -32,7 +32,7 @@ proc main =
)

check:
practiceExercises[20] == expectedHelloWorld
practiceExercises[19] == expectedHelloWorld

test "returns the expected object for `two-fer`":
const expectedTwoFer =
Expand All @@ -47,7 +47,7 @@ proc main =
)

check:
practiceExercises[65] == expectedTwoFer
practiceExercises[64] == expectedTwoFer

main()
{.used.}

0 comments on commit 891c626

Please sign in to comment.