Skip to content

Commit

Permalink
generate: show missing introduction file in output
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Aug 29, 2024
1 parent 9578122 commit afdae6b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/generate/generate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,17 @@ proc generateImpl(trackDir: Path, conf: Conf): seq[PathAndGeneratedDocument] =
slugLookup)
let introductionPath = introductionTemplatePath.string[0..^5] # Removes `.tpl`

if fileExists(introductionPath) and readFile(introductionPath) == generated:
logDetailed(&"Up-to-date: {relativePath(introductionPath, $trackDir)}")
if fileExists(introductionPath):
if readFile(introductionPath) == generated:
logDetailed(&"Up-to-date: {relativePath(introductionPath, $trackDir)}")
else:
logNormal(&"Outdated: {relativePath(introductionPath, $trackDir)}")
result.add PathAndGeneratedDocument(
path: introductionPath,
generatedDocument: generated
)
else:
logNormal(&"Outdated: {relativePath(introductionPath, $trackDir)}")
logNormal(&"Missing: {relativePath(introductionPath, $trackDir)}")
result.add PathAndGeneratedDocument(
path: introductionPath,
generatedDocument: generated
Expand Down
44 changes: 41 additions & 3 deletions tests/test_binary_generate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ proc main =

test "`configlet generate` exits with 0 for a valid `.md.tpl` file":
const expectedOutput = fmt"""
Outdated: {"exercises"/"concept"/"bird-count"/".docs"/"introduction.md"}
Missing: {"exercises"/"concept"/"bird-count"/".docs"/"introduction.md"}
Generated 1 file
""".unindent().replace("\p", "\n")
execAndCheck(0, generateCmdUpdateYes, expectedOutput)
Expand All @@ -67,15 +67,53 @@ proc main =
prepareIntroductionFiles(trackDir, "%{ concept : recursion }",
removeIntro = true)

test "`configlet generate` exits with 0 for valid placeholder usage with spaces":
test "`configlet generate` exits with 0 for valid placeholder usage with spaces, intro does not exist":
const expectedOutput = fmt"""
Outdated: {"exercises"/"concept"/"bird-count"/".docs"/"introduction.md"}
Missing: {"exercises"/"concept"/"bird-count"/".docs"/"introduction.md"}
Generated 1 file
""".unindent().replace("\p", "\n")
execAndCheck(0, generateCmdUpdateYes, expectedOutput)

test "and writes the `introduction.md` file as expected":
checkNoDiff(trackDir)

# Valid placeholder syntax with spaces, and valid slug
prepareIntroductionFiles(trackDir, "%{ concept : atoms }",
removeIntro = false)

test "`configlet generate` exits with 0 for valid placeholder usage with spaces, intro exists":
const expectedOutput = fmt"""
Outdated: {"exercises"/"concept"/"bird-count"/".docs"/"introduction.md"}
Generated 1 file
""".unindent().replace("\p", "\n")
execAndCheck(0, generateCmdUpdateYes, expectedOutput)

test "and writes the `introduction.md` file as expected":
const expectedDiff = """
--- exercises/concept/bird-count/.docs/introduction.md
+++ exercises/concept/bird-count/.docs/introduction.md
-## Recursion
+## Atoms
-Recursive functions are functions that call themselves.
-
-A recursive function needs to have at least one _base case_ and at least one _recursive case_.
-
-A _base case_ returns a value without calling the function again. A _recursive case_ calls the function again, modifying the input so that it will at some point match the base case.
-
-Very often, each case is written in its own function clause.
+Elixir's `atom` type represents a fixed constant. An atom's value is simply its own name. This gives us a type-safe way to interact with data. Atoms can be defined as follows:
-# base case
-def count([]), do: 0
-
-# recursive case
-def count([_head | tail]), do: 1 + count(tail)
+# All atoms are preceded with a ':' then follow with alphanumeric snake-cased characters
+variable = :an_atom
+
+_Atoms_ are internally represented by an integer in a lookup table, which are set automatically. It is not possible to change this internal value.
""".unindent().replace("\p", "\n")
testDiffThenRestore(trackDir, expectedDiff, "exercises"/"concept"/"bird-count"/".docs"/"introduction.md")
removeFile(trackDir / "exercises"/"concept"/"bird-count"/".docs"/"introduction.md.tpl")

main()
{.used.}

0 comments on commit afdae6b

Please sign in to comment.