Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec generator - Respect tests.toml #524

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion bin/generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand All @@ -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'))

Expand Down
5 changes: 2 additions & 3 deletions exercises/practice/book-store/book-store_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -79 to -84
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-generated all specs to make sure that we hadn't inadvertently included tests that shouldn't have been included. When I did this it reverted the change that was made in #513 to fix an issue with the test runner that has since been resolved.


it('one group of one and four is cheaper than one group of two and three', function()
local basket = { 1, 1, 2, 3, 4 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -68 to -75
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the test that was manually removed. It must have slipped back in the next time the spec generator was run. We should be protected against this now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a different test case I accidentally neglected to remove.

The case I removed:

description = "Invalid boards -> Invalid board"
include = false

was essentially the same as

description = "Invalid boards -> Invalid board: X won and O kept playing"

but with a different error string. (I stopped checking the error strings, anticipating the test case might get regenerated.)

In general, does this track have a preference for or against checking error strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, does this track have a preference for or against checking error strings?

At least for recent tests I've been checking the strings. I don't feel strongly one way or the other.


it('finished game where x won via middle row victory', function()
local board = {
'O ', --
Expand Down
Loading