I just finished the exercise Resistor Color in C on Exercism and found the TDD experience a bit frustrating. The exercise doesn’t provide function stubs so while the last test gets ignored:
the code won’t compile unless the color()
function gets defined.
I also think that this error message isn’t very beginner friendly while this currently is the third exercise on the C track:
Compiling tests.out
In file included from ./test-framework/unity.h:21,
from ./test_resistor_color.c:1:
./test_resistor_color.c: In function ‘test_colors’:
./test_resistor_color.c:33:42: error: implicit declaration of function ‘colors’ [-Werror=implicit-function-declaration]
33 | TEST_ASSERT_EQUAL_INT_ARRAY(expected, colors(), ARRAY_LENGTH(expected));
| ^~~~~~
./test-framework/unity_internals.h:892:176: note: in definition of macro ‘UNITY_TEST_ASSERT_EQUAL_INT_ARRAY’
892 | UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY)
| ^~~~~~
./test_resistor_color.c:33:4: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_ARRAY’
33 | TEST_ASSERT_EQUAL_INT_ARRAY(expected, colors(), ARRAY_LENGTH(expected));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./test-framework/unity_internals.h:892:155: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
892 | nts, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY)
| ^
./test-framework/unity.h:295:100: note: in expansion of macro ‘UNITY_TEST_ASSERT_EQUAL_INT_ARRAY’
295 | SSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./test_resistor_color.c:33:4: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_ARRAY’
33 | TEST_ASSERT_EQUAL_INT_ARRAY(expected, colors(), ARRAY_LENGTH(expected));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [makefile:37: tests.out] Error 1
I don’t know enough about C to propose an improvement. Is it possible to ignore this type of error during the TDD phase? What’s the reasoning for not including function stubs? Is it so people are forced to learn about header files?
Thank you for your work on the C track, looking forward to your responses and insights. :)