Skip to content

Commit

Permalink
Merge branch 'new' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dango authored Jul 28, 2024
2 parents e9457c7 + a9f1aee commit bf8fb5a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/bin/ys*
/note/
/shellcheck*
/.clojure/
/out.txt
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ YAML_FILES := \
config.yaml \
docs/config.yaml \

CLOJURE_REPO := .clojure
CLOJURE_REPO_URL := https://github.com/exercism/clojure

SHELLCHECK_VERSION := v0.10.0
SHELLCHECK_REPO := https://github.com/koalaman/shellcheck
SHELLCHECK_RELEASES := $(SHELLCHECK_REPO)/releases/download
Expand All @@ -52,14 +55,15 @@ SHELLCHECK_RELEASE := \
LINE := $(shell printf '%.0s-' {1..80})

exercise ?=
test ?=
v ?=

ifeq (,$(exercise))
exercise-name := all exercises
override exercise := exercises/practice/*/.meta/test/*.ys
ifeq (,$(test))
test-name := all exercises
override test := exercises/practice/*/.meta/test/*.ys
else
exercise-name := $(exercise)
override exercise := exercises/practice/$(exercise)/test/.meta/*.ys
test-name := $(test)
override test := exercises/practice/$(test)/test/.meta/*.ys
endif

export YSPATH := $(shell IFS=:; p=$aexercises/practice/*/.meta$b; \
Expand All @@ -69,6 +73,12 @@ export YSPATH := $(shell IFS=:; p=$aexercises/practice/*/.meta$b; \
#------------------------------------------------------------------------------
default:

new: $(CFGLET) $(YS) $(CLOJURE_REPO)
ifndef exercise
$(error Please set the 'exercise' variable)
endif
exercise=$(exercise) new-exercise

check: $(YS) $(CHECKS)
@echo $(LINE)

Expand All @@ -81,8 +91,8 @@ deps: $(YS) $(CFGLET) $(SHELLCHECK)

test-exercises: $(YS)
@echo $(LINE)
@echo '*** Running tests for $(exercise-name)'
prove $(if $v,-v ,)$(exercise)
@echo '*** Running tests for $(test-name)'
prove $(if $v,-v ,)$(test)
@echo '*** All exercises test ok'

check-yaml: $(YS) $(YAML_FILES)
Expand Down Expand Up @@ -111,7 +121,7 @@ check-exercism: $(CFGLET) update
check-verify: update
@echo $(LINE)
@echo '*** Test all exercises are verified'
$(VERIFY) $(exercise)
$(VERIFY) $(test)
@echo '*** All exercises are verified OK'
@echo

Expand Down Expand Up @@ -153,3 +163,6 @@ $(SHELLCHECK_DIR): $(SHELLCHECK_TAR)

$(SHELLCHECK_TAR):
wget $(SHELLCHECK_RELEASE)

$(CLOJURE_REPO):
git clone $(CLOJURE_REPO_URL) $@
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Actions for this repository are all automated in the Makefile.
* `make check`
* `make test`
* `make test v=1` # verbose
* `make test exercise=hello-world` # Test single exercise
* `make test test=hello-world` # Test single exercise


### YAMLScript Track Repository Testing
Expand All @@ -36,4 +36,4 @@ Run `make check` to check:

To test all exercises, run `make test`.

To test a single exercise, run `make test exercise=<exercise-slug>`.
To test a single exercise, run `make test test=<exercise-slug>`.
49 changes: 49 additions & 0 deletions bin/new-exercise
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -euo pipefail

die() {
echo "Error: $*" >&2
exit 1
}

[[ $exercise ]] ||
die "The 'exercise' variable not set"

(
set -x
git checkout -- config.json config.yaml
rm -fr "exercises/practice/$exercise"
)

configlet create --practice-exercise="$exercise"

new_yaml=$(mktemp)
ys -Y config.json > "$new_yaml"
new_section=$(
diff -u config.yaml "$new_yaml" |
perl -p0e '
s{(?s:.*)\n(\+\ \ -\ slug.*\n(?:\+.*\n)+)(?s:.*)}{$1};
s/^\+//mg' || true
)
top_section=$(grep -B999 '^tags:' config.yaml | head -n -2)
bottom_section=$(grep -A999 '^tags:' config.yaml)

(
cat <<...
$top_section
$new_section
$bottom_section
...
) > config.yaml

(
git status --ignored
tree -a src/leap/ \
src/reverse-string/ \
.clojure/exercises/practice/reverse-string/
) &> out.txt

# make update
12 changes: 3 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
],
"example": [
".meta/%{kebab_slug}.ys"
],
"exemplar": []
]
},
"exercises": {
"concept": [],
"practice": [
{
"slug": "hello-world",
Expand All @@ -47,22 +45,18 @@
"uuid": "a6e60d12-8265-404a-b34e-69b6d00014fd",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": []
"difficulty": 1
},
{
"slug": "two-fer",
"name": "Two-Fer",
"uuid": "0957cb25-13dd-43a0-ab3c-ba452ffa5508",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": []
"difficulty": 1
}
]
},
"concepts": [],
"key_features": [],
"tags": [
"execution_mode/compiled",
"execution_mode/interpreted",
Expand Down
10 changes: 1 addition & 9 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ files:
solution:
- '%{kebab_slug}.ys'
test:
- '%{kebab_slug}/test/test-1.ys'
- 'test/test-1.ys'
example:
- .meta/%{kebab_slug}.ys
exemplar: []

exercises:
concept: []
practice:
- slug: hello-world
name: Hello World
Expand All @@ -53,19 +51,14 @@ exercises:
practices: []
prerequisites: []
difficulty: 1
topics: []

- slug: two-fer
name: Two-Fer
uuid: 0957cb25-13dd-43a0-ab3c-ba452ffa5508
practices: []
prerequisites: []
difficulty: 1
topics: []

concepts: []

key_features: []
tags:
- execution_mode/compiled
- execution_mode/interpreted
Expand All @@ -83,4 +76,3 @@ tags:
- used_for/games
- used_for/scientific_calculations
- used_for/scripts

0 comments on commit bf8fb5a

Please sign in to comment.