improve test logic, coloring, and fbar display
* Store whether the test was run in a boolean, to avoid classifying empty tests as pending when they have run * Update color scheme accordingly * Change the fbar first-level pixel share to give any extra pixel resulting from division truncation to the "done" section rather than the "empty" section, as this would sometimes cause the "empty" section to get 1 pixel for 0 tests
This commit is contained in:
parent
6e8b333e3b
commit
ae242222b3
|
@ -29,6 +29,8 @@ typedef struct ft_test {
|
|||
uint16_t passed;
|
||||
uint16_t skipped;
|
||||
uint16_t failed;
|
||||
/* Whether test was run */
|
||||
bool run;
|
||||
} ft_test;
|
||||
|
||||
/* ft_test_init(): Init counters and logs for a test */
|
||||
|
@ -37,9 +39,6 @@ void ft_test_init(ft_test *test);
|
|||
/* ft_test_run(): Reset and run a test */
|
||||
void ft_test_run(ft_test *test);
|
||||
|
||||
/* ft_test_done(): Check whether a test is done */
|
||||
bool ft_test_done(ft_test *test);
|
||||
|
||||
/* ft_assert(): Record an assertion in a test, return value */
|
||||
int ft_assert(ft_test *test, int expression,
|
||||
char const *file, int line, char const *expression_str);
|
||||
|
|
|
@ -132,7 +132,7 @@ int main(void)
|
|||
// Browse test results
|
||||
if(tab == 0 && e.type == FBROWSER_VALIDATED && e.source == browser) {
|
||||
ft_test *test = fbrowser_current_test(browser);
|
||||
if(ft_test_done(test) && test->widget) {
|
||||
if(test->run && test->widget) {
|
||||
jwidget *w = test->widget(test);
|
||||
if(w) {
|
||||
jwidget_add_child(results, w);
|
||||
|
@ -140,7 +140,7 @@ int main(void)
|
|||
jscene_set_focused_widget(scr->scene, w);
|
||||
}
|
||||
}
|
||||
else if(ft_test_done(test) && test->log) {
|
||||
else if(test->run && test->log) {
|
||||
flog_set_log(testlog, test->log, test->log_size);
|
||||
gscreen_show_tab(scr, 2);
|
||||
}
|
||||
|
|
21
src/test.c
21
src/test.c
|
@ -19,16 +19,13 @@ void ft_test_init(ft_test *test)
|
|||
|
||||
void ft_test_run(ft_test *test)
|
||||
{
|
||||
if(test->log) free(test->log);
|
||||
ft_test_init(test);
|
||||
test->run = true;
|
||||
if(!test->function) return;
|
||||
test->function(test);
|
||||
}
|
||||
|
||||
bool ft_test_done(ft_test *test)
|
||||
{
|
||||
return test->passed + test->skipped + test->failed > 0;
|
||||
}
|
||||
|
||||
int ft_assert(ft_test *test, int expression, char const *file, int line,
|
||||
char const *str)
|
||||
{
|
||||
|
@ -108,25 +105,25 @@ void ft_list_aggregate(ft_list *l)
|
|||
|
||||
int ft_test_color(ft_test const *t)
|
||||
{
|
||||
if(t->failed > 0) return FT_TEST_FAILED;
|
||||
if(t->failed > 0) return FT_TEST_FAILED;
|
||||
if(t->skipped > 0) return FT_TEST_SKIPPED;
|
||||
if(t->passed > 0) return FT_TEST_PASSED;
|
||||
if(t->function) return FT_TEST_PENDING;
|
||||
return FT_TEST_EMPTY;
|
||||
if(t->passed > 0) return FT_TEST_PASSED;
|
||||
|
||||
return (t->function && !t->run) ? FT_TEST_PENDING : FT_TEST_EMPTY;
|
||||
}
|
||||
|
||||
int ft_list_color(ft_list const *l)
|
||||
{
|
||||
if(l->failed > 0) return FT_TEST_FAILED;
|
||||
if(l->failed > 0) return FT_TEST_FAILED;
|
||||
if(l->skipped > 0) return FT_TEST_SKIPPED;
|
||||
|
||||
if(l->children) {
|
||||
for(int i = 0; l->children[i]; i++) {
|
||||
if(l->children[i]->function && l->children[i]->passed == 0)
|
||||
if(l->children[i]->function && l->children[i]->run == 0)
|
||||
return FT_TEST_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
if(l->passed > 0) return FT_TEST_PASSED;
|
||||
if(l->passed > 0) return FT_TEST_PASSED;
|
||||
return FT_TEST_EMPTY;
|
||||
}
|
||||
|
|
|
@ -115,9 +115,9 @@ static void fbar_poly_render(void *b0, int x, int y)
|
|||
bool guaranteed = (w > guaranteeable_min);
|
||||
|
||||
if(guaranteed) w -= guaranteeable_min;
|
||||
px.done = (st.done * w) / main;
|
||||
px.pending = (st.pending * w) / main;
|
||||
px.empty = w - px.done - px.pending;
|
||||
px.empty = (st.empty * w) / main;
|
||||
px.done = w - px.pending - px.empty;
|
||||
if(guaranteed) {
|
||||
if(st.done) px.done += 10;
|
||||
if(st.pending) px.pending += 10;
|
||||
|
|
Loading…
Reference in New Issue