mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
Migrate language_2/assert to NNBD.
Change-Id: I4daa09afa52f76076374591b3e3f3420a46b169b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134240 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
7bf057bdfa
commit
688801cb27
|
@ -393,7 +393,7 @@ class _Future<T> implements Future<T> {
|
||||||
void _prependListeners(_FutureListener? listeners) {
|
void _prependListeners(_FutureListener? listeners) {
|
||||||
if (listeners == null) return;
|
if (listeners == null) return;
|
||||||
if (_mayAddListener) {
|
if (_mayAddListener) {
|
||||||
_FutureListener existingListeners = _resultOrListeners;
|
_FutureListener? existingListeners = _resultOrListeners;
|
||||||
_resultOrListeners = listeners;
|
_resultOrListeners = listeners;
|
||||||
if (existingListeners != null) {
|
if (existingListeners != null) {
|
||||||
_FutureListener cursor = listeners;
|
_FutureListener cursor = listeners;
|
||||||
|
|
91
tests/language/assert/assert_test.dart
Normal file
91
tests/language/assert/assert_test.dart
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
// Copyright (c) 2011, 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.
|
||||||
|
// VMOptions=--enable-asserts
|
||||||
|
// dart2jsOptions=--enable-asserts
|
||||||
|
|
||||||
|
// Dart test program testing assert statements.
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
testTrue() {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
assert(true);
|
||||||
|
} on AssertionError {
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
testFalse() {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
assert(false);
|
||||||
|
} on AssertionError {
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown(dynamic a) {
|
||||||
|
return a ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
testBoolean(bool value) {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
assert(value);
|
||||||
|
} on AssertionError {
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
testDynamic(dynamic value) {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
assert(value);
|
||||||
|
} on AssertionError {
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
testMessage(value, message) {
|
||||||
|
try {
|
||||||
|
assert(value, message);
|
||||||
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
// Catch any type to allow the Boolean conversion to throw either
|
||||||
|
// AssertionError or TypeError.
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
Expect.equals(0, testTrue());
|
||||||
|
Expect.equals(0, testBoolean(true));
|
||||||
|
Expect.equals(0, testDynamic(unknown(true)));
|
||||||
|
|
||||||
|
Expect.equals(1, testFalse());
|
||||||
|
Expect.equals(1, testBoolean(false));
|
||||||
|
Expect.equals(1, testDynamic(unknown(false)));
|
||||||
|
|
||||||
|
Expect.equals(1, testDynamic(null));
|
||||||
|
Expect.equals(1, testDynamic(42));
|
||||||
|
Expect.equals(1, testDynamic(() => true));
|
||||||
|
Expect.equals(1, testDynamic(() => false));
|
||||||
|
Expect.equals(1, testDynamic(() => 42));
|
||||||
|
Expect.equals(1, testDynamic(() => null));
|
||||||
|
|
||||||
|
Expect.equals(1234, testMessage(false, 1234).message);
|
||||||
|
Expect.equals('hi', testMessage(false, 'hi').message);
|
||||||
|
|
||||||
|
// These errors do not have the message because boolean conversion failed.
|
||||||
|
Expect.notEquals(1234, testMessage(null, 1234).message);
|
||||||
|
Expect.notEquals('hi', testMessage(null, 'hi').message);
|
||||||
|
Expect.notEquals('hi', testMessage(() => null, 'hi').message);
|
||||||
|
Expect.notEquals('hi', testMessage(() => false, 'hi').message);
|
||||||
|
Expect.notEquals('hi', testMessage(() => true, 'hi').message);
|
||||||
|
}
|
28
tests/language/assert/assignable_type_test.dart
Normal file
28
tests/language/assert/assignable_type_test.dart
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.
|
||||||
|
// Dart test program to test arithmetic operations.
|
||||||
|
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
|
||||||
|
|
||||||
|
// This test crashes if we recompute type of AssertAssignableInstr based on its
|
||||||
|
// output types. By doing that we would eliminate not only the unnecessary
|
||||||
|
// AssertAssignableInstr but also the trailing class check.
|
||||||
|
|
||||||
|
main() {
|
||||||
|
// Foul up IC data in integer's unary minus.
|
||||||
|
var y = -0x80000000;
|
||||||
|
testInt64List();
|
||||||
|
}
|
||||||
|
|
||||||
|
testInt64List() {
|
||||||
|
var array = new List(10);
|
||||||
|
testInt64ListImpl(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
testInt64ListImpl(array) {
|
||||||
|
for (int i = 0; i < 10; ++i) {}
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
array[i] = -0x80000000000000 + i;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||||
|
// contain strange or dead code.
|
||||||
|
|
||||||
|
// Copyright (c) 2018, 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.
|
||||||
|
// VMOptions=--enable-asserts
|
||||||
|
// dart2jsOptions=--enable-asserts
|
||||||
|
//
|
||||||
|
// Test of asserts in initializer lists.
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
class C {
|
||||||
|
final int x;
|
||||||
|
// Const constructors.
|
||||||
|
const C.cc01(this.x, y) : assert(x < y);
|
||||||
|
const C.cc02(x, y)
|
||||||
|
: x = x,
|
||||||
|
assert(x < y);
|
||||||
|
const C.cc03(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x;
|
||||||
|
const C.cc04(this.x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
super();
|
||||||
|
const C.cc05(x, y)
|
||||||
|
: x = x,
|
||||||
|
assert(x < y),
|
||||||
|
super();
|
||||||
|
const C.cc06(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x,
|
||||||
|
super();
|
||||||
|
const C.cc07(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x,
|
||||||
|
assert(y > x),
|
||||||
|
super();
|
||||||
|
const C.cc08(this.x, y) : assert(x < y, "$x < $y");
|
||||||
|
const C.cc09(this.x, y) : assert(x < y,);
|
||||||
|
const C.cc10(this.x, y) : assert(x < y, "$x < $y",);
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
const x = 3;
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc01(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc02(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc03(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc04(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc05(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc06(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc07(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc08(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc09(2, x);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
const C.cc10(2, x);
|
||||||
|
}
|
||||||
|
}
|
124
tests/language/assert/initializer_const_error2_test.dart
Normal file
124
tests/language/assert/initializer_const_error2_test.dart
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
// Copyright (c) 2018, 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.
|
||||||
|
// VMOptions=--enable-asserts
|
||||||
|
// dart2jsOptions=--enable-asserts
|
||||||
|
//
|
||||||
|
// Test of asserts in initializer lists.
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
class C {
|
||||||
|
final int x;
|
||||||
|
// Const constructors.
|
||||||
|
const C.cc01(this.x, y) : assert(x < y);
|
||||||
|
const C.cc02(x, y)
|
||||||
|
: x = x,
|
||||||
|
assert(x < y);
|
||||||
|
const C.cc03(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x;
|
||||||
|
const C.cc04(this.x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
super();
|
||||||
|
const C.cc05(x, y)
|
||||||
|
: x = x,
|
||||||
|
assert(x < y),
|
||||||
|
super();
|
||||||
|
const C.cc06(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x,
|
||||||
|
super();
|
||||||
|
const C.cc07(x, y)
|
||||||
|
: assert(x < y),
|
||||||
|
x = x,
|
||||||
|
assert(y > x),
|
||||||
|
super();
|
||||||
|
const C.cc08(this.x, y) : assert(x < y, "$x < $y");
|
||||||
|
const C.cc09(this.x, y) : assert(x < y,);
|
||||||
|
const C.cc10(this.x, y) : assert(x < y, "$x < $y",);
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
const x = 3;
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc01(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc02(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc03(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc04(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc05(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc06(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc07(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc08(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc09(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
const C.cc10(2, x);
|
||||||
|
// ^^^^^^^^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||||
|
// ^
|
||||||
|
// [cfe] Constant evaluation error:
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||||
|
// contain strange or dead code.
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static bool check(x, y) => x < y;
|
||||||
|
final int x;
|
||||||
|
const C(this.x);
|
||||||
|
// The expression is not a potentially constant expression.
|
||||||
|
// This is a compile-time error even in production mode.
|
||||||
|
const C.bc03(this.x, y)
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
var c = new C.bc03(1, 2);
|
||||||
|
if (c.x != 1) throw "non-trivial use of c";
|
||||||
|
}
|
22
tests/language/assert/initializer_const_error_test.dart
Normal file
22
tests/language/assert/initializer_const_error_test.dart
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static bool check(x, y) => x < y;
|
||||||
|
final int x;
|
||||||
|
const C(this.x);
|
||||||
|
// The expression is not a potentially constant expression.
|
||||||
|
// This is a compile-time error even in production mode.
|
||||||
|
const C.bc03(this.x, y)
|
||||||
|
: assert(check(x, y))
|
||||||
|
// ^^^^^^^^^^^
|
||||||
|
// [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT
|
||||||
|
// [cfe] Method invocation is not a constant expression.
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
var c = new C.bc03(1, 2);
|
||||||
|
if (c.x != 1) throw "non-trivial use of c";
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||||
|
// contain strange or dead code.
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static bool staticTrue() => true;
|
||||||
|
final int x;
|
||||||
|
|
||||||
|
// Functions as parameters to assert are no longer supported in Dart 2.0, so
|
||||||
|
// this is now a static type error.
|
||||||
|
const C.bc01(this.x, y)
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
new C.bc01(1, 2);
|
||||||
|
}
|
21
tests/language/assert/initializer_const_function_test.dart
Normal file
21
tests/language/assert/initializer_const_function_test.dart
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static bool staticTrue() => true;
|
||||||
|
final int x;
|
||||||
|
|
||||||
|
// Functions as parameters to assert are no longer supported in Dart 2.0, so
|
||||||
|
// this is now a static type error.
|
||||||
|
const C.bc01(this.x, y)
|
||||||
|
: assert(staticTrue)
|
||||||
|
// ^^^^^^^^^^
|
||||||
|
// [analyzer] STATIC_TYPE_WARNING.NON_BOOL_EXPRESSION
|
||||||
|
// [cfe] A value of type 'bool Function()' can't be assigned to a variable of type 'bool'.
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
new C.bc01(1, 2);
|
||||||
|
}
|
130
tests/language/assert/initializer_test.dart
Normal file
130
tests/language/assert/initializer_test.dart
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// Dart test program testing assert statements.
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
class C {
|
||||||
|
static bool check(x, y) => x < y;
|
||||||
|
static bool staticTrue() => true;
|
||||||
|
final int x;
|
||||||
|
const C(this.x);
|
||||||
|
|
||||||
|
C.c01(this.x, y) : assert(x < y);
|
||||||
|
C.c02(x, y) : x = x, assert(x < y);
|
||||||
|
C.c03(x, y) : assert(x < y), x = x;
|
||||||
|
C.c05(this.x, y) : assert(x < y), super();
|
||||||
|
C.c06(x, y) : x = x, assert(x < y), super();
|
||||||
|
C.c07(x, y) : assert(x < y), x = x, super();
|
||||||
|
C.c08(x, y) : assert(x < y), x = x, assert(y > x), super();
|
||||||
|
C.c09(this.x, y) : assert(x < y, "$x < $y");
|
||||||
|
C.c10(this.x, y) : assert(x < y,);
|
||||||
|
C.c11(this.x, y) : assert(x < y, "$x < $y",);
|
||||||
|
|
||||||
|
const C.cc01(this.x, y) : assert(x < y);
|
||||||
|
const C.cc02(x, y) : x = x, assert(x < y);
|
||||||
|
const C.cc03(x, y) : assert(x < y), x = x;
|
||||||
|
const C.cc05(this.x, y) : assert(x < y), super();
|
||||||
|
const C.cc06(x, y) : x = x, assert(x < y), super();
|
||||||
|
const C.cc07(x, y) : assert(x < y), x = x, super();
|
||||||
|
const C.cc08(x, y) : assert(x < y), x = x, assert(y > x), super();
|
||||||
|
const C.cc09(this.x, y) : assert(x < y, "$x < $y");
|
||||||
|
const C.cc10(this.x, y) : assert(x < y,);
|
||||||
|
const C.cc11(this.x, y) : assert(x < y, "$x < $y",);
|
||||||
|
|
||||||
|
C.nc01(this.x, y) : assert(check(x, y));
|
||||||
|
C.nc02(x, y) : x = x, assert(check(x, y));
|
||||||
|
C.nc03(x, y) : assert(check(x, y)), x = x;
|
||||||
|
C.nc05(this.x, y) : assert(check(x, y)), super();
|
||||||
|
C.nc06(x, y) : x = x, assert(check(x, y)), super();
|
||||||
|
C.nc07(x, y) : assert(check(x, y)), x = x, super();
|
||||||
|
C.nc08(x, y) : assert(check(x, y)), x = x, assert(y > x), super();
|
||||||
|
C.nc09(this.x, y) : assert(check(x, y), "$x < $y");
|
||||||
|
C.nc10(this.x, y) : assert(check(x, y),);
|
||||||
|
C.nc11(this.x, y) : assert(check(x, y), "$x < $y",);
|
||||||
|
|
||||||
|
C.fc01(this.x, y) : assert((() => x < y)());
|
||||||
|
C.fc02(x, y) : x = x, assert((() => x < y)());
|
||||||
|
C.fc03(x, y) : assert((() => x < y)()), x = x;
|
||||||
|
C.fc05(this.x, y) : assert((() => x < y)()), super();
|
||||||
|
C.fc06(x, y) : x = x, assert((() => x < y)()), super();
|
||||||
|
C.fc07(x, y) : assert((() => x < y)()), x = x, super();
|
||||||
|
C.fc08(x, y) : assert((() => x < y)()),x = x, assert(y > x), super();
|
||||||
|
C.fc09(this.x, y) : assert((() => x < y)(), "$x < $y");
|
||||||
|
C.fc10(this.x, y) : assert((() => x < y)(),);
|
||||||
|
C.fc11(this.x, y) : assert((() => x < y)(), "$x < $y",);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main() {
|
||||||
|
// Test all constructors with both succeeding and failing asserts.
|
||||||
|
test(1, 2);
|
||||||
|
test(2, 1);
|
||||||
|
|
||||||
|
const c1 = const C(1);
|
||||||
|
|
||||||
|
// Asserts do not affect canonization.
|
||||||
|
Expect.identical(c1, const C.cc01(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc02(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc03(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc05(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc06(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc07(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc08(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc09(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc10(1, 2));
|
||||||
|
Expect.identical(c1, const C.cc11(1, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test(int x, int y) {
|
||||||
|
bool assertionsEnabled = false;
|
||||||
|
assert(assertionsEnabled = true);
|
||||||
|
|
||||||
|
bool Function(C Function()) doTest = (assertionsEnabled && x >= y)
|
||||||
|
? (f) { Expect.throwsAssertionError(f); }
|
||||||
|
: (f) { Expect.equals(x, f().x); };
|
||||||
|
|
||||||
|
doTest(() => new C.c01(x, y));
|
||||||
|
doTest(() => new C.c02(x, y));
|
||||||
|
doTest(() => new C.c03(x, y));
|
||||||
|
doTest(() => new C.c05(x, y));
|
||||||
|
doTest(() => new C.c06(x, y));
|
||||||
|
doTest(() => new C.c07(x, y));
|
||||||
|
doTest(() => new C.c08(x, y));
|
||||||
|
doTest(() => new C.c09(x, y));
|
||||||
|
doTest(() => new C.c10(x, y));
|
||||||
|
doTest(() => new C.c11(x, y));
|
||||||
|
doTest(() => new C.cc01(x, y));
|
||||||
|
doTest(() => new C.cc02(x, y));
|
||||||
|
doTest(() => new C.cc03(x, y));
|
||||||
|
doTest(() => new C.cc05(x, y));
|
||||||
|
doTest(() => new C.cc06(x, y));
|
||||||
|
doTest(() => new C.cc07(x, y));
|
||||||
|
doTest(() => new C.cc08(x, y));
|
||||||
|
doTest(() => new C.cc09(x, y));
|
||||||
|
doTest(() => new C.cc10(x, y));
|
||||||
|
doTest(() => new C.cc11(x, y));
|
||||||
|
doTest(() => new C.nc01(x, y));
|
||||||
|
doTest(() => new C.nc02(x, y));
|
||||||
|
doTest(() => new C.nc03(x, y));
|
||||||
|
doTest(() => new C.nc05(x, y));
|
||||||
|
doTest(() => new C.nc06(x, y));
|
||||||
|
doTest(() => new C.nc07(x, y));
|
||||||
|
doTest(() => new C.nc08(x, y));
|
||||||
|
doTest(() => new C.nc09(x, y));
|
||||||
|
doTest(() => new C.nc10(x, y));
|
||||||
|
doTest(() => new C.nc11(x, y));
|
||||||
|
doTest(() => new C.fc01(x, y));
|
||||||
|
doTest(() => new C.fc02(x, y));
|
||||||
|
doTest(() => new C.fc03(x, y));
|
||||||
|
doTest(() => new C.fc05(x, y));
|
||||||
|
doTest(() => new C.fc06(x, y));
|
||||||
|
doTest(() => new C.fc07(x, y));
|
||||||
|
doTest(() => new C.fc08(x, y));
|
||||||
|
doTest(() => new C.fc09(x, y));
|
||||||
|
doTest(() => new C.fc10(x, y));
|
||||||
|
doTest(() => new C.fc11(x, y));
|
||||||
|
}
|
||||||
|
|
104
tests/language/assert/message_test.dart
Normal file
104
tests/language/assert/message_test.dart
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
// Copyright (c) 2016, 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 "dart:async";
|
||||||
|
|
||||||
|
import "package:async_helper/async_helper.dart";
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
// TODO(rnystrom): Unify with assert_with_message_test.dart.
|
||||||
|
|
||||||
|
main() {
|
||||||
|
// Only run with asserts enabled mode.
|
||||||
|
bool assertsEnabled = false;
|
||||||
|
assert(assertsEnabled = true);
|
||||||
|
if (!assertsEnabled) return;
|
||||||
|
|
||||||
|
// Basics.
|
||||||
|
assert(true, "");
|
||||||
|
|
||||||
|
dynamic x = null;
|
||||||
|
// Successful asserts won't execute message.
|
||||||
|
assert(true, x + 42);
|
||||||
|
assert(true, throw "unreachable");
|
||||||
|
|
||||||
|
// Can use any value as message.
|
||||||
|
try {
|
||||||
|
assert(false, 42);
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals(42, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(false, "");
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals("", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(false, null);
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals(null, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test expression can throw.
|
||||||
|
try {
|
||||||
|
assert(throw "test", throw "message");
|
||||||
|
} on String catch (e) {
|
||||||
|
Expect.equals("test", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message expression can throw.
|
||||||
|
try {
|
||||||
|
assert(false, throw "message");
|
||||||
|
} on String catch (e) {
|
||||||
|
Expect.equals("message", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failing asserts evaluate message after test.
|
||||||
|
var list = [];
|
||||||
|
try {
|
||||||
|
assert((list..add(1)).isEmpty, (list..add(3)).length);
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals(2, e.message);
|
||||||
|
Expect.listEquals([1, 3], list);
|
||||||
|
}
|
||||||
|
|
||||||
|
asyncStart();
|
||||||
|
asyncTests().then((_) {
|
||||||
|
asyncEnd();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future asyncTests() async {
|
||||||
|
// You can await in both condition and message.
|
||||||
|
assert(true, await 0);
|
||||||
|
assert(await true, 1);
|
||||||
|
assert(await true, await 2);
|
||||||
|
|
||||||
|
// Successful asserts won't await/evaluate message.
|
||||||
|
Future unreachable() => throw "unreachable";
|
||||||
|
assert(await true, await unreachable());
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(false, await 3);
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals(3, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var falseFuture = new Future.value(false);
|
||||||
|
var numFuture = new Future.value(4);
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(await falseFuture, await numFuture);
|
||||||
|
} on AssertionError catch (e) {
|
||||||
|
Expect.equals(4, e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(await falseFuture, await new Future.error("error"));
|
||||||
|
} on String catch (e) {
|
||||||
|
Expect.equals("error", e);
|
||||||
|
}
|
||||||
|
}
|
15
tests/language/assert/trailing_comma_runtime_test.dart
Normal file
15
tests/language/assert/trailing_comma_runtime_test.dart
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||||
|
// contain strange or dead code.
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
main() {
|
||||||
|
assert(true);
|
||||||
|
assert(true,);
|
||||||
|
assert(true,"message");
|
||||||
|
assert(true,"message",);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
18
tests/language/assert/trailing_comma_test.dart
Normal file
18
tests/language/assert/trailing_comma_test.dart
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
main() {
|
||||||
|
assert(true);
|
||||||
|
assert(true,);
|
||||||
|
assert(true,"message");
|
||||||
|
assert(true,"message",);
|
||||||
|
assert(true,"message",extra);
|
||||||
|
// ^^^^^
|
||||||
|
// [analyzer] SYNTACTIC_ERROR.UNEXPECTED_TOKEN
|
||||||
|
// [cfe] Unexpected token 'extra'.
|
||||||
|
assert(true,"message",,);
|
||||||
|
// ^
|
||||||
|
// [analyzer] SYNTACTIC_ERROR.UNEXPECTED_TOKEN
|
||||||
|
// [cfe] Unexpected token ','.
|
||||||
|
}
|
88
tests/language/assert/with_message_test.dart
Normal file
88
tests/language/assert/with_message_test.dart
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
// Copyright (c) 2016, 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";
|
||||||
|
|
||||||
|
main() {
|
||||||
|
var assertsEnabled = false;
|
||||||
|
assert((assertsEnabled = true));
|
||||||
|
if (!assertsEnabled) return;
|
||||||
|
|
||||||
|
// TODO(rnystrom): Test cases where the first argument to assert() is a
|
||||||
|
// function.
|
||||||
|
|
||||||
|
testAssertFails();
|
||||||
|
testAssertDoesNotFail();
|
||||||
|
testNullMessage();
|
||||||
|
testDoesNotEvaluateMessageIfAssertSucceeds();
|
||||||
|
testMessageExpressionThatThrows();
|
||||||
|
testCallsToStringOnMessageLazily();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A class with a custom toString() that tracks when it is called.
|
||||||
|
class ToString {
|
||||||
|
bool calledToString = false;
|
||||||
|
|
||||||
|
String toString() {
|
||||||
|
calledToString = true;
|
||||||
|
return "toString!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertFails() {
|
||||||
|
try {
|
||||||
|
assert(false, "Oops");
|
||||||
|
Expect.fail("Assert should throw.");
|
||||||
|
} catch (e) {
|
||||||
|
Expect.isTrue(e.toString().contains("Oops"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testAssertDoesNotFail() {
|
||||||
|
try {
|
||||||
|
assert(true, "Oops");
|
||||||
|
} catch (e) {
|
||||||
|
Expect.fail("Assert should not throw.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testNullMessage() {
|
||||||
|
try {
|
||||||
|
assert(false, null);
|
||||||
|
Expect.fail("Assert should throw.");
|
||||||
|
} catch (e) {
|
||||||
|
Expect.isTrue(e.toString().contains("is not true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testDoesNotEvaluateMessageIfAssertSucceeds() {
|
||||||
|
try {
|
||||||
|
var evaluated = false;
|
||||||
|
assert(true, evaluated = true);
|
||||||
|
Expect.isFalse(evaluated);
|
||||||
|
} catch (e) {
|
||||||
|
Expect.fail("Assert should not throw.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testMessageExpressionThatThrows() {
|
||||||
|
try {
|
||||||
|
assert(false, throw "dang");
|
||||||
|
Expect.fail("Should throw");
|
||||||
|
} catch (e) {
|
||||||
|
Expect.equals(e, "dang");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testCallsToStringOnMessageLazily() {
|
||||||
|
var toString = new ToString();
|
||||||
|
try {
|
||||||
|
assert(false, toString);
|
||||||
|
Expect.fail("Assert should throw.");
|
||||||
|
} catch (e) {
|
||||||
|
Expect.isFalse(toString.calledToString);
|
||||||
|
Expect.isTrue(e.toString().contains("Instance of 'ToString'"));
|
||||||
|
Expect.isFalse(toString.calledToString);
|
||||||
|
}
|
||||||
|
}
|
28
tests/language/assert/with_type_test_or_cast_test.dart
Normal file
28
tests/language/assert/with_type_test_or_cast_test.dart
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// Issue 3741: generic type tests and casts fail in assertion statements
|
||||||
|
// when run in production mode.
|
||||||
|
//
|
||||||
|
// The cause was incomplete generic type skipping, so each of the assert
|
||||||
|
// statements below would fail.
|
||||||
|
//
|
||||||
|
// VMOptions=
|
||||||
|
// VMOptions=--enable_asserts
|
||||||
|
|
||||||
|
main() {
|
||||||
|
var names = new List<int>();
|
||||||
|
|
||||||
|
// Generic type test.
|
||||||
|
assert(names is List<int>);
|
||||||
|
|
||||||
|
// Negated generic type test.
|
||||||
|
assert(names is! List<String>);
|
||||||
|
|
||||||
|
// Generic type cast.
|
||||||
|
assert((names as List<num>).length == 0);
|
||||||
|
|
||||||
|
// Generic type test inside expression.
|
||||||
|
assert((names is List<int>));
|
||||||
|
}
|
|
@ -56,9 +56,7 @@ testMessage(value, message) {
|
||||||
try {
|
try {
|
||||||
assert(value, message);
|
assert(value, message);
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} on AssertionError catch (error) {
|
||||||
// Catch any type to allow the Boolean conversion to throw either
|
|
||||||
// AssertionError or TypeError.
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,11 +80,4 @@ main() {
|
||||||
|
|
||||||
Expect.equals(1234, testMessage(false, 1234).message);
|
Expect.equals(1234, testMessage(false, 1234).message);
|
||||||
Expect.equals('hi', testMessage(false, 'hi').message);
|
Expect.equals('hi', testMessage(false, 'hi').message);
|
||||||
|
|
||||||
// These errors do not have the message because boolean conversion failed.
|
|
||||||
Expect.notEquals(1234, testMessage(null, 1234).message);
|
|
||||||
Expect.notEquals('hi', testMessage(null, 'hi').message);
|
|
||||||
Expect.notEquals('hi', testMessage(() => null, 'hi').message);
|
|
||||||
Expect.notEquals('hi', testMessage(() => false, 'hi').message);
|
|
||||||
Expect.notEquals('hi', testMessage(() => true, 'hi').message);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue