From 736c28b35926d92e65249c3d3f45afee0ee19fc6 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 19 Jul 2019 18:27:16 -0700 Subject: [PATCH] Update Dart engine tests to check for assertion failures only when running in debug mode (#9959) --- testing/dart/compositing_test.dart | 174 +++++++++++++++++------------ testing/dart/gradient_test.dart | 30 ++--- 2 files changed, 121 insertions(+), 83 deletions(-) diff --git a/testing/dart/compositing_test.dart b/testing/dart/compositing_test.dart index a7b8e9a7c8f..53812d9be4b 100644 --- a/testing/dart/compositing_test.dart +++ b/testing/dart/compositing_test.dart @@ -24,10 +24,13 @@ void main() { 0, 0, 1, 0, 0, 0, 0, ]); - expect( - () => builder.pushTransform(matrix4WrongLength), - throwsA(const TypeMatcher()), - ); + assert(() { + expect( + () => builder.pushTransform(matrix4WrongLength), + throwsA(const TypeMatcher()), + ); + return true; + }()); final Float64List matrix4NaN = Float64List.fromList([ 1, 0, 0, 0, @@ -35,10 +38,13 @@ void main() { 0, 0, 1, 0, 0, 0, 0, double.nan, ]); - expect( - () => builder.pushTransform(matrix4NaN), - throwsA(const TypeMatcher()), - ); + assert(() { + expect( + () => builder.pushTransform(matrix4NaN), + throwsA(const TypeMatcher()), + ); + return true; + }()); final Float64List matrix4Infinity = Float64List.fromList([ 1, 0, 0, 0, @@ -46,10 +52,13 @@ void main() { 0, 0, 1, 0, 0, 0, 0, double.infinity, ]); - expect( - () => builder.pushTransform(matrix4Infinity), - throwsA(const TypeMatcher()), - ); + assert(() { + expect( + () => builder.pushTransform(matrix4Infinity), + throwsA(const TypeMatcher()), + ); + return true; + }()); }); test('SceneBuilder accepts typed layers', () { @@ -76,12 +85,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); pushFunction(builder2, layer); builder2.pop(); - try { - builder2.addRetained(layer); - fail('Expected addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('The layer is already being used')); - } + assert(() { + try { + builder2.addRetained(layer); + fail('Expected addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('The layer is already being used')); + } + return true; + }()); builder2.build(); } @@ -94,12 +106,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); builder2.addRetained(layer); - try { - pushFunction(builder2, layer); - fail('Expected push to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('The layer is already being used')); - } + assert(() { + try { + pushFunction(builder2, layer); + fail('Expected push to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('The layer is already being used')); + } + return true; + }()); builder2.build(); } @@ -112,12 +127,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); builder2.addRetained(layer); - try { - builder2.addRetained(layer); - fail('Expected second addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('The layer is already being used')); - } + assert(() { + try { + builder2.addRetained(layer); + fail('Expected second addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('The layer is already being used')); + } + return true; + }()); builder2.build(); } @@ -130,12 +148,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); pushFunction(builder2, layer); - try { - pushFunction(builder2, layer); - fail('Expected push to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('was previously used as oldLayer')); - } + assert(() { + try { + pushFunction(builder2, layer); + fail('Expected push to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('was previously used as oldLayer')); + } + return true; + }()); builder2.build(); } @@ -150,12 +171,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); builder2.addRetained(layer); - try { - builder2.pushOpacity(321, oldLayer: childLayer); - fail('Expected pushOpacity to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('The layer is already being used')); - } + assert(() { + try { + builder2.pushOpacity(321, oldLayer: childLayer); + fail('Expected pushOpacity to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('The layer is already being used')); + } + return true; + }()); builder2.build(); } @@ -171,12 +195,15 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); builder2.pushOpacity(234, oldLayer: childLayer); builder2.pop(); - try { - builder2.addRetained(layer); - fail('Expected addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('The layer is already being used')); - } + assert(() { + try { + builder2.addRetained(layer); + fail('Expected addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('The layer is already being used')); + } + return true; + }()); builder2.build(); } @@ -190,13 +217,16 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); pushFunction(builder2, layer); builder2.pop(); - try { - final SceneBuilder builder3 = SceneBuilder(); - builder3.addRetained(layer); - fail('Expected addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('was previously used as oldLayer')); - } + assert(() { + try { + final SceneBuilder builder3 = SceneBuilder(); + builder3.addRetained(layer); + fail('Expected addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('was previously used as oldLayer')); + } + return true; + }()); builder2.build(); } @@ -210,13 +240,16 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); pushFunction(builder2, layer); builder2.pop(); - try { - final SceneBuilder builder3 = SceneBuilder(); - pushFunction(builder3, layer); - fail('Expected addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('was previously used as oldLayer')); - } + assert(() { + try { + final SceneBuilder builder3 = SceneBuilder(); + pushFunction(builder3, layer); + fail('Expected addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('was previously used as oldLayer')); + } + return true; + }()); builder2.build(); } @@ -232,13 +265,16 @@ void main() { final SceneBuilder builder2 = SceneBuilder(); builder2.pushOpacity(321, oldLayer: childLayer); builder2.pop(); - try { - final SceneBuilder builder3 = SceneBuilder(); - builder3.addRetained(parentLayer); - fail('Expected addRetained to throw AssertionError but it returned successully'); - } on AssertionError catch (error) { - expect(error.toString(), contains('was previously used as oldLayer')); - } + assert(() { + try { + final SceneBuilder builder3 = SceneBuilder(); + builder3.addRetained(parentLayer); + fail('Expected addRetained to throw AssertionError but it returned successully'); + } on AssertionError catch (error) { + expect(error.toString(), contains('was previously used as oldLayer')); + } + return true; + }()); builder2.build(); } diff --git a/testing/dart/gradient_test.dart b/testing/dart/gradient_test.dart index 587485e582d..7c2489a2cf3 100644 --- a/testing/dart/gradient_test.dart +++ b/testing/dart/gradient_test.dart @@ -53,19 +53,21 @@ void main() { // this would result in div/0 on skia side. test('radial center and focal == Offset.zero and focalRadius != 0.0 assert', - () { - expect( - () => Gradient.radial( - Offset.zero, - 0.0, - [const Color(0xFFFFFFFF), const Color(0xFFFFFFFF)], - [0.0, 1.0], - TileMode.mirror, - null, - Offset.zero, - 1.0, - ), - throwsA(const TypeMatcher()), - ); + () { + assert(() { + expect( + () => Gradient.radial( + Offset.zero, + 0.0, + [const Color(0xFFFFFFFF), const Color(0xFFFFFFFF)], + [0.0, 1.0], + TileMode.mirror, + null, + Offset.zero, + 1.0, + ), + throwsA(const TypeMatcher()), + ); + }()); }); }