mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:31:20 +00:00
94ebff2225
This CL will: - fix a bug in the legacy AnalyzerCommandOutputImpl class (in certain cases we did not report that the analyzer was missing a warning). - make the outcome of running the analyzer on a test be one of: * CompileTimeError * MissingCompileTimeError * StaticWarning * MissingStaticWarning - Make status file updates using the new Expectation markers - Remove support for '@static-clean': Previously running the analyer on a test could either result in 'Pass' or in 'Fail'. The '@static-clean' annotation has been used as a (poor) mechanism to distinguish between errors and warnings. Having the 4 markers mentioned above means we can remove '@static-clean' - Remove 100 lines of rotted legacy code in our testing scripts. - Make a status file entry for every test that has analyzer errors or warnings R=ricow@google.com Review URL: https://codereview.chromium.org//46163002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29350 260f80e4-7a28-3924-810f-c04153c831b5
219 lines
6.1 KiB
Dart
219 lines
6.1 KiB
Dart
// 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class BoolTest {
|
|
static void testEquality() {
|
|
Expect.equals(true, true);
|
|
Expect.equals(false, false);
|
|
Expect.isTrue(identical(true, true));
|
|
Expect.isFalse(identical(true, false));
|
|
Expect.isTrue(identical(false, false));
|
|
Expect.isFalse(identical(false, true));
|
|
Expect.isFalse(!identical(true, true));
|
|
Expect.isTrue(!identical(true, false));
|
|
Expect.isFalse(!identical(false, false));
|
|
Expect.isTrue(!identical(false, true));
|
|
Expect.isTrue(true == true);
|
|
Expect.isFalse(true == false);
|
|
Expect.isTrue(false == false);
|
|
Expect.isFalse(false == true);
|
|
Expect.isFalse(true != true);
|
|
Expect.isTrue(true != false);
|
|
Expect.isFalse(false != false);
|
|
Expect.isTrue(false != true);
|
|
Expect.isTrue(identical(true, (true == true)));
|
|
Expect.isTrue(identical(false, (true == false)));
|
|
Expect.isTrue(identical(true, (false == false)));
|
|
Expect.isTrue(identical(false, (false == true)));
|
|
Expect.isFalse(!identical(true, (true == true)));
|
|
Expect.isFalse(!identical(false, (true == false)));
|
|
Expect.isFalse(!identical(true, (false == false)));
|
|
Expect.isFalse(!identical(false, (false == true)));
|
|
Expect.isFalse(identical(false, (true == true)));
|
|
Expect.isFalse(identical(true, (true == false)));
|
|
Expect.isFalse(identical(false, (false == false)));
|
|
Expect.isFalse(identical(true, (false == true)));
|
|
Expect.isTrue(!identical(false, (true == true)));
|
|
Expect.isTrue(!identical(true, (true == false)));
|
|
Expect.isTrue(!identical(false, (false == false)));
|
|
Expect.isTrue(!identical(true, (false == true)));
|
|
// Expect.equals could rely on a broken boolean equality.
|
|
if (true == false) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (false == true) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (identical(true, false)) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (identical(false, true)) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (true == true) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (false == false) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (identical(true, true)) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (identical(false, false)) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (true != false) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (false != true) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (!identical(true, false)) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (!identical(false, true)) {
|
|
} else {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (true != true) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (false != false) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (!identical(true, true)) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
if (!identical(false, false)) {
|
|
throw "Expect.equals broken";
|
|
}
|
|
}
|
|
|
|
static void testToString() {
|
|
Expect.equals("true", true.toString());
|
|
Expect.equals("false", false.toString());
|
|
}
|
|
|
|
static void testNegate(isTrue, isFalse) {
|
|
Expect.equals(true, !false);
|
|
Expect.equals(false, !true);
|
|
Expect.equals(true, !isFalse);
|
|
Expect.equals(false, !isTrue);
|
|
}
|
|
|
|
static void testLogicalOp() {
|
|
testOr(a, b, onTypeError) {
|
|
try {
|
|
return a || b;
|
|
} on TypeError catch (t) {
|
|
return onTypeError;
|
|
}
|
|
}
|
|
testAnd(a, b, onTypeError) {
|
|
try {
|
|
return a && b;
|
|
} on TypeError catch (t) {
|
|
return onTypeError;
|
|
}
|
|
}
|
|
|
|
var isTrue = true;
|
|
var isFalse = false;
|
|
Expect.equals(true, testAnd(isTrue, isTrue, false));
|
|
Expect.equals(false, testAnd(isTrue, 0, false));
|
|
Expect.equals(false, testAnd(isTrue, 1, false));
|
|
Expect.equals(false, testAnd(isTrue, "true", false));
|
|
Expect.equals(false, testAnd(0, isTrue, false));
|
|
Expect.equals(false, testAnd(1, isTrue, false));
|
|
|
|
Expect.equals(true, testOr(isTrue, isTrue, false));
|
|
Expect.equals(true, testOr(isFalse, isTrue, false));
|
|
Expect.equals(true, testOr(isTrue, isFalse, false));
|
|
Expect.equals(true, testOr(isTrue, 0, true));
|
|
Expect.equals(true, testOr(isTrue, 1, true));
|
|
Expect.equals(false, testOr(isFalse, 0, false));
|
|
Expect.equals(false, testOr(isFalse, 1, false));
|
|
Expect.equals(true, testOr(0, isTrue, true));
|
|
Expect.equals(true, testOr(1, isTrue, true));
|
|
Expect.equals(false, testOr(0, isFalse, false));
|
|
Expect.equals(false, testOr(1, isFalse, false));
|
|
|
|
// Test side effects.
|
|
int trueCount = 0, falseCount = 0;
|
|
|
|
trueFunc() {
|
|
trueCount++;
|
|
return true;
|
|
}
|
|
|
|
falseFunc() {
|
|
falseCount++;
|
|
return false;
|
|
}
|
|
|
|
Expect.equals(0, trueCount);
|
|
Expect.equals(0, falseCount);
|
|
|
|
trueFunc() && trueFunc();
|
|
Expect.equals(2, trueCount);
|
|
Expect.equals(0, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
falseFunc() && trueFunc();
|
|
Expect.equals(0, trueCount);
|
|
Expect.equals(1, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
trueFunc() && falseFunc();
|
|
Expect.equals(1, trueCount);
|
|
Expect.equals(1, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
falseFunc() && falseFunc();
|
|
Expect.equals(0, trueCount);
|
|
Expect.equals(1, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
trueFunc() || trueFunc();
|
|
Expect.equals(1, trueCount);
|
|
Expect.equals(0, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
falseFunc() || trueFunc();
|
|
Expect.equals(1, trueCount);
|
|
Expect.equals(1, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
trueFunc() || falseFunc();
|
|
Expect.equals(1, trueCount);
|
|
Expect.equals(0, falseCount);
|
|
|
|
trueCount = falseCount = 0;
|
|
falseFunc() || falseFunc();
|
|
Expect.equals(0, trueCount);
|
|
Expect.equals(2, falseCount);
|
|
}
|
|
|
|
|
|
static void testMain() {
|
|
testEquality();
|
|
testNegate(true, false);
|
|
testToString();
|
|
testLogicalOp();
|
|
}
|
|
}
|
|
|
|
main() {
|
|
BoolTest.testMain();
|
|
}
|