-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4902a4e
commit 2edba7c
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Synopsis: | ||
# Generate the tests for each exercise with a generator template. | ||
|
||
# Example: generate tests for all exercises with a generator template | ||
# bin/generate-tests | ||
|
||
# Example: generate tests for a single exercise with a generator template | ||
# bin/generate-tests two-fer | ||
|
||
set -eo pipefail | ||
|
||
die() { echo "$*" >&2; exit 1; } | ||
|
||
required_tool() { | ||
command -v "${1}" >/dev/null 2>&1 || | ||
die "${1} is required but not installed. Please install it and make sure it's in your PATH." | ||
} | ||
|
||
required_tool clj | ||
|
||
exercise_slug="${1}" | ||
|
||
pushd generators >/dev/null || die "Could not change to the 'generators' directory" | ||
|
||
if [ -z "${exercise_slug}" ]; then | ||
clj -X generator/run | ||
else | ||
clj -X generator/run :exercise "${exercise_slug}" | ||
fi | ||
|
||
popd >/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
(ns generator | ||
(:require [canonical-data] | ||
(:require [clojure.string :as str] | ||
[canonical-data] | ||
[templates] | ||
[log])) | ||
|
||
(defn- slugs-to-generate [args] | ||
(defn- slugs-to-generate [slug] | ||
(let [slugs templates/exercises-with-template] | ||
(if-let [slug (first args)] | ||
(if (str/blank? slug) | ||
slugs | ||
(if (contains? slugs slug) | ||
[slug] | ||
(log/error (str "No template found for exercise '" slug "'"))) | ||
slugs))) | ||
(log/error (str "No template found for exercise '" slug "'")))))) | ||
|
||
(defn- run [args] | ||
(defn- run [{:keys [exercise]}] | ||
(canonical-data/sync-repo) | ||
(doseq [slug (slugs-to-generate args)] | ||
(doseq [slug (slugs-to-generate (str exercise))] | ||
(log/normal (str "Generating tests for exercise '" slug "'")) | ||
(templates/generate-tests-file slug (canonical-data/test-cases slug)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters