Skip to content

Commit dd1e7ae

Browse files
Anna GringauzeCommit Queue
Anna Gringauze
authored and
Commit Queue
committed
[ddc] Run tests on canary and stable bots with matching settings
Closes: #53077 Towards: #43986 Change-Id: I60df13b8ff29a0865a45b3a48a97af0ce94460b7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317448 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Anna Gringauze <[email protected]>
1 parent d0114ec commit dd1e7ae

File tree

31 files changed

+499
-308
lines changed

31 files changed

+499
-308
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4546,23 +4546,41 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
45464546
jsCondition = runtimeCall('test(#)', [jsCondition]);
45474547
}
45484548

4549-
var encodedSource =
4550-
node.enclosingComponent!.uriToSource[node.location!.file]!.source;
4551-
var source = utf8.decode(encodedSource, allowMalformed: true);
4552-
var conditionSource =
4553-
source.substring(node.conditionStartOffset, node.conditionEndOffset);
4554-
var location = _toSourceLocation(node.conditionStartOffset)!;
4549+
SourceLocation? location;
4550+
late String conditionSource;
4551+
if (node.location != null) {
4552+
var encodedSource =
4553+
node.enclosingComponent!.uriToSource[node.location!.file]!.source;
4554+
var source = utf8.decode(encodedSource, allowMalformed: true);
4555+
4556+
conditionSource =
4557+
source.substring(node.conditionStartOffset, node.conditionEndOffset);
4558+
location = _toSourceLocation(node.conditionStartOffset)!;
4559+
} else {
4560+
// Location is null in expression compilation when modules
4561+
// are loaded from kernel using expression compiler worker.
4562+
// Show the error only in that case, with the condition AST
4563+
// instead of the source.
4564+
//
4565+
// TODO(annagrin): Can we add some information to the kernel,
4566+
// or add better printing for the condition?
4567+
// Issue: https://github.com/dart-lang/sdk/issues/43986
4568+
conditionSource = node.condition.toString();
4569+
}
45554570
return js.statement(' if (!#) #;', [
45564571
jsCondition,
45574572
runtimeCall('assertFailed(#, #, #, #, #)', [
45584573
if (node.message == null)
45594574
js_ast.LiteralNull()
45604575
else
45614576
_visitExpression(node.message!),
4562-
_cacheUri(location.sourceUrl.toString()),
4577+
if (location == null)
4578+
_cacheUri('<unknown source>')
4579+
else
4580+
_cacheUri(location.sourceUrl.toString()),
45634581
// Lines and columns are typically printed with 1 based indexing.
4564-
js.number(location.line + 1),
4565-
js.number(location.column + 1),
4582+
js.number(location == null ? -1 : location.line + 1),
4583+
js.number(location == null ? -1 : location.column + 1),
45664584
js.escapedString(conditionSource),
45674585
])
45684586
]);

pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ExpressionCompilerWorker {
8484
final CompilerOptions _compilerOptions;
8585
final ModuleFormat _moduleFormat;
8686
final bool _canaryFeatures;
87+
final bool _enableAsserts;
8788
final Component _sdkComponent;
8889

8990
void Function()? onDone;
@@ -93,17 +94,13 @@ class ExpressionCompilerWorker {
9394
this._compilerOptions,
9495
this._moduleFormat,
9596
this._canaryFeatures,
97+
this._enableAsserts,
9698
this._sdkComponent,
9799
this.requestStream,
98100
this.sendResponse,
99101
this.onDone,
100102
);
101103

102-
// Disable asserts due to failures to load source and locations on kernel
103-
// loaded from dill files in DDC.
104-
// https://github.com/dart-lang/sdk/issues/43986
105-
static const bool _enableAsserts = false;
106-
107104
/// Create expression compiler worker from [args] and start it.
108105
///
109106
/// If [sendPort] is provided, creates a `receivePort` and sends it to
@@ -197,6 +194,7 @@ class ExpressionCompilerWorker {
197194
soundNullSafety: parsedArgs['sound-null-safety'] as bool,
198195
moduleFormat: moduleFormat,
199196
canaryFeatures: parsedArgs['canary'] as bool,
197+
enableAsserts: parsedArgs['enable-asserts'] as bool,
200198
verbose: parsedArgs['verbose'] as bool,
201199
requestStream: requestStream,
202200
sendResponse: sendResponse,
@@ -223,6 +221,7 @@ class ExpressionCompilerWorker {
223221
bool soundNullSafety = false,
224222
ModuleFormat moduleFormat = ModuleFormat.amd,
225223
bool canaryFeatures = false,
224+
bool enableAsserts = true,
226225
bool verbose = false,
227226
Stream<Map<String, dynamic>>? requestStream, // Defaults to read from stdin
228227
void Function(Map<String, dynamic>)?
@@ -242,7 +241,7 @@ class ExpressionCompilerWorker {
242241
..omitPlatform = true
243242
..environmentDefines = addGeneratedVariables({
244243
if (environmentDefines != null) ...environmentDefines,
245-
}, enableAsserts: _enableAsserts)
244+
}, enableAsserts: enableAsserts)
246245
..explicitExperimentalFlags = explicitExperimentalFlags
247246
..onDiagnostic = _onDiagnosticHandler(errors, warnings, infos)
248247
..nnbdMode = soundNullSafety ? NnbdMode.Strong : NnbdMode.Weak
@@ -267,6 +266,7 @@ class ExpressionCompilerWorker {
267266
compilerOptions,
268267
moduleFormat,
269268
canaryFeatures,
269+
enableAsserts,
270270
sdkComponent,
271271
requestStream,
272272
sendResponse,
@@ -451,8 +451,8 @@ class ExpressionCompilerWorker {
451451
summarizeApi: false,
452452
moduleName: moduleName,
453453
soundNullSafety: _compilerOptions.nnbdMode == NnbdMode.Strong,
454-
enableAsserts: _enableAsserts,
455454
canaryFeatures: _canaryFeatures,
455+
enableAsserts: _enableAsserts,
456456
),
457457
_moduleCache.componentForLibrary,
458458
_moduleCache.moduleNameForComponent,
@@ -790,6 +790,13 @@ final argParser = ArgParser()
790790
..addFlag('track-widget-creation', defaultsTo: false)
791791
..addFlag('sound-null-safety', negatable: true, defaultsTo: true)
792792
..addFlag('canary', negatable: true, defaultsTo: false)
793+
// Disable asserts in compiled code by default, which is different
794+
// from the default value of the setting in DDC.
795+
//
796+
// TODO(annagrin) Change the default to `true` after the user code
797+
// is tested with enabled asserts.
798+
// Issue: https://github.com/dart-lang/sdk/issues/43986
799+
..addFlag('enable-asserts', negatable: true, defaultsTo: false)
793800
..addFlag('verbose', defaultsTo: false);
794801

795802
Uri? _argToUri(String? uriArg) =>

pkg/dev_compiler/test/expression_compiler/assertions_enabled_test.dart

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
import 'package:test/test.dart';
66

77
import 'expression_compiler_e2e_suite.dart';
8+
import 'setup_compiler_options.dart';
89

9-
void main() async {
10+
void main(List<String> args) async {
1011
var driver = await TestDriver.init();
1112

12-
group('dart.web.assertions_enabled', () {
13+
group('Assertions |', () {
1314
const source = r'''
1415
void main() {
1516
var b = const bool.fromEnvironment('dart.web.assertions_enabled');
1617
1718
// Breakpoint: bp
1819
print('hello world');
1920
}
21+
int myAssert() {
22+
assert(false);
23+
return 0;
24+
}
2025
''';
2126

2227
tearDown(() async {
@@ -27,19 +32,52 @@ void main() async {
2732
await driver.finish();
2833
});
2934

30-
test('is automatically set', () async {
31-
var setup = SetupCompilerOptions(enableAsserts: true);
35+
test('dart.web.assertions_enabled is set when asserts are enabled',
36+
() async {
37+
var setup = SetupCompilerOptions(args: args);
38+
await driver.initSource(setup, source);
39+
40+
await driver.check(
41+
breakpointId: 'bp',
42+
expression: 'b',
43+
expectedResult: '${setup.enableAsserts}');
44+
});
45+
46+
test('assert errors in the source code when asserts are enabled', () async {
47+
var setup = SetupCompilerOptions(args: args);
3248
await driver.initSource(setup, source);
33-
// TODO(43986): Update when assertions are enabled.
49+
3450
await driver.check(
35-
breakpointId: 'bp', expression: 'b', expectedResult: 'false');
51+
breakpointId: 'bp',
52+
expression: 'myAssert()',
53+
expectedResult: setup.enableAsserts
54+
? allOf(
55+
contains('Error: Assertion failed:'),
56+
contains('test.dart:8:16'),
57+
contains('false'),
58+
contains('is not true'),
59+
)
60+
: '0',
61+
);
3662
});
3763

38-
test('is automatically unset', () async {
39-
var setup = SetupCompilerOptions(enableAsserts: false);
64+
test('assert errors in evaluated expression when asserts are enabled',
65+
() async {
66+
var setup = SetupCompilerOptions(args: args);
4067
await driver.initSource(setup, source);
68+
4169
await driver.check(
42-
breakpointId: 'bp', expression: 'b', expectedResult: 'false');
70+
breakpointId: 'bp',
71+
expression: '() { assert(false); return 0; } ()',
72+
expectedResult: setup.enableAsserts
73+
? allOf(
74+
contains('Error: Assertion failed:'),
75+
contains('<unknown source>:-1:-1'),
76+
contains('BoolLiteral(false)'),
77+
contains('is not true'),
78+
)
79+
: '0',
80+
);
4381
});
4482
});
4583
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:test/test.dart';
8+
9+
import 'expression_compiler_e2e_suite.dart';
10+
import 'setup_compiler_options.dart';
11+
12+
void main(List<String> args) async {
13+
var driver = await TestDriver.init();
14+
15+
group('canary', () {
16+
const source = r'''
17+
void main() {
18+
print('hello world');
19+
}
20+
''';
21+
22+
tearDown(() async {
23+
await driver.cleanupTest();
24+
});
25+
26+
tearDownAll(() async {
27+
await driver.finish();
28+
});
29+
30+
test('is automatically set to the configuration value', () async {
31+
var setup = SetupCompilerOptions(args: args);
32+
await driver.initSource(setup, source);
33+
34+
expect(
35+
File(driver.dartSdkPath).readAsStringSync(),
36+
setup.canaryFeatures
37+
? contains('canary')
38+
: isNot(contains('canary')));
39+
});
40+
});
41+
}

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_agnostic_sound_shard_1_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import 'package:test/test.dart';
88

99
import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
11+
import 'setup_compiler_options.dart';
1112

12-
void main() async {
13+
void main(List<String> args) async {
1314
var driver = await TestDriver.init();
1415

1516
group('(Sound null safety) (Agnostic code shard 1)', () {
@@ -19,9 +20,11 @@ void main() async {
1920

2021
group('(AMD module system)', () {
2122
var setup = SetupCompilerOptions(
22-
soundNullSafety: true,
23-
legacyCode: false,
24-
moduleFormat: ModuleFormat.amd);
23+
soundNullSafety: true,
24+
legacyCode: false,
25+
moduleFormat: ModuleFormat.amd,
26+
args: args,
27+
);
2528
runAgnosticSharedTestsShard1(setup, driver);
2629
});
2730
});

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_agnostic_sound_shard_2_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import 'package:test/test.dart';
88

99
import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
11+
import 'setup_compiler_options.dart';
1112

12-
void main() async {
13+
void main(List<String> args) async {
1314
var driver = await TestDriver.init();
1415

1516
group('(Sound null safety) (Agnostic code shard 2)', () {
@@ -19,9 +20,11 @@ void main() async {
1920

2021
group('(AMD module system)', () {
2122
var setup = SetupCompilerOptions(
22-
soundNullSafety: true,
23-
legacyCode: false,
24-
moduleFormat: ModuleFormat.amd);
23+
soundNullSafety: true,
24+
legacyCode: false,
25+
moduleFormat: ModuleFormat.amd,
26+
args: args,
27+
);
2528
runAgnosticSharedTestsShard2(setup, driver);
2629
});
2730
});

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_agnostic_unsound_shard_1_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import 'package:test/test.dart';
88

99
import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
11+
import 'setup_compiler_options.dart';
1112

12-
void main() async {
13+
void main(List<String> args) async {
1314
var driver = await TestDriver.init();
1415

1516
group('(Unsound null safety) (Agnostic code shard 1)', () {
@@ -19,9 +20,11 @@ void main() async {
1920

2021
group('(AMD module system)', () {
2122
var setup = SetupCompilerOptions(
22-
soundNullSafety: false,
23-
legacyCode: false,
24-
moduleFormat: ModuleFormat.amd);
23+
soundNullSafety: false,
24+
legacyCode: false,
25+
moduleFormat: ModuleFormat.amd,
26+
args: args,
27+
);
2528
runAgnosticSharedTestsShard1(setup, driver);
2629
});
2730
});

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_agnostic_unsound_shard_2_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import 'package:test/test.dart';
88

99
import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
11+
import 'setup_compiler_options.dart';
1112

12-
void main() async {
13+
void main(List<String> args) async {
1314
var driver = await TestDriver.init();
1415

1516
group('(Unsound null safety) (Agnostic code shard 2)', () {
@@ -19,9 +20,11 @@ void main() async {
1920

2021
group('(AMD module system)', () {
2122
var setup = SetupCompilerOptions(
22-
soundNullSafety: false,
23-
legacyCode: false,
24-
moduleFormat: ModuleFormat.amd);
23+
soundNullSafety: false,
24+
legacyCode: false,
25+
moduleFormat: ModuleFormat.amd,
26+
args: args,
27+
);
2528
runAgnosticSharedTestsShard2(setup, driver);
2629
});
2730
});

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_legacy_shard_1_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import 'package:test/test.dart';
88

99
import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
11+
import 'setup_compiler_options.dart';
1112

12-
void main() async {
13+
void main(List<String> args) async {
1314
var driver = await TestDriver.init();
1415

1516
group('(Legacy code shard 1)', () {
@@ -19,9 +20,11 @@ void main() async {
1920

2021
group('(AMD module system)', () {
2122
var setup = SetupCompilerOptions(
22-
soundNullSafety: false,
23-
legacyCode: true,
24-
moduleFormat: ModuleFormat.amd);
23+
soundNullSafety: false,
24+
legacyCode: true,
25+
moduleFormat: ModuleFormat.amd,
26+
args: args,
27+
);
2528
runAgnosticSharedTestsShard1(setup, driver);
2629
});
2730
});

0 commit comments

Comments
 (0)