From 6d3a6d9605ed91da3c14cd2a8085e3e9594ff4cd Mon Sep 17 00:00:00 2001 From: Ryan Hartlage Date: Mon, 7 Oct 2024 18:22:33 -0400 Subject: [PATCH 1/3] Spec generator - Respect tests.toml --- bin/generate-spec | 24 ++++++++++++++++++- .../practice/book-store/book-store_spec.lua | 5 ++-- .../state-of-tic-tac-toe_spec.lua | 9 ------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/bin/generate-spec b/bin/generate-spec index dc1f5f7..98607eb 100755 --- a/bin/generate-spec +++ b/bin/generate-spec @@ -15,6 +15,24 @@ local function write_file(path, contents) f:close() end +local function included_tests_from_toml(path) + local included = {} + local last_uuid + + for line in io.lines(path) do + for uuid in line:gmatch('%[(.+)%]') do + last_uuid = uuid + included[uuid] = true + end + + if line:match('^include%s*=%s*false') then + included[last_uuid] = nil + end + end + + return included +end + local exercise_name = arg[1] local exercise_directory = 'exercises/practice/' .. exercise_name @@ -33,6 +51,8 @@ local canonical_data = json.decode(canonical_data_json) local spec_generator = require('spec_generator') +local included_tests = included_tests_from_toml(exercise_directory .. '/.meta/tests.toml') + local function process(node) if node.cases then local output = {} @@ -49,7 +69,9 @@ local function process(node) local cases = {} for _, case in ipairs(node.cases) do - table.insert(cases, process(case)) + if not case.uuid or included_tests[case.uuid] then + table.insert(cases, process(case)) + end end table.insert(output, table.concat(cases, '\n\n')) diff --git a/exercises/practice/book-store/book-store_spec.lua b/exercises/practice/book-store/book-store_spec.lua index 9e75ee2..676c9ce 100644 --- a/exercises/practice/book-store/book-store_spec.lua +++ b/exercises/practice/book-store/book-store_spec.lua @@ -76,12 +76,11 @@ describe('book-store', function() assert.are.same(10240, book_store.total(basket)) end) - -- LuaFormatter off - it('check that groups of four are created properly even when there are more groups of three than groups of five', function() + it('check that groups of four are created properly even when there are more groups of three than groups of five', + function() local basket = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 } assert.are.same(14560, book_store.total(basket)) end) - -- LuaFormatter on it('one group of one and four is cheaper than one group of two and three', function() local basket = { 1, 1, 2, 3, 4 } diff --git a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua index 0784cf1..774613c 100644 --- a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua +++ b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua @@ -65,15 +65,6 @@ describe('state-of-tic-tac-toe', function() assert.are.same('win', state_of_tic_tac_toe.gamestate(board)) end) - it('finished game where x won via middle row victory', function() - local board = { - 'O O', -- - 'XXX', -- - ' O ' -- - } - assert.are.same('win', state_of_tic_tac_toe.gamestate(board)) - end) - it('finished game where x won via middle row victory', function() local board = { 'O ', -- From 6d8eef4b434835119723128891f9f4c37eaed0a9 Mon Sep 17 00:00:00 2001 From: Ryan Hartlage Date: Mon, 7 Oct 2024 18:32:08 -0400 Subject: [PATCH 2/3] Be slightly more restrictive when matching UUIDs --- bin/generate-spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/generate-spec b/bin/generate-spec index 98607eb..e9c5fd7 100755 --- a/bin/generate-spec +++ b/bin/generate-spec @@ -20,7 +20,7 @@ local function included_tests_from_toml(path) local last_uuid for line in io.lines(path) do - for uuid in line:gmatch('%[(.+)%]') do + for uuid in line:gmatch('%[([%x%-]+)%]') do last_uuid = uuid included[uuid] = true end From d6e155199b4c45aca09d62b15dd267b66f23921e Mon Sep 17 00:00:00 2001 From: Ryan Hartlage Date: Mon, 7 Oct 2024 18:34:01 -0400 Subject: [PATCH 3/3] Extract tests.toml path to local variable --- bin/generate-spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/generate-spec b/bin/generate-spec index e9c5fd7..14bd569 100755 --- a/bin/generate-spec +++ b/bin/generate-spec @@ -42,6 +42,7 @@ package.path = package.path .. ';' .. exercise_directory .. '/.meta/?.lua' local canonical_data_url = 'https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/' .. exercise_name .. '/canonical-data.json' local canonical_data_path = 'canonical-data/' .. exercise_name .. '.json' local spec_path = exercise_directory .. '/' .. exercise_name .. '_spec.lua' +local tests_toml_path = exercise_directory .. '/.meta/tests.toml' assert(os.execute('mkdir -p `dirname ' .. canonical_data_path .. '`')) assert(os.execute('curl ' .. canonical_data_url .. ' -s -o ' .. canonical_data_path)) @@ -51,7 +52,7 @@ local canonical_data = json.decode(canonical_data_json) local spec_generator = require('spec_generator') -local included_tests = included_tests_from_toml(exercise_directory .. '/.meta/tests.toml') +local included_tests = included_tests_from_toml(tests_toml_path) local function process(node) if node.cases then