Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:image/image.dart' as dart_image;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'test_util.dart';

typedef CanvasCallback = void Function(Canvas canvas);

Future<Image> createImage(int width, int height) {
Expand All @@ -38,35 +40,6 @@ void testCanvas(CanvasCallback callback) {
} catch (error) { } // ignore: empty_catches
}

void expectAssertion(Function callback) {
bool assertsEnabled = false;
assert(() {
assertsEnabled = true;
return true;
}());
if (assertsEnabled) {
bool threw = false;
try {
callback();
} catch (e) {
expect(e is AssertionError, true);
threw = true;
}
expect(threw, true);
}
}

void expectArgumentError(Function callback) {
bool threw = false;
try {
callback();
} catch (e) {
expect(e is ArgumentError, true);
threw = true;
}
expect(threw, true);
}

void testNoCrashes() {
test('canvas APIs should not crash', () async {
final Paint paint = Paint();
Expand Down
44 changes: 44 additions & 0 deletions testing/dart/test_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6

import 'package:test/test.dart';

/// Asserts that `callback` throws an [AssertionError].
///
/// When running in a VM in which assertions are enabled, asserts that the
/// specified callback throws an [AssertionError]. When asserts are not
/// enabled, such as when running using a release-mode VM with default
/// settings, this acts as a no-op.
void expectAssertion(Function callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random unsolicited note (since you asked :D) why not give it a class and a function to just expectThrows instead? Something like https://www.codota.com/code/java/methods/org.testng.Assert/expectThrows

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Will land this as-is so I can use it for the lerp tests, but as I say, planning to do a cleanup so will take a look!

bool assertsEnabled = false;
assert(() {
assertsEnabled = true;
return true;
}());
if (assertsEnabled) {
bool threw = false;
try {
callback();
} catch (e) {
expect(e is AssertionError, true);
threw = true;
}
expect(threw, true);
}
}

/// Asserts that `callback` throws an [ArgumentError].
void expectArgumentError(Function callback) {
bool threw = false;
try {
callback();
} catch (e) {
expect(e is ArgumentError, true);
threw = true;
}
expect(threw, true);
}

2 changes: 1 addition & 1 deletion testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def RunDartTests(build_dir, filter, verbose_dart_snapshot):
# Now that we have the Sky packages at the hardcoded location, run `pub get`.
RunEngineExecutable(build_dir, os.path.join('dart-sdk', 'bin', 'pub'), None, flags=['get'], cwd=dart_tests_dir)

dart_tests = glob.glob('%s/*.dart' % dart_tests_dir)
dart_tests = glob.glob('%s/*_test.dart' % dart_tests_dir)

for dart_test_file in dart_tests:
if filter is not None and os.path.basename(dart_test_file) not in filter:
Expand Down