Better messages when error messages don't match

TEST=test-only change
Change-Id: I2cbb1611da39ca2ca0c24a2c5f2e53028026db7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219500
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Brian Quinlan 2021-11-05 17:45:47 +00:00 committed by commit-bot@chromium.org
parent fe050f709b
commit 18d421d6d2
2 changed files with 16 additions and 8 deletions

View file

@ -51,7 +51,8 @@ testRenameToSamePath() async {
// On Windows, the directory will be *deleted*.
Expect.isFalse(dir.existsSync());
Expect.isTrue(
e.osError!.message.contains('cannot find the file specified'));
e.osError!.message.contains('cannot find the file specified'),
'Unexpected error: $e');
} else {
Expect.fail('Directory.rename to same path should not fail on '
'${Platform.operatingSystem} (${Platform.operatingSystemVersion}): '
@ -74,9 +75,11 @@ testRenameToExistingFile() async {
Expect.fail('Directory.rename should fail to rename a non-directory');
} 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'),
'Unexpected error: $e');
} else if (Platform.isWindows) {
Expect.isTrue(e.osError!.message.contains('file already exists'));
Expect.isTrue(e.osError!.message.contains('file already exists'),
'Unexpected error: $e');
}
}
});
@ -122,7 +125,8 @@ testRenameToExistingNonEmptyDirectory() async {
}
} on FileSystemException catch (e) {
if (Platform.isLinux || Platform.isMacOS) {
Expect.isTrue(e.osError!.message.contains('Directory not empty'));
Expect.isTrue(e.osError!.message.contains('Directory not empty'),
'Unexpected error: $e');
}
}
});

View file

@ -53,7 +53,8 @@ testRenameToSamePath() async {
// On Windows, the directory will be *deleted*.
Expect.isFalse(dir.existsSync());
Expect.isTrue(
e.osError.message.contains('cannot find the file specified'));
e.osError.message.contains('cannot find the file specified'),
'Unexpected error: $e');
} else {
Expect.fail('Directory.rename to same path should not fail on '
'${Platform.operatingSystem} (${Platform.operatingSystemVersion}): '
@ -76,9 +77,11 @@ testRenameToExistingFile() async {
Expect.fail('Directory.rename should fail to rename a non-directory');
} 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'),
'Unexpected error: $e');
} else if (Platform.isWindows) {
Expect.isTrue(e.osError.message.contains('file already exists'));
Expect.isTrue(e.osError.message.contains('file already exists'),
'Unexpected error: $e');
}
}
});
@ -124,7 +127,8 @@ testRenameToExistingNonEmptyDirectory() async {
}
} on FileSystemException catch (e) {
if (Platform.isLinux || Platform.isMacOS) {
Expect.isTrue(e.osError.message.contains('Directory not empty'));
Expect.isTrue(e.osError.message.contains('Directory not empty'),
'Unexpected error: $e');
}
}
});