Skip to content

Commit

Permalink
Fix Makefile and bin/generate (#193)
Browse files Browse the repository at this point in the history
Bin-tooling fixes

* Fix recipe of make target 'test'
* Make bin/generate work again
* Remove parsing of 'version' from canonical-data.json since this key was removed in exercism/problem-specifications PR #1678
* Remove FIXME concerning renaming of functions since this seems to be not easily fixable with the current setting
* Fix syntax errors in make target gha
  • Loading branch information
rainij authored Apr 2, 2022
1 parent 57fb1d3 commit 44e1ad8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dirs := $(wildcard exercises/*)
dirs := $(wildcard exercises/practice/*)
all-tests := $(addprefix test-, $(notdir $(dirs)))

COMMIT_RANGE := HEAD
Expand All @@ -25,20 +25,20 @@ gha:
@$(MAKE) -s debug
$(eval tests := $(shell \
git diff-tree --name-only -r --diff-filter=AM $(COMMIT_RANGE) | \
perl -n -e '/exercises\/practice/([a-z-_]+)\/.+\.sml/ && print "test-$$1\n"' | uniq))
perl -n -e '/exercises\/practice\/([a-z-_]+)\/.+\.sml/ && print "test-$$1\n"' | uniq))
$(if $(tests), @echo Tests: $(tests), @echo 'Nothing to test.')
$(if $(tests), @$(MAKE) -s $(tests))

test-%:
$(eval exercise := $(patsubst test-%, %, $@))
@echo
@ls ./exercises/practice/$(exercise)/README.md > /dev/null
@ls ./exercises/practice/$(exercise)/.docs/instructions.md > /dev/null
@# check stub type
@cd ./exercises/practice/$(exercise) && \
poly -q --use test | grep 'error: Type error' | \
wc -l | xargs -I @ expr @ = 0 > /dev/null || \
{ echo '$(exercise).sml is faulty'; exit 1; }
@cd ./exercises/practice/$(exercise) && cat test.sml | sed 's/$(exercise).sml/.meta/example.sml/' | poly -q
@cd ./exercises/practice/$(exercise) && cat test.sml | sed 's/$(exercise).sml/.meta\/example.sml/' | poly -q
@echo

.PHONY: test
14 changes: 6 additions & 8 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ def sml_value(value, smltype='', force=False):


def get_fn_args(case):
reserved_keys = {'property', 'expected', 'description', 'comments'}
case_input = case["input"]
return OrderedDict(
(k, case[k])
for k in sorted(case.keys())
if k not in reserved_keys
(k, case_input[k])
for k in sorted(case_input.keys())
)


Expand Down Expand Up @@ -157,7 +156,8 @@ def extract_signatures(data, force=False):
def expectation(signature, fn, args, expected, force=False):
tmpl = '(fn _ => %s |> Expect.%s)'
output = sml_value(expected, signature['output'], force=force)
invocation = '%s (%s)' % (
invocation_tmpl = '%s %s' if len(args) == 1 else '%s (%s)'
invocation = invocation_tmpl % (
fn,
', '.join((
sml_value(val, signature['args'][arg], force=force)
Expand Down Expand Up @@ -213,8 +213,6 @@ def generate_test_content(data, signature, force=False):
return acc

return '\n'.join([
'(* version %s *)' % data['version'],
'',
'use "testlib.sml";',
'use "%s.sml";' % data['exercise'],
'',
Expand Down Expand Up @@ -260,7 +258,7 @@ FLAGS = TEST | STUB | EXAMPLE

def generate(exercise, flags, force=False):
root = Path(__file__).parent.parent.absolute()
path = root / 'exercises' / exercise
path = root / 'exercises' / 'practice' / exercise

if not path.exists():
path.mkdir()
Expand Down

0 comments on commit 44e1ad8

Please sign in to comment.