fix list_unmodifiable_test

This test had some runtime soundness errors. I've added some type annotations to make those easier to catch, and also made the test a bit more rigorous about whether an error is expected.

R=bkonyi@google.com

Review-Url: https://codereview.chromium.org/2995703002 .
This commit is contained in:
Jennifer Messerly 2017-08-11 13:19:17 -07:00
parent f1e34ffd11
commit 04f61db8a8
2 changed files with 35 additions and 28 deletions

View file

@ -151,7 +151,6 @@ symbol_reserved_word_test/12: RuntimeError # Issue 29921
int_parse_with_limited_ints_test: Skip # dartdevc doesn't know about --limit-ints-to-64-bits
typed_data_with_limited_ints_test: Skip # dartdevc doesn't know about --limit-ints-to-64-bits
int_modulo_arith_test/none: RuntimeError # Issue 29921
list_unmodifiable_test: RuntimeError # Issue 29921, strong mode cast failure
[ ($compiler == dart2js || $compiler == dartdevc) && $runtime != none ]
big_integer_arith_vm_test: RuntimeError # Issues 10245, 30170

View file

@ -139,23 +139,25 @@ class Test<E> {
list.fillRange(0, 1, null);
});
success(opName, op(list)) {
var expect;
try {
expect = op(elements);
} catch (e) {
try {
op(list);
} catch (e2) {
Expect.equals(
e.runtimeType,
e2.runtimeType,
"$name :: $opName threw different exceptions: "
"${e.runtimeType} vs ${e2.runtimeType}");
return;
}
Expect.fail("$name-$opName didn't throw, expected: $e");
success(opName, op(List list), [bool throws = false]) {
if (throws) {
var e1, e2;
Expect.throws(() => op(elements), (e) {
e1 = e;
return true;
}, '$name :: $opName should throw for $elements');
Expect.throws(() => op(list), (e) {
e2 = e;
return true;
}, '$name :: $opName should throw for $list');
Expect.equals(
e1.runtimeType,
e2.runtimeType,
"$name :: $opName threw different errors for $elements and $list: "
"${e1.runtimeType} vs ${e2.runtimeType}");
return;
}
var expect = op(elements);
var actual = op(list);
checkElements();
if (expect is List) {
@ -171,10 +173,10 @@ class Test<E> {
success("indexOf", (l) => l.indexOf(null));
success("lastIndexOf", (l) => l.lastIndexOf(null));
success("contains", (l) => l.contains(2));
success("elementAt", (l) => l.elementAt[1]);
success("elementAt", (l) => l.elementAt(1), list.length < 2);
success("reversed", (l) => l.reversed);
success("sublist0-1", (l) => l.sublist(0, 1));
success("getRange0-1", (l) => l.getRange(0, 1));
success("sublist0-1", (l) => l.sublist(0, 1), list.isEmpty);
success("getRange0-1", (l) => l.getRange(0, 1), list.isEmpty);
success("asMap-keys", (l) => l.asMap().keys);
success("asMap-values", (l) => l.asMap().values);
success("where", (l) => l.where((x) => true));
@ -184,17 +186,22 @@ class Test<E> {
success("take", (l) => l.take(1));
success("skipWhile", (l) => l.skipWhile((x) => false));
success("takeWhile", (l) => l.takeWhile((x) => true));
success("first", (l) => l.first);
success("last", (l) => l.last);
success("single", (l) => l.single);
success("firstWhere", (l) => l.firstWhere((x) => true));
success("lastWhere", (l) => l.lastWhere((x) => true));
success("singleWhere", (l) => l.singleWhere((x) => true));
success("first", (l) => l.first, list.isEmpty);
success("last", (l) => l.last, list.isEmpty);
success("single", (l) => l.single, list.length != 1);
success("firstWhere", (l) => l.firstWhere((x) => true), list.isEmpty);
success("lastWhere", (l) => l.lastWhere((x) => true), list.isEmpty);
success("singleWhere", (l) => l.singleWhere((x) => true), list.length != 1);
success("isEmpty", (l) => l.isEmpty);
success("isNotEmpty", (l) => l.isNotEmpty);
success("join", (l) => l.join("/"));
success("fold", (l) => l.fold("--", (a, b) => "$a/$b"));
success("reduce", (l) => l.reduce((a, b) => a + b));
if (elements is List<num> && list is List<num>) {
success(
"reduce",
(l) => (l as List<num>).reduce((a, b) => (a + b).floor()),
list.isEmpty);
}
success("every", (l) => l.every((x) => x == 0));
success("any", (l) => l.any((x) => x == 2));
success("toList", (l) => l.toList());
@ -209,7 +216,8 @@ class Test<E> {
Expect.isFalse(it.moveNext());
if (elements is List<int> && list is List<int>) {
success("String.fromCharCodes", (l) => new String.fromCharCodes(l));
success("String.fromCharCodes",
(l) => new String.fromCharCodes(l as List<int>));
}
}
}