Word Count is broken for me after recent update of tests.
Tests now do std.testing.checkAllAllocationFailures(). This is a good thing in most cases. It helps you to find places where you forgot to errdefer the cleanup. But sometimes it triggers false positives. The documentation says
If an allocation was made to fail during a run of
test_fn, buttest_fndidn’t returnerror.OutOfMemory, thenerror.SwallowedOutOfMemoryErroris returned fromcheckAllAllocationFailures. You may want to ignore this depending on whether or not the code you’re testing includes some strategies for recovering fromerror.OutOfMemory.
I want to ignore. This is what happened to me.
10/14 test_word_count.test.with quotations...FAIL (SwallowedOutOfMemoryError)
/opt/zig/lib/std/testing.zig:1148:17: 0x115974d in checkAllAllocationFailures__anon_22030 (std.zig)
return error.SwallowedOutOfMemoryError;
^
/mnt/exercism-iteration/test_word_count.zig:171:5: 0x115a9c9 in test.with quotations (test_word_count.zig)
try std.testing.checkAllAllocationFailures(
^
My solution calls std.StringHashMap.getOrPut(). This function recovers from error.OutOfMemory. Comments in source:
// If allocation fails, try to do the lookup anyway.
// If we find an existing item, we can return it.
// Otherwise return the error, we could not add another.
Please disable error.SwallowedOutOfMemoryError and allow me to use the standard library function that fits this exercise nicely.