Files
sdk/pkg/analyzer_cli/test/analysis_options_test.dart
Paul Berry bd65b86ada [analyzer_cli] Migrate to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the analyzer_cli package to use the new
constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
package's SDK constraint to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Change-Id: I563e97f19c03ad0672dba271de303b786a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508367
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-06-01 22:05:51 -07:00

90 lines
2.6 KiB
Dart

// Copyright (c) 2017, 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 'dart:io';
import 'package:analyzer_cli/src/driver.dart' show Driver, outSink, errorSink;
import 'package:analyzer_cli/src/options.dart' show ExitHandler, exitHandler;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'utils.dart' show recursiveCopy, testDirectory, withTempDirAsync;
void main() {
defineReflectiveTests(OptionsTest);
}
@reflectiveTest
class OptionsTest {
final _Runner _runner = _Runner.setUp();
void tearDown() {
_runner.tearDown();
}
Future<void> test_options() async {
// Copy to the temp directory so that existing analysis options in the test
// directory hierarchy do not interfere.
var projDir = path.join(testDirectory, 'data', 'flutter_analysis_options');
await withTempDirAsync((String tempDirPath) async {
await recursiveCopy(Directory(projDir), tempDirPath);
var expectedPath = path.join(
tempDirPath,
'somepkgs',
'flutter',
'lib',
'analysis_options.yaml',
);
expect(FileSystemEntity.isFileSync(expectedPath), isTrue);
await _runner.run2([
'--packages',
path.join(tempDirPath, 'packagelist'),
path.join(tempDirPath, 'lib', 'main.dart'),
]);
expect(_runner.stdout, contains('The parameter \'child\' is required'));
// Should be a warning as specified in 'analysis_options.yaml'.
expect(_runner.stdout, contains('1 warning found'));
});
}
}
class _Runner {
final _stdout = StringBuffer();
final _stderr = StringBuffer();
final StringSink _savedOutSink;
final StringSink _savedErrorSink;
final int _savedExitCode;
final ExitHandler _savedExitHandler;
new setUp()
: _savedOutSink = outSink,
_savedErrorSink = errorSink,
_savedExitHandler = exitHandler,
_savedExitCode = exitCode {
outSink = _stdout;
errorSink = _stderr;
exitHandler = (_) {};
}
String get stderr => _stderr.toString();
String get stdout => _stdout.toString();
Future<void> run2(List<String> args) async {
await Driver().start(args);
if (stderr.isNotEmpty) {
fail('Unexpected output to stderr:\n$stderr');
}
}
void tearDown() {
outSink = _savedOutSink;
errorSink = _savedErrorSink;
exitCode = _savedExitCode;
exitHandler = _savedExitHandler;
}
}