mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 20:51:19 +00:00
Revert "Resolve package pubspec of target for relevant dartdev commands"
This reverts commit 645511d7f4
.
Reason for revert: Deemed too risky to land so close to the release branch cut
Original change's description:
> Resolve package pubspec of target for relevant dartdev commands
>
> Adds a `--no-pub` flag to those commands
>
> Bug: https://github.com/dart-lang/sdk/issues/50422
> Change-Id: I949605c4ebb4c609eb19159625958317e54523a9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291500
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Jonas Jensen <jonasfj@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Bug: https://github.com/dart-lang/sdk/issues/50422
Change-Id: I465e43c59240e545658dce2e3fd764755d55ca97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293560
Auto-Submit: Ben Konyi <bkonyi@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
a88aebf59a
commit
ffe1c532e5
|
@ -84,12 +84,6 @@ class AnalyzeCommand extends DartdevCommand {
|
|||
'supplies a mapping of package names\ninto paths.',
|
||||
hide: !verbose,
|
||||
)
|
||||
..addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
)
|
||||
..addOption(
|
||||
'sdk-path',
|
||||
valueHelp: 'path',
|
||||
|
@ -112,19 +106,7 @@ class AnalyzeCommand extends DartdevCommand {
|
|||
// Find targets from the 'rest' params.
|
||||
final List<io.FileSystemEntity> targets = [];
|
||||
if (args.rest.isEmpty) {
|
||||
if (args['pub']) {
|
||||
// If there was no specified targets, we analyze the surrounding project,
|
||||
// and make sure that the pubspec.yaml (if it exists) is resolved.
|
||||
final target = await findEnclosingProjectAndResolveIfNeeded(
|
||||
io.Directory.current.path);
|
||||
if (target == null) {
|
||||
usageException('No dart project found.\n'
|
||||
'Run from inside a dart project, or pass the path to the files to analyze');
|
||||
}
|
||||
targets.add(io.Directory(target));
|
||||
} else {
|
||||
targets.add(io.Directory.current);
|
||||
}
|
||||
} else {
|
||||
for (String targetPath in args.rest) {
|
||||
if (io.Directory(targetPath).existsSync()) {
|
||||
|
|
|
@ -72,58 +72,13 @@ class CompileJSCommand extends CompileSubcommandCommand {
|
|||
|
||||
if (!Sdk.checkArtifactExists(librariesPath)) return 255;
|
||||
|
||||
// We need to find the single bare arg (argument that is not an option or
|
||||
// flag).
|
||||
//
|
||||
// dart2js argument parsing is a bit idiosyncratic:
|
||||
//
|
||||
// The only options that can be separated from their value is --output, --out
|
||||
// -o and --define. (But not the synonym -D).
|
||||
//
|
||||
// (see: /usr/local/google/home/sigurdm/projects/dart-sdk/sdk/pkg/compiler/lib/src/dart2js.dart
|
||||
// those that allow separation are those defined with `_ManyOptions`).
|
||||
//
|
||||
// dart2js argument handling doesn't support the -- convention.
|
||||
//
|
||||
// TODO(sigurdm): try finding a cleaner solution.
|
||||
var hasSeenPackages = false;
|
||||
// Whether the `--pub` flag is enabled.
|
||||
var pubArg = true; // default to true.
|
||||
final arguments = argResults!.arguments.toList();
|
||||
String? target;
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
final arg = arguments[i];
|
||||
if (arg == '--pub' || arg == '--no-pub') {
|
||||
pubArg = (arg == '--pub');
|
||||
// Don't pass this argument to dart2js.
|
||||
arguments.removeAt(i);
|
||||
i--;
|
||||
} else if (arg.startsWith('-')) {
|
||||
if (['-o', '--output', '--out', '--define'].contains(arg)) {
|
||||
i++;
|
||||
} else if (arg.startsWith('--packages=')) {
|
||||
hasSeenPackages = true;
|
||||
}
|
||||
} else {
|
||||
// Multiple bare arguments will be rejected by dart2js
|
||||
target = arg;
|
||||
}
|
||||
}
|
||||
if (pubArg &&
|
||||
!hasSeenPackages &&
|
||||
target != null &&
|
||||
File(target).existsSync()) {
|
||||
// Resolve the pubspec of the project surrounding [sourcePath].
|
||||
await findEnclosingProjectAndResolveIfNeeded(path.dirname(target));
|
||||
}
|
||||
|
||||
VmInteropHandler.run(
|
||||
sdk.dart2jsSnapshot,
|
||||
[
|
||||
'--libraries-spec=$librariesPath',
|
||||
'--cfe-invocation-modes=compile',
|
||||
'--invoker=dart_cli',
|
||||
...arguments,
|
||||
...argResults!.arguments,
|
||||
],
|
||||
packageConfigOverride: null,
|
||||
);
|
||||
|
@ -178,13 +133,7 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
|
|||
help: soundNullSafetyOption.help,
|
||||
defaultsTo: soundNullSafetyOption.flagDefaultsTo,
|
||||
hide: true)
|
||||
..addExperimentalFlags(verbose: verbose)
|
||||
..addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
);
|
||||
..addExperimentalFlags(verbose: verbose);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -249,10 +198,6 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
|
|||
}
|
||||
|
||||
final String? packages = args[packagesOption.flag];
|
||||
if (args['pub'] && packages == null) {
|
||||
// Resolve the pubspec of the project surrounding [sourcePath].
|
||||
await findEnclosingProjectAndResolveIfNeeded(path.dirname(sourcePath));
|
||||
}
|
||||
if (packages != null) {
|
||||
buildArgs.add('--packages=$packages');
|
||||
}
|
||||
|
@ -330,12 +275,6 @@ class CompileNativeCommand extends CompileSubcommandCommand {
|
|||
valueHelp: packagesOption.valueHelp,
|
||||
help: packagesOption.help,
|
||||
)
|
||||
..addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
)
|
||||
..addFlag(soundNullSafetyOption.flag,
|
||||
help: soundNullSafetyOption.help,
|
||||
defaultsTo: soundNullSafetyOption.flagDefaultsTo,
|
||||
|
@ -387,19 +326,13 @@ Remove debugging information from the output and save it separately to the speci
|
|||
return compileErrorExitCode;
|
||||
}
|
||||
|
||||
var packages = args['packages'];
|
||||
if (args['pub'] && packages == null) {
|
||||
// Resolve the pubspec of the project surrounding [sourcePath].
|
||||
await findEnclosingProjectAndResolveIfNeeded(path.dirname(sourcePath));
|
||||
}
|
||||
|
||||
try {
|
||||
await generateNative(
|
||||
kind: format,
|
||||
sourceFile: sourcePath,
|
||||
outputFile: args['output'],
|
||||
defines: args['define'],
|
||||
packages: packages,
|
||||
packages: args['packages'],
|
||||
enableAsserts:
|
||||
commandName != exeCmdName ? args['enable-asserts'] : false,
|
||||
enableExperiment: args.enabledExperiments.join(','),
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:dartdev/src/utils.dart';
|
||||
import 'package:dartdoc/dartdoc.dart';
|
||||
import 'package:dartdoc/options.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -50,12 +49,6 @@ For additional documentation generation options, see the 'dartdoc_options.yaml'
|
|||
negatable: false,
|
||||
help: 'Try to generate the docs without saving them.',
|
||||
);
|
||||
argParser.addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -65,8 +58,7 @@ For additional documentation generation options, see the 'dartdoc_options.yaml'
|
|||
FutureOr<int> run() async {
|
||||
final options = <String>[];
|
||||
final args = argResults!;
|
||||
// The directory to create docs for.
|
||||
String? directory;
|
||||
|
||||
if (args['sdk-docs']) {
|
||||
options.add('--sdk-docs');
|
||||
} else {
|
||||
|
@ -76,12 +68,13 @@ For additional documentation generation options, see the 'dartdoc_options.yaml'
|
|||
|
||||
// Determine input directory; default to the cwd if no explicit input dir
|
||||
// is passed in.
|
||||
directory =
|
||||
args.rest.isEmpty ? io.Directory.current.path : args.rest.first;
|
||||
if (!io.Directory(directory).existsSync()) {
|
||||
usageException('Input directory doesn\'t exist: $directory');
|
||||
final directory = args.rest.isEmpty
|
||||
? io.Directory.current
|
||||
: io.Directory(args.rest.first);
|
||||
if (!directory.existsSync()) {
|
||||
usageException('Input directory doesn\'t exist: ${directory.path}');
|
||||
}
|
||||
options.add('--input=$directory');
|
||||
options.add('--input=${directory.path}');
|
||||
}
|
||||
|
||||
if (args['dry-run'] && args['validate-links']) {
|
||||
|
@ -111,9 +104,6 @@ For additional documentation generation options, see the 'dartdoc_options.yaml'
|
|||
if (verbose) {
|
||||
log.stdout('Using the following options: $options');
|
||||
}
|
||||
if (args['pub'] && directory != null) {
|
||||
await findEnclosingProjectAndResolveIfNeeded(directory);
|
||||
}
|
||||
final packageConfigProvider = PhysicalPackageConfigProvider();
|
||||
final packageBuilder = PubPackageBuilder(
|
||||
config, pubPackageMetaProvider, packageConfigProvider);
|
||||
|
|
|
@ -59,12 +59,6 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed
|
|||
'Compare the result of applying fixes to a golden file for testing.',
|
||||
hide: !verbose,
|
||||
);
|
||||
argParser.addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -112,11 +106,6 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed
|
|||
var modeText = dryRun ? ' (dry run)' : '';
|
||||
|
||||
final targetName = path.basename(fixPath);
|
||||
if (args['pub']) {
|
||||
await findEnclosingProjectAndResolveIfNeeded(
|
||||
target.isDirectory ? target.path : target.parent.path);
|
||||
}
|
||||
|
||||
Progress? computeFixesProgress = log.progress(
|
||||
'Computing fixes in ${log.ansi.emphasized(targetName)}$modeText');
|
||||
|
||||
|
|
|
@ -190,12 +190,6 @@ class RunCommand extends DartdevCommand {
|
|||
help: 'The path to a directory that dart:io calls will treat as the '
|
||||
'root of the filesystem.',
|
||||
)
|
||||
..addFlag(
|
||||
'pub',
|
||||
defaultsTo: true,
|
||||
hide: !verbose,
|
||||
help: 'Run an implicit `pub get` to resolve `pubspec.yaml` first.',
|
||||
)
|
||||
..addOption(
|
||||
'root-certs-file',
|
||||
hide: !verbose,
|
||||
|
@ -307,8 +301,6 @@ class RunCommand extends DartdevCommand {
|
|||
DartExecutableWithPackageConfig executable;
|
||||
final hasExperiments = args.enabledExperiments.isNotEmpty;
|
||||
try {
|
||||
// TODO(sigurdm): We want to also be able to run this from a subdir
|
||||
// inside a project.
|
||||
executable = await getExecutableForCommand(
|
||||
mainCommand,
|
||||
allowSnapshot: !(useResidentServer || hasExperiments),
|
||||
|
@ -317,12 +309,6 @@ class RunCommand extends DartdevCommand {
|
|||
log.stderr(e.message);
|
||||
return errorExitCode;
|
||||
}
|
||||
if (args['pub'] &&
|
||||
args['packages'] == null &&
|
||||
executable.packageConfig == null) {
|
||||
await findEnclosingProjectAndResolveIfNeeded(
|
||||
dirname(executable.executable));
|
||||
}
|
||||
|
||||
final residentServerInfoFile = hasServerInfoOption
|
||||
? File(maybeUriToFilename(args[serverInfoOption]))
|
||||
|
|
|
@ -7,9 +7,6 @@ import 'dart:math' as math;
|
|||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:pub/pub.dart';
|
||||
|
||||
import 'core.dart';
|
||||
|
||||
/// For commands where we are able to initialize the [ArgParser], this value
|
||||
/// is used as the usageLineLength.
|
||||
|
@ -324,44 +321,3 @@ class _MarkdownCell {
|
|||
|
||||
_MarkdownCell(this.value, this.right);
|
||||
}
|
||||
|
||||
/// Looks for a "project folder" in [dir] and all parent directories.
|
||||
///
|
||||
/// A project folder is one with either a pubspec.yaml or a
|
||||
/// .dart_tool/package_config.json.
|
||||
///
|
||||
/// If the folder found has a pubspec.yaml, we ensure that is resolved to an
|
||||
/// up-to-date .dart_tool/package_config.json. If that fails to resolve we print
|
||||
/// an error and exit.
|
||||
///
|
||||
/// Returns the path of the folder was found, or `null` if no folder was found.
|
||||
Future<String?> findEnclosingProjectAndResolveIfNeeded(String dir) async {
|
||||
while (true) {
|
||||
if (File(p.join(dir, 'pubspec.yaml')).existsSync()) {
|
||||
try {
|
||||
await ensurePubspecResolved(
|
||||
dir,
|
||||
// Give full output to inform about outdated dependencies.
|
||||
// This will only happen if pub decides it needs a new resolution.
|
||||
summaryOnly: false,
|
||||
);
|
||||
} on ResolutionFailedException catch (e) {
|
||||
log.stderr(e.message);
|
||||
exit(255);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
if (File(p.join(dir, '.dart_tool', 'package_config.json')).existsSync()) {
|
||||
return dir;
|
||||
}
|
||||
if (p.equals(dir, '.')) {
|
||||
dir = p.absolute(dir);
|
||||
}
|
||||
final parent = p.dirname(dir);
|
||||
if (p.equals(parent, dir)) {
|
||||
// We have reached the root.
|
||||
return null;
|
||||
}
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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:cli_util/cli_logging.dart';
|
||||
import 'package:dartdev/src/analysis_server.dart';
|
||||
import 'package:dartdev/src/commands/analyze.dart';
|
||||
|
@ -532,32 +530,6 @@ void f() {
|
|||
expect(cache.findDirectory('.analysis-driver'), isNotNull);
|
||||
});
|
||||
|
||||
test('with no target resolves pubspec in current dir', () async {
|
||||
final bar = project(name: 'bar', mainSrc: 'final x = 42;');
|
||||
|
||||
final p = project(pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': bar.dirPath}
|
||||
}
|
||||
});
|
||||
p.file('main.dart', '''
|
||||
import 'package:bar/main.dart';
|
||||
int get foo => 'str'; // An error, to ensure we actually analyze the thing.
|
||||
void main(args) {
|
||||
print(x); // this should not be.
|
||||
}
|
||||
''');
|
||||
// Run in a sub-dir of the project with a relative path to the main.
|
||||
// The pubspec should be resolved. And the whole project analyzed.
|
||||
final subDir = path.join(p.dirPath, 'subdir');
|
||||
Directory(subDir).createSync();
|
||||
final result = await p.runAnalyze([], workingDir: subDir);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout,
|
||||
allOf(contains('return_of_invalid_type'), contains('1 issue found.')));
|
||||
expect(result.exitCode, isNot(0));
|
||||
});
|
||||
|
||||
group('display mode', () {
|
||||
final sampleInfoJson = {
|
||||
'severity': 'INFO',
|
||||
|
|
|
@ -1258,81 +1258,6 @@ void main() {
|
|||
expect(result.exitCode, 0);
|
||||
});
|
||||
|
||||
// One test per sub-command, as they do not share the target resolution code.
|
||||
for (final command in [
|
||||
'exe',
|
||||
'js',
|
||||
'jit-snapshot',
|
||||
'aot-snapshot',
|
||||
'kernel',
|
||||
]) {
|
||||
test('`compile $command` resolves pubspec for target project', () async {
|
||||
final bar = project(name: 'bar', mainSrc: 'final x = 42;');
|
||||
|
||||
final p = project(mainSrc: '''
|
||||
import 'package:bar/main.dart';
|
||||
void main(args) {
|
||||
print(x);
|
||||
}
|
||||
''', pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': bar.dirPath}
|
||||
}
|
||||
});
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should be resolved.
|
||||
final siblingDir = path.join(p.root.path, 'sibling');
|
||||
Directory(siblingDir).createSync();
|
||||
final target = path.relative(
|
||||
path.join(p.dirPath, 'lib', 'main.dart'),
|
||||
from: siblingDir,
|
||||
);
|
||||
|
||||
final result = await p
|
||||
.run(['compile', command, target, '-o', 'a'], workingDir: siblingDir);
|
||||
// TODO(sigurdm): expect something from stdout and stderr, however they
|
||||
// are highly irregular between commands.
|
||||
expect(result.exitCode, 0);
|
||||
});
|
||||
|
||||
test(
|
||||
'`compile $command --no-pub` doesn\'t resolve pubspec for target project',
|
||||
() async {
|
||||
final bar = project(name: 'bar', mainSrc: 'final x = does not compile;');
|
||||
final bar2 = project(name: 'bar', mainSrc: 'final x = 42;');
|
||||
|
||||
final p = project(mainSrc: '''
|
||||
import 'package:bar/main.dart';
|
||||
void main(args) {
|
||||
print(x);
|
||||
}
|
||||
''', pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': bar.dirPath}
|
||||
}
|
||||
});
|
||||
p.file('.dart_tool/package_config.json', '''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "bar",
|
||||
"rootUri": "${bar2.dirPath}",
|
||||
"packageUri": "${path.join(bar2.dirPath, 'lib')}"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should not be resolved due to '--no-pub'.
|
||||
final result = await p
|
||||
.run(['compile', command, '--no-pub', p.relativeFilePath, '-o', 'a']);
|
||||
// TODO(sigurdm): expect something from stdout and stderr, however they
|
||||
// are highly irregular between commands.
|
||||
expect(result.exitCode, 0);
|
||||
});
|
||||
}
|
||||
|
||||
if (Platform.isMacOS) {
|
||||
test('Compile and run executable from signed dartaotruntime', () async {
|
||||
// Either the locally built dartaotruntime is already linker signed
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
// 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:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../utils.dart';
|
||||
|
@ -131,37 +128,4 @@ class Foo {
|
|||
// --validate-links flag.
|
||||
expect(result.stdout, contains('Documenting dartdev_temp'));
|
||||
});
|
||||
|
||||
test('`doc <dir>` resolves pubspec for target dir', () async {
|
||||
final bar = project(name: 'bar', mainSrc: 'final x = 42;');
|
||||
|
||||
final p = project(mainSrc: '''
|
||||
import 'package:bar/main.dart';
|
||||
/// Prints hello.
|
||||
void sayHello(args) {
|
||||
print('hello');
|
||||
}
|
||||
''', pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': bar.dirPath}
|
||||
}
|
||||
});
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should be resolved.
|
||||
final siblingDir = path.join(p.root.path, 'sibling');
|
||||
Directory(siblingDir).createSync();
|
||||
final target = path.relative(p.dirPath, from: siblingDir);
|
||||
final outputDir = path.join(siblingDir, 'doc', 'api');
|
||||
|
||||
final result = await p.run(['doc', target], workingDir: siblingDir);
|
||||
expect(
|
||||
result.stdout,
|
||||
allOf(
|
||||
contains('Documenting dartdev_temp...'),
|
||||
contains('Documented 1 public library'),
|
||||
contains('Success! Docs generated into $outputDir'),
|
||||
));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ Matcher stringContainsInOrderWithVariableBullets(List<String> substrings) {
|
|||
}
|
||||
|
||||
void defineFix() {
|
||||
TestProject? p;
|
||||
late ProcessResult result;
|
||||
|
||||
void assertResult({int exitCode = 0}) {
|
||||
|
@ -58,9 +59,9 @@ ${result.stderr}
|
|||
|
||||
group('usage', () {
|
||||
test('--help', () async {
|
||||
final p = project(mainSrc: 'int get foo => 1;\n');
|
||||
p = project(mainSrc: 'int get foo => 1;\n');
|
||||
|
||||
var result = await p.runFix([p.dirPath, '--help']);
|
||||
var result = await p!.runFix([p!.dirPath, '--help']);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
|
@ -74,9 +75,9 @@ ${result.stderr}
|
|||
});
|
||||
|
||||
test('--help --verbose', () async {
|
||||
final p = project(mainSrc: 'int get foo => 1;\n');
|
||||
p = project(mainSrc: 'int get foo => 1;\n');
|
||||
|
||||
var result = await p.runFix([p.dirPath, '--help', '--verbose']);
|
||||
var result = await p!.runFix([p!.dirPath, '--help', '--verbose']);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
|
@ -93,9 +94,9 @@ ${result.stderr}
|
|||
});
|
||||
|
||||
test('no args', () async {
|
||||
final p = project(mainSrc: 'int get foo => 1;\n');
|
||||
p = project(mainSrc: 'int get foo => 1;\n');
|
||||
|
||||
var result = await p.runFix([p.dirPath]);
|
||||
var result = await p!.runFix([p!.dirPath]);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
|
@ -106,9 +107,9 @@ ${result.stderr}
|
|||
|
||||
group('perform', () {
|
||||
test('--apply (nothing to fix)', () async {
|
||||
final p = project(mainSrc: 'int get foo => 1;\n');
|
||||
p = project(mainSrc: 'int get foo => 1;\n');
|
||||
|
||||
var result = await p.runFix(['--apply', p.dirPath]);
|
||||
var result = await p!.runFix(['--apply', p!.dirPath]);
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
|
@ -116,7 +117,7 @@ ${result.stderr}
|
|||
});
|
||||
|
||||
test('--apply (no args)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
''',
|
||||
|
@ -127,7 +128,7 @@ linter:
|
|||
''',
|
||||
);
|
||||
|
||||
var result = await p.runFix(['--apply'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -140,7 +141,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--dry-run', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -157,7 +158,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--dry-run', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--dry-run', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -176,7 +177,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--dry-run --code=(single)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -190,9 +191,9 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(
|
||||
var result = await p!.runFix(
|
||||
['--dry-run', '--code', 'prefer_single_quotes', '.'],
|
||||
workingDir: p.dirPath);
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -205,7 +206,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--dry-run --code=(single: undefined)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -219,8 +220,8 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--dry-run', '--code', '_undefined_', '.'],
|
||||
workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--dry-run', '--code', '_undefined_', '.'],
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 3);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -231,7 +232,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply lib/main.dart', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
''',
|
||||
|
@ -241,8 +242,8 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', path.join('lib', 'main.dart')],
|
||||
workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', path.join('lib', 'main.dart')],
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
result.stdout,
|
||||
|
@ -256,7 +257,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(single)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -270,9 +271,9 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(
|
||||
var result = await p!.runFix(
|
||||
['--apply', '--code', 'prefer_single_quotes', '.'],
|
||||
workingDir: p.dirPath);
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -286,11 +287,11 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(undefined)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '--code', '_undefined_', '.'],
|
||||
workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '--code', '_undefined_', '.'],
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 3);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -301,7 +302,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(not enabled)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -314,9 +315,9 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(
|
||||
var result = await p!.runFix(
|
||||
['--apply', '--code', 'prefer_single_quotes', '.'],
|
||||
workingDir: p.dirPath);
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout,
|
||||
|
@ -324,7 +325,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(multiple: one undefined)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -338,14 +339,14 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix([
|
||||
var result = await p!.runFix([
|
||||
'--apply',
|
||||
'--code',
|
||||
'_undefined_',
|
||||
'--code',
|
||||
'unnecessary_new',
|
||||
'.'
|
||||
], workingDir: p.dirPath);
|
||||
], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 3);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -356,7 +357,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(multiple)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -370,14 +371,14 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix([
|
||||
var result = await p!.runFix([
|
||||
'--apply',
|
||||
'--code',
|
||||
'prefer_single_quotes',
|
||||
'--code',
|
||||
'unnecessary_new',
|
||||
'.'
|
||||
], workingDir: p.dirPath);
|
||||
], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -392,7 +393,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply --code=(multiple: comma-delimited)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
class A {
|
||||
|
@ -406,9 +407,9 @@ linter:
|
|||
- unnecessary_new
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(
|
||||
var result = await p!.runFix(
|
||||
['--apply', '--code=prefer_single_quotes,unnecessary_new', '.'],
|
||||
workingDir: p.dirPath);
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -423,7 +424,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply (.)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
''',
|
||||
|
@ -433,7 +434,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -447,7 +448,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply (contradictory lints do not loop infinitely)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
''',
|
||||
|
@ -458,7 +459,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -473,7 +474,7 @@ linter:
|
|||
});
|
||||
|
||||
test('--apply (excludes)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
var x = "";
|
||||
''',
|
||||
|
@ -486,14 +487,14 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, contains('Nothing to fix!'));
|
||||
});
|
||||
|
||||
test('--apply (ignores)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
// ignore: prefer_single_quotes
|
||||
var x = "";
|
||||
|
@ -504,14 +505,14 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, contains('Nothing to fix!'));
|
||||
});
|
||||
|
||||
test('--apply (unused imports require a second pass)', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
import 'dart:math';
|
||||
|
||||
|
@ -523,7 +524,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
var result = await p.runFix(['--apply', '.'], workingDir: p.dirPath);
|
||||
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(
|
||||
|
@ -540,7 +541,7 @@ linter:
|
|||
|
||||
group('compare-to-golden', () {
|
||||
test('target is not a directory', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -557,7 +558,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
p.file('lib/main.dart.expect', '''
|
||||
p!.file('lib/main.dart.expect', '''
|
||||
class A {
|
||||
String a() => '';
|
||||
}
|
||||
|
@ -567,15 +568,15 @@ class B extends A {
|
|||
String a() => '';
|
||||
}
|
||||
''');
|
||||
result = await p.runFix(['--compare-to-golden', 'lib/main.dart.expect'],
|
||||
workingDir: p.dirPath);
|
||||
result = await p!.runFix(['--compare-to-golden', 'lib/main.dart.expect'],
|
||||
workingDir: p!.dirPath);
|
||||
expect(result.exitCode, 64);
|
||||
expect(result.stderr,
|
||||
startsWith('Golden comparison requires a directory argument.'));
|
||||
});
|
||||
|
||||
test('applied fixes do not match expected', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -592,7 +593,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
p.file('lib/main.dart.expect', '''
|
||||
p!.file('lib/main.dart.expect', '''
|
||||
class A {
|
||||
String a() => '';
|
||||
}
|
||||
|
@ -602,12 +603,12 @@ class B extends A {
|
|||
}
|
||||
''');
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', '.'], workingDir: p.dirPath);
|
||||
await p!.runFix(['--compare-to-golden', '.'], workingDir: p!.dirPath);
|
||||
assertResult(exitCode: 1);
|
||||
});
|
||||
|
||||
test('applied fixes match expected', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -624,7 +625,7 @@ linter:
|
|||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
p.file('lib/main.dart.expect', '''
|
||||
p!.file('lib/main.dart.expect', '''
|
||||
class A {
|
||||
String a() => '';
|
||||
}
|
||||
|
@ -635,12 +636,12 @@ class B extends A {
|
|||
}
|
||||
''');
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', '.'], workingDir: p.dirPath);
|
||||
await p!.runFix(['--compare-to-golden', '.'], workingDir: p!.dirPath);
|
||||
assertResult();
|
||||
});
|
||||
|
||||
test('missing expect', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -658,27 +659,27 @@ linter:
|
|||
''',
|
||||
);
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', '.'], workingDir: p.dirPath);
|
||||
await p!.runFix(['--compare-to-golden', '.'], workingDir: p!.dirPath);
|
||||
assertResult(exitCode: 1);
|
||||
});
|
||||
|
||||
test('missing original', () async {
|
||||
final p = project(mainSrc: '''
|
||||
p = project(mainSrc: '''
|
||||
class C {}
|
||||
''');
|
||||
p.file('lib/main.dart.expect', '''
|
||||
p!.file('lib/main.dart.expect', '''
|
||||
class C {}
|
||||
''');
|
||||
p.file('lib/secondary.dart.expect', '''
|
||||
p!.file('lib/secondary.dart.expect', '''
|
||||
class A {}
|
||||
''');
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', '.'], workingDir: p.dirPath);
|
||||
await p!.runFix(['--compare-to-golden', '.'], workingDir: p!.dirPath);
|
||||
assertResult(exitCode: 1);
|
||||
});
|
||||
|
||||
test('no fixes to apply does not match expected', () async {
|
||||
final p = project(
|
||||
p = project(
|
||||
mainSrc: '''
|
||||
class A {
|
||||
String a() => "";
|
||||
|
@ -690,42 +691,14 @@ linter:
|
|||
- annotate_overrides
|
||||
''',
|
||||
);
|
||||
p.file('lib/main.dart.expect', '''
|
||||
p!.file('lib/main.dart.expect', '''
|
||||
class A {
|
||||
String a() => '';
|
||||
}
|
||||
''');
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', '.'], workingDir: p.dirPath);
|
||||
await p!.runFix(['--compare-to-golden', '.'], workingDir: p!.dirPath);
|
||||
assertResult(exitCode: 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('Will resolve pubspec of project containing target', () async {
|
||||
final p = project(
|
||||
mainSrc: '''
|
||||
import 'package:bar/main.dart';
|
||||
|
||||
final a = "";
|
||||
''',
|
||||
analysisOptions: '''
|
||||
linter:
|
||||
rules:
|
||||
- prefer_single_quotes
|
||||
''',
|
||||
);
|
||||
p.file('lib/main.dart.expect', '''
|
||||
import 'package:bar/main.dart';
|
||||
|
||||
final a = '';
|
||||
''');
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should be resolved.
|
||||
final siblingDir = path.join(p.root.path, 'sibling');
|
||||
Directory(siblingDir).createSync();
|
||||
final target = path.relative(path.join(p.dirPath, 'lib'), from: siblingDir);
|
||||
result =
|
||||
await p.runFix(['--compare-to-golden', target], workingDir: siblingDir);
|
||||
assertResult(exitCode: 0);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -222,87 +222,6 @@ void main(List<String> args) => print("$b $args");
|
|||
expect(result.exitCode, 0);
|
||||
});
|
||||
|
||||
test('Resolves pubspec in the project where target file resides', () async {
|
||||
final bar = project(name: 'bar', mainSrc: 'final x = 42;');
|
||||
|
||||
p = project(pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': bar.dirPath}
|
||||
}
|
||||
});
|
||||
p.file('main.dart', '''
|
||||
import 'package:bar/main.dart';
|
||||
void main(args) {
|
||||
print(x);
|
||||
print(args);
|
||||
}
|
||||
''');
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should be resolved.
|
||||
final siblingDir = path.join(p.root.path, 'sibling');
|
||||
Directory(siblingDir).createSync();
|
||||
final target =
|
||||
path.relative(path.join(p.dirPath, 'main.dart'), from: siblingDir);
|
||||
final result = await p.run(
|
||||
[
|
||||
'run',
|
||||
'--enable-experiment=test-experiment',
|
||||
target,
|
||||
'--argument1',
|
||||
'argument2',
|
||||
],
|
||||
workingDir: siblingDir,
|
||||
);
|
||||
|
||||
// --enable-experiment and main.dart should not be passed.
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, equals('42\n[--argument1, argument2]\n'));
|
||||
expect(result.exitCode, 0);
|
||||
});
|
||||
|
||||
test('Reports errors from pubspec in the project where target file resides',
|
||||
() async {
|
||||
p = project(pubspecExtras: {
|
||||
'dependencies': {
|
||||
'bar': {'path': '../does_not_exist'}
|
||||
}
|
||||
});
|
||||
p.file('main.dart', '''
|
||||
import 'package:bar/main.dart';
|
||||
void main(args) {
|
||||
print(x);
|
||||
print(args);
|
||||
}
|
||||
''');
|
||||
// Run in a sibling-dir to the project with a relative path to the main.
|
||||
// The pubspec should be resolved.
|
||||
final siblingDir = path.join(p.root.path, 'sibling');
|
||||
Directory(siblingDir).createSync();
|
||||
final target =
|
||||
path.relative(path.join(p.dirPath, 'main.dart'), from: siblingDir);
|
||||
final result = await p.run(
|
||||
[
|
||||
'run',
|
||||
'--enable-experiment=test-experiment',
|
||||
target,
|
||||
'--argument1',
|
||||
'argument2',
|
||||
],
|
||||
workingDir: siblingDir,
|
||||
);
|
||||
|
||||
// --enable-experiment and main.dart should not be passed.
|
||||
expect(
|
||||
result.stderr,
|
||||
allOf(
|
||||
contains('(could not find package bar at "../does_not_exist")'),
|
||||
contains('version solving failed.'),
|
||||
),
|
||||
);
|
||||
expect(result.stdout, isEmpty);
|
||||
expect(result.exitCode, 255);
|
||||
});
|
||||
|
||||
test('with file uri', () async {
|
||||
p = project();
|
||||
p.file('main.dart', 'void main(args) { print(args); }');
|
||||
|
@ -852,7 +771,7 @@ void residentRun() {
|
|||
p = project(
|
||||
mainSrc: r"void main() { print(('hello','world').$1); }",
|
||||
sdkConstraint: VersionConstraint.parse(
|
||||
'^3.0.0-0',
|
||||
'^3.0.0',
|
||||
),
|
||||
);
|
||||
final result = await p.run([
|
||||
|
|
|
@ -128,10 +128,7 @@ class TestProject {
|
|||
List<String> arguments, {
|
||||
String? workingDir,
|
||||
}) async {
|
||||
return run(
|
||||
['fix', '--suppress-analytics', ...arguments],
|
||||
workingDir: workingDir,
|
||||
);
|
||||
return run(['fix', '--suppress-analytics', ...arguments]);
|
||||
}
|
||||
|
||||
Future<ProcessResult> run(
|
||||
|
|
|
@ -160,12 +160,8 @@ abstract class LaunchingVMServiceHelper extends VMServiceHelper {
|
|||
_started = true;
|
||||
_process = await Process.start(
|
||||
Platform.resolvedExecutable,
|
||||
[
|
||||
"--pause_isolates_on_start",
|
||||
"--enable-vm-service=0",
|
||||
"run",
|
||||
"--no-pub", // We don't want to resolve the local pubspec here.
|
||||
]..addAll(scriptAndArgs));
|
||||
["--pause_isolates_on_start", "--enable-vm-service=0"]
|
||||
..addAll(scriptAndArgs));
|
||||
_process.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(new LineSplitter())
|
||||
|
|
Loading…
Reference in a new issue