blob: cd9c490d7d6490da6e1f0f2d4b52698fc4d81779 [file] [log] [blame]
// 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.
// @dart = 2.9
import "package:expect/expect.dart";
class Test1 {
void bar(bool condition) {
if (condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test1(bool condition) {
Test1 obj = new Test1();
obj.bar(condition);
}
class Test2 {
bool condition;
Test2(this.condition);
void bar() {
if (!condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test2(bool condition) {
Test2 obj = new Test2(condition);
obj.bar();
}
class Test3 {
bool condition;
Test3(this.condition);
bool bazz() => condition;
void bar() {
while (bazz() || bazz()) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test3(bool condition) {
Test3 obj = new Test3(condition);
obj.bar();
}
const bool test4Condition = null;
void test4(bool condition) {
if (test4Condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void test5(bool condition) {
if (null) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void testStackTrace(void testCase(bool condition), List<int> lineNumbers) {
try {
testCase(null);
Expect.fail("Using null in a bool condition should throw TypeError");
} catch (e, stacktrace) {
print('--------- exception ---------');
print(e);
print('-------- stack trace --------');
print(stacktrace);
print('-----------------------------');
Expect.isTrue(e is AssertionError);
Expect.equals(
'Failed assertion: boolean expression must not be null', e.toString());
final String st = stacktrace.toString();
for (int lineNum in lineNumbers) {
String item = '.dart:$lineNum';
Expect.isTrue(st.contains(item), "Stack trace doesn't contain $item");
}
print('OK');
}
}
main() {
testStackTrace(test1, [11, 20]);
testStackTrace(test2, [28, 37]);
testStackTrace(test3, [47, 56]);
testStackTrace(test4, [62]); //# 01: ok
testStackTrace(test5, [69]); //# 02: ok
}