Fix issue where invalid analysis options file is produced for some tests

R=brianwilkerson@google.com

fixes: https://github.com/dart-lang/sdk/issues/54921
Change-Id: Ib1d7fa2400ea587ff66568efdaec67559cad1e6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352866
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Osama Alraddadi <osama.alraddadi@gmail.com>
This commit is contained in:
osaxma 2024-02-20 16:51:00 +00:00 committed by Commit Queue
parent bf17088787
commit a3cb1f6bdc

View file

@ -119,39 +119,41 @@ class AbstractContextTest
/// Create an analysis options file based on the given arguments.
void createAnalysisOptionsFile({
List<String>? experiments,
List<String>? cannotIgnore,
List<String>? lints,
Map<String, Object?>? errors,
List<String> experiments = const [],
List<String> cannotIgnore = const [],
List<String> lints = const [],
Map<String, Object?> errors = const {},
}) {
var buffer = StringBuffer();
if (experiments != null || cannotIgnore != null || errors != null) {
if (experiments.isNotEmpty ||
cannotIgnore.isNotEmpty ||
errors.isNotEmpty) {
buffer.writeln('analyzer:');
}
if (errors != null) {
if (errors.isNotEmpty) {
buffer.writeln(' errors:');
for (var error in errors.entries) {
buffer.writeln(' ${error.key}: ${error.value}');
}
}
if (experiments != null) {
if (experiments.isNotEmpty) {
buffer.writeln(' enable-experiment:');
for (var experiment in experiments) {
buffer.writeln(' - $experiment');
}
}
if (cannotIgnore != null) {
if (cannotIgnore.isNotEmpty) {
buffer.writeln(' cannot-ignore:');
for (var unignorable in cannotIgnore) {
buffer.writeln(' - $unignorable');
}
}
if (lints != null) {
if (lints.isNotEmpty) {
buffer.writeln('linter:');
buffer.writeln(' rules:');
for (var lint in lints) {