Skip to content

Commit c16c3b1

Browse files
authored
Move hardcoded exclusions from the generator script to the spec_generator module (#119)
1 parent d5d8b6a commit c16c3b1

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
If there are, add `include = false` properties in the exercise's `.meta/tests.toml` file.
5858
59+
If there are whole test groups to exclude, add an "exclusions" property to the spec_generator module (see below).
60+
5961
1. Considering the canonical data, decide if this exercise makes sense to use a test generator.
6062
6163
- If no:
@@ -76,6 +78,8 @@
7678
- `case` is the Lua object for the test case
7779
- `level`, default value 2, is the indentation level of the body.
7880
- (optional) `test_helpers`: (string) a block of code that gets added at the top of the top-level `describe` block.
81+
- (optional) `exclusions`: (list of tables) identifies things from the canonical data to exclude.
82+
- See `simple-linked-list` and `gigasecond` spec generators for examples.
7983
8084
Look to see how it's implemented for other exercises.
8185
The `space-age` one is interesting: it uses the test_helpers block to register a custom assertion, and has expected errors.

bin/generate-spec

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ included_tests_from_toml = (path) ->
4848

4949
-- ----------------------------------------------------------
5050
-- functions marked as global so spec_generators can see them
51-
export indent, quote, is_json_null, is_empty
51+
export indent, quote, is_json_null, is_empty, contains
5252

5353
indent = (text, level) -> string.rep(' ', level) .. text
5454

@@ -63,15 +63,25 @@ is_empty = (t) -> not next t
6363
-- the dkjson `json.null` value is an empty table
6464
is_json_null = (value) -> type(value) == 'table' and is_empty(value)
6565

66+
-- a table contains a value
67+
contains = (t, v) ->
68+
for elem in *t
69+
return true if elem == v
70+
false
71+
6672
-- ----------------------------------------------------------
6773

6874

6975
test_cmd = 'it'
7076

7177
process = (node, level=0) ->
72-
if exercise_name == 'simple-linked-list' and node.description == 'toList LIFO'
73-
-- skip this whole node
74-
return ''
78+
-- exclude the test cases in this node?
79+
for exclusion in *(spec_generator.exclusions or {})
80+
if node[exclusion.key]
81+
if exclusion.op == 'contains'
82+
return '' if contains node[exclusion.key], exclusion.value
83+
else
84+
return '' if node[exclusion.key] == exclusion.value
7585

7686
if node.cases
7787
output = {}

exercises/practice/simple-linked-list/.meta/spec_generator.moon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ int_list = (list) -> "{#{table.concat list, ', '}}"
3131
table.insert lines, "assert.are.same #{int_list op.expected}, result"
3232

3333
table.concat [indent line, level for line in *lines], '\n'
34+
35+
exclusions: {
36+
{key: 'description', value: 'toList LIFO'}
37+
}
3438
}

0 commit comments

Comments
 (0)