Make tests not assume catch(e) gives e type dynamic.

See #41558

Bug: http://dartbug.com/41558
Change-Id: I8980ad6e0d240c917f36ec4f9fcf2091fb61a4b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143819
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Lasse Reichstein Holst Nielsen 2020-05-05 09:57:23 +00:00 committed by commit-bot@chromium.org
parent 2ac2433a31
commit 765c9c3a8e
16 changed files with 35 additions and 43 deletions

View file

@ -18,7 +18,7 @@ class B {
A.Aa();
} catch (e) {
// This should produce a NoSuchMethodError.
var trace = e.stackTrace;
var trace = (e as dynamic).stackTrace;
}
}
}

View file

@ -58,7 +58,7 @@ main() {
bool hasThrown = false;
try {
f();
} catch (e) {
} on Error catch (e) {
hasThrown = true;
Expect.isTrue(
e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace");

View file

@ -18,7 +18,7 @@ foo() async {
}
main() async {
var error = "no error";
Object error = "no error";
try {
await foo();
} catch (e) {

View file

@ -32,7 +32,7 @@ test1_1() async {
test1_2() async {
try {
await test1_1();
} catch (e) {
} on int catch (e) {
throw e + 1;
}
}
@ -50,18 +50,18 @@ test2() async {
var test2_1 = () async {
try {
throw 'a';
} catch (e) {
} on String catch (e) {
throw e + 'b';
}
};
try {
try {
await test2_1();
} catch (e) {
} on String catch (e) {
var y = await bar(e + 'c');
throw y;
}
} catch (e) {
} on String catch (e) {
x = e + 'd';
return '?';
} finally {

View file

@ -42,7 +42,7 @@ quazz() async {
try {
x = await bar(1);
throw x;
} catch (e1) {
} on int catch (e1) {
var y = await baz(e1 + 1);
throw y;
}
@ -65,7 +65,7 @@ nesting() async {
};
var a = await y();
throw a;
} catch (e2) {
} on int catch (e2) {
throw e2 + 1;
}
} catch (e3) {

View file

@ -17,7 +17,7 @@ class Helper {
int j = 0;
try {
j = func();
} catch (exception) {
} on MyException1 catch (exception) {
i = i + 100;
print(exception.message_);
} finally {

View file

@ -55,25 +55,25 @@ class Helper {
}
try {
j = j + 24;
} catch (e) {
} on TestException catch (e) {
i = 300;
print(e.getMessage());
}
try {
j += 20;
} catch (e) {
} on TestException catch (e) {
i = 400;
print(e.getMessage());
}
try {
j += 40;
} catch (e) {
} on TestException catch (e) {
i = 600;
print(e.getMessage());
}
try {
j += 60;
} catch (e, trace) {
} on TestException catch (e, trace) {
i = 700;
print(trace.toString());
print(e.getMessage());

View file

@ -29,8 +29,7 @@ main() async {
test('directoryDoesntExist', () async {
try {
await fs.root.getDirectory('directory2');
} catch (error) {
expect(true, error is DomException);
} on DomException catch (error) {
expect(DomException.NOT_FOUND, error.name);
}
});

View file

@ -58,9 +58,7 @@ main() async {
try {
entry = await fs.root.getFile('file4');
fail("File file4 should not exist.");
} catch (error) {
expect(error is DomException, true,
reason: "Not DomException - not exist");
} on DomException catch (error) {
expect(DomException.NOT_FOUND, error.name);
}
@ -71,9 +69,7 @@ main() async {
try {
var entry = await fileAndDir.dir.getFile(fileAndDir.file.name);
fail("file not removed");
} catch (error) {
expect(error is DomException, true,
reason: "Not DomException - removed");
} on DomException catch (error) {
expect(DomException.NOT_FOUND, error.name);
}
});

View file

@ -30,8 +30,7 @@ main() async {
try {
var fileObj = await fs.root.getFile('file2');
fail("file found");
} catch (error) {
expect(true, error is DomException);
} on DomException catch (error) {
expect(DomException.NOT_FOUND, error.name);
}
});

View file

@ -27,7 +27,7 @@ main() async {
device.label.endsWith('Built-in Microphone');
expect(goodDevLabel, true);
}
} catch (e) {
} on DomException catch (e) {
// Could fail if bot machine doesn't support audio or video.
expect(e.name == DomException.NOT_FOUND, true);
}
@ -54,7 +54,7 @@ main() async {
video.src = url;
return completer.future;
}).catchError((e) {
}).catchError((dynamic e) {
// Could fail if bot machine doesn't support audio or video.
expect(e.name == DomException.NOT_FOUND, true);
});
@ -87,7 +87,7 @@ main() async {
video.src = url;
return completer.future;
}).catchError((e) {
}).catchError((dynamic e) {
// Could fail if bot machine doesn't support audio or video.
expect(e.name == DomException.NOT_FOUND, true);
});

View file

@ -66,7 +66,7 @@ main() async {
try {
await dropTable(tx, tableName);
expect(false, true, reason: "dropTable should fail");
} catch (error) {
} on DomException catch (error) {
expect(error.message,
"could not prepare statement (1 no such table: test_table)");
}
@ -80,7 +80,7 @@ main() async {
SqlResultSet createResult =
await createTable(tx, tableName, columnName);
expect(createResult.insertId, 0);
} catch (error) {
} on DomException catch (error) {
expect(false, true, reason: "createTable failed - ${error.message}");
}
});
@ -94,7 +94,7 @@ main() async {
await insertTable(tx, tableName, columnName, 'Some text data');
expect(insertResult.insertId, 1);
expect(insertResult.rowsAffected, 1);
} catch (error) {
} on DomException catch (error) {
expect(false, true, reason: "insert failed - ${error.message}");
}
});
@ -107,7 +107,7 @@ main() async {
SqlResultSet queryResult = await queryTable(tx, tableName);
expect(queryResult.rows.length, 1);
expect(queryResult.rows[0]['test_data'], "Some text data");
} catch (error) {
} on DomException catch (error) {
expect(false, true, reason: "queryTable failed - ${error.message}");
}
});

View file

@ -76,8 +76,8 @@ Future testRequestNoFile() async {
try {
await HttpRequest.request('NonExistingFile');
fail('Request should not have succeeded.');
} catch (error) {
HttpRequest xhr = error.target;
} on ProgressEvent catch (error) {
HttpRequest xhr = error.target as HttpRequest;
expect(xhr.readyState, HttpRequest.DONE);
validate404(xhr);
}
@ -103,8 +103,8 @@ Future testRequestWithCredentialsNoFile() async {
try {
await HttpRequest.request('NonExistingFile', withCredentials: true);
fail('Request should not have succeeded.');
} catch (error) {
HttpRequest xhr = error.target;
} on ProgressEvent catch (error) {
HttpRequest xhr = error.target as HttpRequest;
expect(xhr.readyState, HttpRequest.DONE);
validate404(xhr);
}
@ -126,8 +126,8 @@ Future testGetStringNoFile() async {
try {
await HttpRequest.getString('NonExistingFile');
fail('Succeeded for non-existing file.');
} catch (error) {
HttpRequest xhr = error.target;
} on ProgressEvent catch (error) {
HttpRequest xhr = error.target as HttpRequest;
expect(xhr.readyState, HttpRequest.DONE);
validate404(xhr);
}

View file

@ -64,7 +64,7 @@ confuse(x) {
try {
if (new DateTime.now().millisecondsSinceEpoch == 42) x = 42;
throw [x];
} catch (e) {
} on List catch (e) {
return e[0];
}
return 42;

View file

@ -603,10 +603,9 @@ testRename() {
try {
new Directory(foo).renameSync(bar);
Expect.fail('Directory.rename should fail to rename a non-directory');
} catch (e) {
Expect.isTrue(e is FileSystemException);
} on FileSystemException catch (e) {
if (Platform.isLinux || Platform.isMacOS) {
Expect.isTrue(e.osError.message.contains('Not a directory'));
Expect.isTrue(e.osError!.message.contains('Not a directory'));
}
}

View file

@ -31,8 +31,7 @@ testBadCreate() async {
try {
await badFile.create();
Expect.fail('Should be unreachable');
} catch (e) {
Expect.isTrue(e is FileSystemException);
} on FileSystemException catch (e) {
Expect.isNotNull(e.osError);
}
await tmp.delete(recursive: true);