Re-land beginning Dart 2.0 test migration.

This is similar to:

47985d6dbd
452d2d0840
7af2d86ed3

Except that it also fixes the status for dart2analyzer.

R=jcollins@google.com

Review-Url: https://codereview.chromium.org/2980213002 .
This commit is contained in:
Bob Nystrom 2017-07-17 12:40:17 -07:00
parent bc937b3b6b
commit 489c96ac2e
21 changed files with 101 additions and 214 deletions

View file

@ -0,0 +1,3 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

View file

@ -0,0 +1,15 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library dart.test.symbol_map_helper;
// TODO(ahe): Update map literals to avoid this method.
Map<Symbol, dynamic> symbolMapToStringMap(Map<String, dynamic> map) {
if (map == null) return null;
Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();
map.forEach((name, value) {
result[new Symbol(name)] = value;
});
return result;
}

View file

@ -1,76 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import "symbol_map_helper.dart";
// Testing Function.apply calls correctly.
// This test is not testing error handling, only that correct parameters
// cause a correct call.
int test0() => 42;
int test0a({int a}) => 37 + a;
int test1(int i) => i + 1;
int test1a(int i, {int a}) => i + a;
int test2(int i, int j) => i + j;
int test2a(int i, int j, {int a}) => i + j + a;
class C {
int x = 10;
int foo(y) => this.x + y;
}
class Callable {
int call(int x, int y) => x + y;
}
@NoInline()
@AssumeDynamic()
confuse(x) => x;
main() {
testMap(res, func, map) {
map = symbolMapToStringMap(map);
Expect.equals(res, Function.apply(func, null, map));
Expect.equals(res, Function.apply(func, [], map));
}
testList(res, func, list) {
Expect.equals(res, Function.apply(func, list));
Expect.equals(res, Function.apply(func, list, null));
Expect.equals(res, Function.apply(func, list, new Map<Symbol, dynamic>()));
}
test(res, func, list, map) {
map = symbolMapToStringMap(map);
Expect.equals(res, Function.apply(func, list, map));
}
testList(42, test0, null);
testList(42, test0, []);
testMap(42, test0a, {"a": 5});
testList(42, test1, [41]);
test(42, test1a, [20], {"a": 22});
testList(42, test2, [20, 22]);
test(42, test2a, [10, 15], {"a": 17});
// Test that "this" is correct when calling closurized functions.
var cfoo = new C().foo;
testList(42, cfoo, [32]);
// Test that apply works even with a different name.
var app = confuse(Function.apply);
Expect.equals(42, app(test2, [22, 20]));
// Test that apply can itself be applied.
Expect.equals(
42,
Function.apply(Function.apply, [
test2,
[17, 25]
]));
// Test that apply works on callable objects.
testList(42, new Callable(), [13, 29]);
}

View file

@ -1,14 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
abstract //# 01: static type warning
class Abstract {
Abstract(_);
}
void main() {
Expect.throws(() => new Abstract(throw "argument"), (e) => e == "argument");
}

View file

