Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: pkg/expect/lib/expect.dart

Issue 2989743002: Add some more validation of things in expect that should not be used. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/migration/lib/src/validate.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/expect/lib/expect.dart
diff --git a/pkg/expect/lib/expect.dart b/pkg/expect/lib/expect.dart
index 4d9c425275ad6c253b9ac5ac74320e05a505983f..c9810b03504f6398de48e8318643a343785c16f6 100644
--- a/pkg/expect/lib/expect.dart
+++ b/pkg/expect/lib/expect.dart
@@ -436,8 +436,7 @@ class Expect {
*
* Expect.throws(myThrowingFunction, (e) => e is MyException);
*/
- static void throws(void f(),
- [_CheckExceptionFn check = null, String reason = null]) {
+ static void throws(void f(), [_CheckExceptionFn check, String reason]) {
String msg = reason == null ? "" : "($reason)";
if (f is! _Nullary) {
// Only throws from executing the function body should count as throwing.
@@ -457,6 +456,35 @@ class Expect {
_fail('Expect.throws$msg fails: Did not throw');
}
+ static void throwsArgumentError(void f()) {
+ Expect.throws(f, (error) => error is ArgumentError, "ArgumentError");
+ }
+
+ static void throwsCastError(void f()) {
+ Expect.throws(f, (error) => error is CastError, "CastError");
+ }
+
+ static void throwsNoSuchMethodError(void f()) {
+ Expect.throws(
+ f, (error) => error is NoSuchMethodError, "NoSuchMethodError");
+ }
+
+ static void throwsRangeError(void f()) {
+ Expect.throws(f, (error) => error is RangeError, "RangeError");
+ }
+
+ static void throwsStateError(void f()) {
+ Expect.throws(f, (error) => error is StateError, "StateError");
+ }
+
+ static void throwsTypeError(void f()) {
+ Expect.throws(f, (error) => error is TypeError, "TypeError");
+ }
+
+ static void throwsUnsupportedError(void f()) {
+ Expect.throws(f, (error) => error is UnsupportedError, "UnsupportedError");
+ }
+
static String _getMessage(String reason) =>
(reason == null) ? "" : ", '$reason'";
@@ -505,6 +533,7 @@ class AssumeDynamic {
}
/// Is true iff type assertions are enabled.
+// TODO(rnystrom): Remove this once all tests are no longer using it.
final bool typeAssertionsEnabled = (() {
try {
dynamic i = 42;
@@ -526,5 +555,6 @@ final bool assertStatementsEnabled = (() {
})();
/// Is true iff checked mode is enabled.
+// TODO(rnystrom): Remove this once all tests are no longer using it.
final bool checkedModeEnabled =
typeAssertionsEnabled && assertStatementsEnabled;
« no previous file with comments | « no previous file | tools/migration/lib/src/validate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698