Skip to content

Commit 257ff32

Browse files
authored
Spec generator - Respect tests.toml (#524)
* Spec generator - Respect tests.toml * Be slightly more restrictive when matching UUIDs * Extract tests.toml path to local variable
1 parent 59263a8 commit 257ff32

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

bin/generate-spec

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ local function write_file(path, contents)
1515
f:close()
1616
end
1717

18+
local function included_tests_from_toml(path)
19+
local included = {}
20+
local last_uuid
21+
22+
for line in io.lines(path) do
23+
for uuid in line:gmatch('%[([%x%-]+)%]') do
24+
last_uuid = uuid
25+
included[uuid] = true
26+
end
27+
28+
if line:match('^include%s*=%s*false') then
29+
included[last_uuid] = nil
30+
end
31+
end
32+
33+
return included
34+
end
35+
1836
local exercise_name = arg[1]
1937

2038
local exercise_directory = 'exercises/practice/' .. exercise_name
@@ -24,6 +42,7 @@ package.path = package.path .. ';' .. exercise_directory .. '/.meta/?.lua'
2442
local canonical_data_url = 'https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/' .. exercise_name .. '/canonical-data.json'
2543
local canonical_data_path = 'canonical-data/' .. exercise_name .. '.json'
2644
local spec_path = exercise_directory .. '/' .. exercise_name .. '_spec.lua'
45+
local tests_toml_path = exercise_directory .. '/.meta/tests.toml'
2746

2847
assert(os.execute('mkdir -p `dirname ' .. canonical_data_path .. '`'))
2948
assert(os.execute('curl ' .. canonical_data_url .. ' -s -o ' .. canonical_data_path))
@@ -33,6 +52,8 @@ local canonical_data = json.decode(canonical_data_json)
3352

3453
local spec_generator = require('spec_generator')
3554

55+
local included_tests = included_tests_from_toml(tests_toml_path)
56+
3657
local function process(node)
3758
if node.cases then
3859
local output = {}
@@ -49,7 +70,9 @@ local function process(node)
4970

5071
local cases = {}
5172
for _, case in ipairs(node.cases) do
52-
table.insert(cases, process(case))
73+
if not case.uuid or included_tests[case.uuid] then
74+
table.insert(cases, process(case))
75+
end
5376
end
5477
table.insert(output, table.concat(cases, '\n\n'))
5578

exercises/practice/book-store/book-store_spec.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ describe('book-store', function()
7676
assert.are.same(10240, book_store.total(basket))
7777
end)
7878

79-
-- LuaFormatter off
80-
it('check that groups of four are created properly even when there are more groups of three than groups of five', function()
79+
it('check that groups of four are created properly even when there are more groups of three than groups of five',
80+
function()
8181
local basket = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 }
8282
assert.are.same(14560, book_store.total(basket))
8383
end)
84-
-- LuaFormatter on
8584

8685
it('one group of one and four is cheaper than one group of two and three', function()
8786
local basket = { 1, 1, 2, 3, 4 }

exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@ describe('state-of-tic-tac-toe', function()
6565
assert.are.same('win', state_of_tic_tac_toe.gamestate(board))
6666
end)
6767

68-
it('finished game where x won via middle row victory', function()
69-
local board = {
70-
'O O', --
71-
'XXX', --
72-
' O ' --
73-
}
74-
assert.are.same('win', state_of_tic_tac_toe.gamestate(board))
75-
end)
76-
7768
it('finished game where x won via middle row victory', function()
7869
local board = {
7970
'O ', --

0 commit comments

Comments
 (0)