From ba4cf35804bc34075bd8d5dda841271a424b637a Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Fri, 26 Sep 2014 20:08:37 -0700 Subject: [PATCH 1/2] Return bad error code when tests fail --- src/Layout-test-utils.c | 4 +++- src/Layout-test-utils.h | 2 +- src/__tests__/Layout-test.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Layout-test-utils.c b/src/Layout-test-utils.c index 1f9c4fc5..833ab0f9 100644 --- a/src/Layout-test-utils.c +++ b/src/Layout-test-utils.c @@ -92,7 +92,7 @@ void test(const char *name, css_node_t *style, css_node_t *expected_layout) { } } -void tests_finished() { +int tests_finished() { failed_test_t *failed_test = failed_test_head; printf("\n"); @@ -121,8 +121,10 @@ void tests_finished() { if (tests_failed > 0) { printf("TESTS FAILED: %d\n", tests_failed); + return 1; } else { printf("ALL TESTS PASSED\n"); + return 0; } } diff --git a/src/Layout-test-utils.h b/src/Layout-test-utils.h index 216d0b00..716e3d58 100644 --- a/src/Layout-test-utils.h +++ b/src/Layout-test-utils.h @@ -5,7 +5,7 @@ #include void test(const char *name, css_node_t *style, css_node_t *expected_layout); -void tests_finished(void); +int 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/__tests__/Layout-test.c b/src/__tests__/Layout-test.c index 8593ad06..3c6ab1ae 100644 --- a/src/__tests__/Layout-test.c +++ b/src/__tests__/Layout-test.c @@ -3166,5 +3166,5 @@ int main() test("should layout with absolutely position bottom", root_node, root_layout); } /** END_GENERATED **/ - tests_finished(); + return tests_finished(); } -- 2.50.1.windows.1 From 308d0edc0b55e5c1e0790245c4ccc8033eacdbe9 Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Fri, 26 Sep 2014 20:38:34 -0700 Subject: [PATCH 2/2] Add test that makes sure text consts are in sync --- RunLayoutTests.html | 1 + src/Layout-test-utils.js | 19 +++++++++++-------- src/__tests__/Layout-consts-test.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/__tests__/Layout-consts-test.js diff --git a/RunLayoutTests.html b/RunLayoutTests.html index b5283fa6..f97ad606 100755 --- a/RunLayoutTests.html +++ b/RunLayoutTests.html @@ -18,5 +18,6 @@ + diff --git a/src/Layout-test-utils.js b/src/Layout-test-utils.js index 3f2a2b60..62796f32 100644 --- a/src/Layout-test-utils.js +++ b/src/Layout-test-utils.js @@ -269,15 +269,17 @@ var layoutTestUtils = (function() { big: 'loooooooooong with space', }; + var preDefinedTextSizes = { + smallWidth: 34.671875, + smallHeight: 18, + bigWidth: 172.421875, + bigHeight: 36, + bigMinWidth: 100.453125 + }; + var textSizes; if (typeof require === 'function') { - textSizes = { - smallWidth: 34.671875, - smallHeight: 18, - bigWidth: 172.421875, - bigHeight: 36, - bigMinWidth: 100.453125 - }; + textSizes = preDefinedTextSizes; } else { textSizes = { smallWidth: measureTextSizes(texts.small, 0).width, @@ -291,6 +293,7 @@ var layoutTestUtils = (function() { return { texts: texts, textSizes: textSizes, + preDefinedTextSizes: preDefinedTextSizes, testLayout: function(node, expectedLayout) { var layout = computeCSSLayout(node); var domLayout = computeDOMLayout(node); @@ -333,7 +336,7 @@ var layoutTestUtils = (function() { fn.toString = function() { return text; }; return fn; } - } + }; })(); if (typeof module !== 'undefined') { diff --git a/src/__tests__/Layout-consts-test.js b/src/__tests__/Layout-consts-test.js new file mode 100644 index 00000000..52523148 --- /dev/null +++ b/src/__tests__/Layout-consts-test.js @@ -0,0 +1,14 @@ +/* globals layoutTestUtils */ + +var textSizes = layoutTestUtils.textSizes; +var preDefinedTextSizes = layoutTestUtils.preDefinedTextSizes; + +describe('Layout tests consts', function() { + it('keeps browser text measurements in sync with predefined consts', function() { + expect(preDefinedTextSizes).toEqual( + textSizes, + 'Looks like browser has updated its text measurements functions. ' + + 'You need to update `preDefinedTextSizes` in Layout-test-utils.js' + ); + }); +}); -- 2.50.1.windows.1