Files
sdk/tests/language/vm/bool_check_stack_traces_test.dart
T
Robert Nystrom 5bb9e922db Opt multitests out of formatting in language/.
The new formatter supports opting a region of code out from being
formatted. I'm applying this marker to all of the multitests since
those tests are often very sensitive to formatting and easily broken.
This way, anyone touching a multitest (including me when I reformat
the tests) doesn't have to remember to not run the formatter on it.

Unfortunately, this doesn't opt out 100# of the multitests. There are a
handful of multitests that also contain "@dart=" comments and are thus
formatted using the old style where the "// dart format off" marker has
no effect. For those, we'll have to still be careful to not accidentally
format them.

Change-Id: I257d0ee1eb44eee57047be06b8520f0ccc7b56d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396162
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2024-11-21 10:49:44 +00:00

114 lines
2.6 KiB
Dart

// 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.
// Formatting can break multitests, so don't format them.
// dart format off
import "package:expect/expect.dart";
import "package:expect/variations.dart";
class Test1 {
void bar(dynamic condition) {
if (condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test1(dynamic condition) {
Test1 obj = new Test1();
obj.bar(condition);
}
class Test2 {
dynamic condition;
Test2(this.condition);
void bar() {
if (!condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test2(dynamic condition) {
Test2 obj = new Test2(condition);
obj.bar();
}
class Test3 {
dynamic 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(dynamic condition) {
Test3 obj = new Test3(condition);
obj.bar();
}
const dynamic test4Condition = null;
void test4(dynamic condition) {
if (test4Condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void test5(dynamic condition) {
if (null as dynamic) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void testStackTrace(void testCase(dynamic 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('-----------------------------');
if (!unsoundNullSafety) {
Expect.isTrue(e is TypeError);
Expect.equals(
"type 'Null' is not a subtype of type 'bool'", e.toString());
} else {
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, [13, 22]);
testStackTrace(test2, [30, 39]);
testStackTrace(test3, [49, 58]);
testStackTrace(test4, [64]); //# 01: ok
testStackTrace(test5, [71]); //# 02: ok
}