Files
sdk/pkg/dev_compiler/test/expression_compiler/assertions_enabled_test.dart
T
Nicholas Shahan 98a3605562 [ddc] Fix assert location in expression eval
When assertions appear in a debugger expression they now have a
synthetic source location available. This also allows for the lookup
of the actual source.

Issue: https://github.com/dart-lang/sdk/issues/43986
Fixes: https://github.com/dart-lang/sdk/issues/54956
Change-Id: I34ae5f810593b40282929d02cb290de86603922f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356287
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-03-08 17:05:10 +00:00

93 lines
2.8 KiB
Dart

// Copyright (c) 2023, 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:test/test.dart';
import '../shared_test_options.dart';
import 'expression_compiler_e2e_suite.dart';
void main(List<String> args) async {
final debug = false;
var driver = await ExpressionEvaluationTestDriver.init();
var setup = SetupCompilerOptions(args: args);
setup.options.verbose = debug;
group('Asserts', () {
const source = r'''
void main() {
var b = const bool.fromEnvironment('dart.web.assertions_enabled');
// Breakpoint: bp
print('hello world');
}
int myAssert() {
assert(false);
return 0;
}
''';
setUpAll(() => driver.initSource(setup, source));
tearDownAll(() async {
await driver.cleanupTest();
await driver.finish();
});
if (setup.enableAsserts) {
group('enabled |', () {
test('dart.web.assertions_enabled is set', () async {
await driver.checkInFrame(
breakpointId: 'bp', expression: 'b', expectedResult: 'true');
});
test('assert errors in the source code', () async {
await driver.checkInFrame(
breakpointId: 'bp',
expression: 'myAssert()',
expectedError: allOf(
contains('Error: Assertion failed:'),
contains('test.dart:8:16'),
contains('false'),
contains('is not true'),
));
});
test('assert errors in evaluated expression', () async {
await driver.checkInFrame(
breakpointId: 'bp',
expression: '() { assert(false); return 0; } ()',
expectedError: allOf(
contains('Error: Assertion failed:'),
contains('org-dartlang-debug:synthetic_debug_expression:1:13'),
contains('false'),
contains('is not true'),
));
});
});
}
if (!setup.enableAsserts) {
group('disabled |', () {
test('dart.web.assertions_enabled is not set', () async {
await driver.checkInFrame(
breakpointId: 'bp', expression: 'b', expectedResult: 'false');
});
test('no assert errors in the source code', () async {
await driver.checkInFrame(
breakpointId: 'bp',
expression: 'myAssert()',
expectedResult: '0');
});
test('no assert errors in evaluated expression', () async {
await driver.checkInFrame(
breakpointId: 'bp',
expression: '() { assert(false); return 0; } ()',
expectedResult: '0');
});
});
}
});
}