@ -1,28 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// When an instantiation of an abstract class has the wrong arguments, an
// AbstractClassInstantiationError is thrown, not a NoSuchMethodError.
abstract class A {
A() {}
}
class B {
B() {}
}
bool isAbstractClassInstantiationError(e) =>
e is AbstractClassInstantiationError;
bool isNoSuchMethodError(e) => e is NoSuchMethodError;
void main() {
Expect.throws(() => new A(), isAbstractClassInstantiationError);
Expect.throws(() => new B(1), isNoSuchMethodError);
Expect.throws(() => new A(1), isAbstractClassInstantiationError);
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for dart2js that used to duplicate some `Object`
// methods to handle `noSuchMethod`.
import "package:expect/expect.dart";
import "compiler_annotations.dart";
abstract //# 01: static type warning
class Foo {
noSuchMethod(im) => 42;
}
@DontInline()
returnFoo() {
(() => 42)();
return new Foo();
}
class Bar {
operator ==(other) => false;
}
var a = [false, true, new Object(), new Bar()];
main() {
if (a[0]) {
// This `==` call will make the compiler create a selector with an
// exact `TypeMask` of `Foo`. Since `Foo` is abstract, such a call
// cannot happen, but we still used to generate a `==` method on
// the `Object` class to handle `noSuchMethod`.
print(returnFoo() == 42);
} else {
Expect.isFalse(a[2] == 42);
}
}

View file

@ -0,0 +1,16 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// TODO(rnystrom): This test should be renamed since now it's just about
// testing that constructing an abstract class generates an error.
abstract class A {
A() {}
}
void main() {
/*@compile-error=unspecified*/ new A();
}

View file

@ -8,8 +8,8 @@
import "package:expect/expect.dart";
import "compiler_annotations.dart";
abstract //# 01: static type warning
class Foo {
abstract //# 01: compile-time error
class Foo {
noSuchMethod(im) => 42;
}

View file

@ -8,7 +8,7 @@ import "package:expect/expect.dart";
class Foo {
// Intentionally abstract:
get i; // //# 01: static type warning
get i; // //# 01: compile-time error
}
class Bar {}

View file

@ -0,0 +1,12 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library compiler_annotations;
// This library contains annotations useful for testing.
// TODO(ngeoffray): Implement in dart2js.
class DontInline {
const DontInline();
}

View file

@ -0,0 +1,10 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# The VM and dart2js do not implement the Dart 2.0 static type errors yet.
# Analyzer does, but only when "--strong" is used.
[ $runtime == vm || $compiler == dart2js || $runtime == dart_precompiled || ($compiler == dart2analyzer && ! $strong) ]
abstract_beats_arguments_test: MissingCompileTimeError
abstract_exact_selector_test/01: MissingCompileTimeError
abstract_getter_test/01: MissingCompileTimeError

View file

@ -1,27 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for dart2js that used to be confused when inlining
// method that always aborts in a switch case.
import "package:expect/expect.dart";
foo() {
throw 42;
}
main() {
var exception;
try {
switch (42) {
case 42:
foo();
foo();
break;
}
} catch (e) {
exception = e;
}
Expect.equals(42, exception);
}

View file

@ -1,27 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Test to ensure that an abstract getter is not mistaken for a field.
class Foo {
// Intentionally abstract:
get i; // //# 01: static type warning
}
class Bar {}
noMethod(e) => e is NoSuchMethodError;
checkIt(f) {
Expect.throws(() { f.i = 'hi'; }, noMethod); // //# 01: continued
Expect.throws(() { print(f.i); }, noMethod); // //# 01: continued
Expect.throws(() { print(f.i()); }, noMethod); // //# 01: continued
}
main() {
checkIt(new Foo());
checkIt(new Bar());
}

3
tests/lib_2/lib_2.status Normal file
View file

@ -0,0 +1,3 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

View file

@ -4,6 +4,9 @@
// VMOptions=--optimization-counter-threshold=-1 --new_gen_semi_max_size=2
// TODO(rnystrom): This looks like a VM-specific test. Move out of
// tests/language and into somewhere more appropriate.
import 'dart:math';
main() {

View file

@ -14,6 +14,10 @@ import bot
import bot_utils
TARGETS = [
'language_2',
'corelib_2',
'lib_2',
# TODO(rnystrom): Remove these when all tests have been migrated out.
'language_strong',
'corelib_strong',
'lib_strong'

View file

@ -13,14 +13,17 @@ const _defaultTestSelectors = const [
'samples',
'standalone',
'corelib',
'corelib_2',
'co19',
'language',
'language_2',
'isolate',
'vm',
'html',
'benchmark_smoke',
'utils',
'lib',
'lib_2',
'analyze_library',
'service',
'kernel',

View file

@ -39,14 +39,17 @@ final TEST_SUITE_DIRECTORIES = [
new Path('tests/compiler/dart2js_extra'),
new Path('tests/compiler/dart2js_native'),
new Path('tests/corelib'),
new Path('tests/corelib_2'),
new Path('tests/corelib_strong'),
new Path('tests/html'),
new Path('tests/isolate'),
new Path('tests/kernel'),
new Path('tests/language'),
new Path('tests/language_strong'),
new Path('tests/language_2'),
new Path('tests/lib'),
new Path('tests/lib_strong'),
new Path('tests/lib_2'),
new Path('tests/standalone'),
new Path('tests/utils'),
new Path('utils/tests/css'),

View file

@ -1572,13 +1572,38 @@ class StandardTestSuite extends TestSuite {
subtestNames.add(fullMatch.substring(fullMatch.indexOf("'") + 1));
}
// TODO(rnystrom): During the migration of the existing tests to Dart 2.0,
// we have a number of tests that used to both generate static type warnings
// and also validate some runtime behavior in an implementation that
// ignores those warnings. Those warnings are now errors. The test code
// validates the runtime behavior can and should be removed, but the code
// that causes the static warning should still be preserved since that is
// part of our coverage of the static type system.
//
// The test needs to indicate that it should have a static error. We could
// put that in the status file, but that makes it confusing because it
// would look like implementations that *don't* report the error are more
// correct. Eventually, we want to have a notation similar to what front_end
// is using for the inference tests where we can put a comment inside the
// test that says "This specific static error should be reported right by
// this token."
//
// That system isn't in place yet, so we do a crude approximation here in
// test.dart. If a test contains `/*@compile-error=`, which matches the
// beginning of the tag syntax that front_end uses, then we assume that
// this test must have a static error somewhere in it.
//
// Redo this code once we have a more precise test framework for detecting
// and locating these errors.
var hasCompileError = contents.contains("/*@compile-error=");
return {
"vmOptions": result,
"sharedOptions": sharedOptions ?? [],
"dartOptions": dartOptions,
"packageRoot": packageRoot,
"packages": packages,
"hasCompileError": false,
"hasCompileError": hasCompileError,
"hasRuntimeError": false,
"hasStaticWarning": false,
"otherScripts": otherScripts,