Hello, I'm working on a unit test library. I've come to the point when library starts to work, and I would like to get your feedback on its ergonomics. It's still missing some features, but the core functionality is ready. Please let me know what could be improved, or which areas should I explain clearer in examples.
Repository: https://codeberg.org/KOOBAS/UltimaTest
There are examples included in the repository, that shows the library capabilities:
01 - shows how to create suites and tests
02 - shows how to use asserts/expects
03 - shows how to use mocks
04 - shows how to use test options to handle signals
I don't expect you to dive into the whole codebase. Focusing on the public API and examples would be really helpful. The only public header is the "include/ultimatest.h".
Here is how the library could be used (it's simplified example from my other project):
#include <ultimatest.h>
#include <widget.h>
#include <screen.h>
#include <context.h>
void widget_suite_prepare(void)
{
struct Widget *widget = ut_test_data(sizeof(struct Widget));
widget->type = TYPE_EMPTY;
widget->order = 0;
widget->position.y = 0;
widget->position.x = 0;
widget->size.h = 10;
widget->size.w = 20;
}
TestSuite(widget_suite, .prepare = &widget_suite_prepare);
Test(widget_suite, move_widget_should_return_error_if_widget_is_null)
{
ut_assert_eq(widget_move(nullptr, 4, 4), ERROR);
}
Test(widget_suite, move_widget_should_change_its_position)
{
struct Widget *widget = ut_get_test_data();
int new_y = 5;
int new_x = 7;
ut_assert_eq(widget_move(widget, new_y, new_x), OK);
ut_assert_eq(widget->position.y, new_y);
ut_assert_eq(widget->position.x, new_x);
}
Test(widget_suite, resize_widget_should_return_error_if_size_is_negative)
{
struct Widget *widget = ut_get_test_data();
int old_h = widget->size.h;
int old_w = widget->size.w;
ut_assert_eq(widget_resize(widget, -1, 30), ERROR);
ut_assert_eq(widget->size.h, old_h);
ut_assert_eq(widget->size.w, old_w);
ut_assert_eq(widget_resize(widget, 30, -1), ERROR);
ut_assert_eq(widget->size.h, old_h);
ut_assert_eq(widget->size.w, old_w);
}
Mock (void*, malloc, size_t);
Mock (int, getmaxy, WINDOW*);
Mock (int, getmaxx, WINDOW*);
Test(context_suite, init_should_create_screen_array_and_buffer)
{
const int max_y = 5;
const int max_x = 10;
const int screen_num = 5;
expect_call(ut_will_return(max_y), getmaxy, ut_any);
expect_call(ut_will_return(max_x), getmaxx, ut_any);
size_t buffer_size = sizeof(cchar_t) * max_x * max_y;
size_t screen_size = sizeof(struct Screen) * screen_num;
expect_call(ut_will_return(ut_test_data(buffer_size)), malloc, buffer_size);
expect_call(ut_will_return(ut_test_data(screen_size)), malloc, screen_size);
struct Context context;
ut_assert_eq(context_init(&context, screen_num), OK);
ut_assert_gt(context.size.h, 0);
ut_assert_gt(context.size.w, 0);
ut_assert_ne_ptr(context.screen, nullptr);
ut_assert_ne_ptr(context.buffer, nullptr);
}
Also, please let me know if the namespace is polluted by my prefixes or if the log messages or error messages are unclear.
AI usage: Only as googling tool (when searching for documentation, examples, etc. or discussing ideas). No code in the repository was generated by AI.