mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
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:
parent
2ac2433a31
commit
765c9c3a8e
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -18,7 +18,7 @@ foo() async {
|
|||
}
|
||||
|
||||
main() async {
|
||||
var error = "no error";
|
||||
Object error = "no error";
|
||||
try {
|
||||
await foo();
|
||||
} catch (e) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue