diff --git a/src/Layout-test-utils.c b/src/Layout-test-utils.c index e90a4c2e..b71dd4ce 100644 --- a/src/Layout-test-utils.c +++ b/src/Layout-test-utils.c @@ -2,6 +2,30 @@ #include "Layout-test-utils.h" #include +typedef struct failed_test_t { + struct failed_test_t *next; + const char *name; + css_node_t *style; + css_node_t *expected; +} failed_test_t; + +static failed_test_t *failed_test_head = NULL; +static failed_test_t *failed_test_tail = NULL; +static void add_failed_test(const char *name, css_node_t *style, css_node_t *expected) { + failed_test_t *failed_test = malloc(sizeof(failed_test_t)); + failed_test->name = name; + failed_test->style = style; + failed_test->expected = expected; + + if (!failed_test_head) { + failed_test_head = failed_test; + failed_test_tail = failed_test; + } else { + failed_test_tail->next = failed_test; + failed_test_tail = failed_test; + } +} + static bool eq(float a, float b) { return fabs(a - b) < 0.0001; } @@ -49,21 +73,47 @@ void test(const char *name, css_node_t *style, css_node_t *expected_layout) { layoutNode(style, CSS_UNDEFINED); if (!are_layout_equal(style, expected_layout)) { - printf("%sFAIL%s %s\n", "\x1B[31m", "\x1B[0m", name); + printf("%sF%s", "\x1B[31m", "\x1B[0m"); + add_failed_test(name, style, expected_layout); + } else { + printf("%s.%s", "\x1B[32m", "\x1B[0m"); + free_css_node(style); + free_css_node(expected_layout); + } +} + +void tests_finished() { + failed_test_t *failed_test = failed_test_head; + printf("\n"); + + int tests_failed = 0; + while (failed_test) { + printf("%sFAIL%s %s\n", "\x1B[31m", "\x1B[0m", failed_test->name); printf("Input: "); - print_css_node(style, CSS_PRINT_STYLE); + print_css_node(failed_test->style, CSS_PRINT_STYLE); printf("Output: "); - print_css_node(style, CSS_PRINT_LAYOUT); + print_css_node(failed_test->style, CSS_PRINT_LAYOUT); printf("Expected: "); - print_css_node(expected_layout, CSS_PRINT_LAYOUT); - } else { - printf("%sPASS%s %s\n", "\x1B[32m", "\x1B[0m", name); - } + print_css_node(failed_test->expected, CSS_PRINT_LAYOUT); - free_css_node(style); - free_css_node(expected_layout); + free_css_node(failed_test->style); + free_css_node(failed_test->expected); + + failed_test_t *next_failed_test = failed_test->next; + free(failed_test); + failed_test = next_failed_test; + + tests_failed++; + } + printf("\n\n"); + + if (tests_failed > 0) { + printf("TESTS FAILED: %d\n", tests_failed); + } else { + printf("ALL TESTS PASSED\n"); + } } static css_node_t* get_child(void *context, int i) { diff --git a/src/Layout-test-utils.h b/src/Layout-test-utils.h index 5cba72c5..216d0b00 100644 --- a/src/Layout-test-utils.h +++ b/src/Layout-test-utils.h @@ -5,6 +5,7 @@ #include void test(const char *name, css_node_t *style, css_node_t *expected_layout); +void tests_finished(void); css_dim_t measure(void *context, float width); void init_css_node_children(css_node_t *node, int children_count); css_node_t *new_test_css_node(void); diff --git a/src/Layout-test-utils.js b/src/Layout-test-utils.js index 960bf9b8..1f43099b 100644 --- a/src/Layout-test-utils.js +++ b/src/Layout-test-utils.js @@ -283,6 +283,9 @@ var layoutTestUtils = (function() { expect({i: i, node: node, layout: computeCSSLayout(node)}) .toEqual({i: i, node: node, layout: computeDOMLayout(node)}); }, + testsFinished: function() { + console.log('tests finished!'); + }, computeLayout: computeCSSLayout, computeDOMLayout: computeDOMLayout, reduceTest: reduceTest, diff --git a/src/__tests__/Layout-test.c b/src/__tests__/Layout-test.c index d6340b9c..b362580e 100644 --- a/src/__tests__/Layout-test.c +++ b/src/__tests__/Layout-test.c @@ -6525,4 +6525,6 @@ int main() test("Random #99", root_node, root_layout); } + + tests_finished(); } diff --git a/src/transpile.html b/src/transpile.html index 9a838e86..e515acd7 100644 --- a/src/transpile.html +++ b/src/transpile.html @@ -237,6 +237,8 @@ function printLayout(test) { add('test("' + test.name.replace(/"/g, '\\"') + '", root_node, root_layout);'); level--; add('}'); + add(''); + add('tests_finished();'); return res.join('\n'); }