mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[ CLI ] Add support for --[no-]sound-null-safety to dart compile {jit-snapshot,kernel}
Fixes https://github.com/dart-lang/sdk/issues/50079 Change-Id: I4a71dab1c9003f13ff74741bc64f3ee239c03195 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262620 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
c8651ac551
commit
72506b826a
|
@ -127,6 +127,9 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
|
|||
abbr: defineOption.abbr,
|
||||
valueHelp: defineOption.valueHelp,
|
||||
)
|
||||
..addFlag('sound-null-safety',
|
||||
help: 'Respect the nullability of types at runtime.',
|
||||
defaultsTo: null)
|
||||
..addExperimentalFlags(verbose: verbose);
|
||||
}
|
||||
|
||||
|
@ -183,6 +186,11 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
|
|||
buildArgs.add('--snapshot-kind=$formatName');
|
||||
buildArgs.add('--snapshot=${path.canonicalize(outputFile)}');
|
||||
|
||||
final bool? soundNullSafety = args['sound-null-safety'];
|
||||
if (soundNullSafety != null) {
|
||||
buildArgs.add('--${soundNullSafety ? '' : 'no-'}sound-null-safety');
|
||||
}
|
||||
|
||||
final String? packages = args[packagesOption.flag];
|
||||
if (packages != null) {
|
||||
buildArgs.add('--packages=$packages');
|
||||
|
|
|
@ -962,6 +962,56 @@ void main() {}
|
|||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile kernel with --sound-null-safety', () async {
|
||||
final p = project(mainSrc: '''void main() {
|
||||
print((<int?>[] is List<int>) ? 'oh no' : 'sound');
|
||||
}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'mydill'));
|
||||
|
||||
var result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'kernel',
|
||||
'--sound-null-safety',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, contains(soundNullSafetyMessage));
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile kernel with --no-sound-null-safety', () async {
|
||||
final p = project(mainSrc: '''void main() {
|
||||
print((<int?>[] is List<int>) ? 'unsound' : 'oh no');
|
||||
}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'mydill'));
|
||||
|
||||
var result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'kernel',
|
||||
'--no-sound-null-safety',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile kernel without info', () async {
|
||||
final p = project(mainSrc: '''void main() {}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
|
@ -1085,6 +1135,56 @@ void main() {}
|
|||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile JIT snapshot with --sound-null-safety', () async {
|
||||
final p = project(mainSrc: '''void main() {
|
||||
print((<int?>[] is List<int>) ? 'oh no' : 'sound');
|
||||
}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myjit'));
|
||||
|
||||
var result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'jit-snapshot',
|
||||
'--sound-null-safety',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, contains(soundNullSafetyMessage));
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile JIT snapshot with --no-sound-null-safety', () async {
|
||||
final p = project(mainSrc: '''void main() {
|
||||
print((<int?>[] is List<int>) ? 'unsound' : 'oh no');
|
||||
}''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'mydill'));
|
||||
|
||||
var result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'jit-snapshot',
|
||||
'--no-sound-null-safety',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
|
||||
expect(result.exitCode, 0);
|
||||
expect(File(outFile).existsSync(), true,
|
||||
reason: 'File not found: $outFile');
|
||||
});
|
||||
|
||||
test('Compile JIT snapshot with training args', () async {
|
||||
final p =
|
||||
project(mainSrc: '''void main(List<String> args) => print(args);''');
|
||||
|
|
Loading…
Reference in a new issue