Unverified Commit d80e994a authored by Sigurd Meldgaard's avatar Sigurd Meldgaard Committed by GitHub

Reland: Show output from pub get in flutter pub get (#110851)

parent 1ed23124
......@@ -980,6 +980,13 @@ class _SnippetChecker {
/// Invokes the analyzer on the given [directory] and returns the stdout (with some lines filtered).
List<String> _runAnalyzer() {
_createConfigurationFiles();
// Run pub get to avoid output from getting dependencies in the analyzer
// output.
Process.runSync(
_flutter,
<String>['pub', 'get'],
workingDirectory: _tempDirectory.absolute.path,
);
final ProcessResult result = Process.runSync(
_flutter,
<String>['--no-wrap', 'analyze', '--no-preamble', '--no-congratulate', '.'],
......@@ -1006,7 +1013,7 @@ class _SnippetChecker {
if (stdout.isNotEmpty && stdout.first == 'Building flutter tool...') {
stdout.removeAt(0);
}
if (stdout.isNotEmpty && stdout.first.startsWith('Running "flutter pub get" in ')) {
if (stdout.isNotEmpty && stdout.first.isEmpty) {
stdout.removeAt(0);
}
return stdout;
......
......@@ -42,11 +42,10 @@ TaskFunction createWebDevModeTest(String webDevice, bool enableIncrementalCompil
recursiveCopy(flutterGalleryDir, _editedFlutterGalleryDir);
await inDirectory<void>(_editedFlutterGalleryDir, () async {
{
final Process packagesGet = await startProcess(
await exec(
path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>['packages', 'get'],
);
await packagesGet.exitCode;
final Process process = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
flutterCommandArgs('run', options),
......
......@@ -192,7 +192,6 @@ class CreateCommand extends CreateBase {
}
validateOutputDirectoryArg();
String? sampleCode;
final String? sampleArgument = stringArg('sample');
if (sampleArgument != null) {
......@@ -255,7 +254,29 @@ class CreateCommand extends CreateBase {
}
final String dartSdk = globals.cache.dartSdkBuild;
final bool includeIos = featureFlags.isIOSEnabled && platforms.contains('ios');
final bool includeIos;
final bool includeAndroid;
final bool includeWeb;
final bool includeLinux;
final bool includeMacos;
final bool includeWindows;
if (template == FlutterProjectType.module) {
// The module template only supports iOS and Android.
includeIos = true;
includeAndroid = true;
includeWeb = false;
includeLinux = false;
includeMacos = false;
includeWindows = false;
} else {
includeIos = featureFlags.isIOSEnabled && platforms.contains('ios');
includeAndroid = featureFlags.isAndroidEnabled && platforms.contains('android');
includeWeb = featureFlags.isWebEnabled && platforms.contains('web');
includeLinux = featureFlags.isLinuxEnabled && platforms.contains('linux');
includeMacos = featureFlags.isMacOSEnabled && platforms.contains('macos');
includeWindows = featureFlags.isWindowsEnabled && platforms.contains('windows');
}
String? developmentTeam;
if (includeIos) {
developmentTeam = await getCodeSigningIdentityDevelopmentTeam(
......@@ -282,11 +303,11 @@ class CreateCommand extends CreateBase {
iosLanguage: stringArgDeprecated('ios-language'),
iosDevelopmentTeam: developmentTeam,
ios: includeIos,
android: featureFlags.isAndroidEnabled && platforms.contains('android'),
web: featureFlags.isWebEnabled && platforms.contains('web'),
linux: featureFlags.isLinuxEnabled && platforms.contains('linux'),
macos: featureFlags.isMacOSEnabled && platforms.contains('macos'),
windows: featureFlags.isWindowsEnabled && platforms.contains('windows'),
android: includeAndroid,
web: includeWeb,
linux: includeLinux,
macos: includeMacos,
windows: includeWindows,
// Enable null safety everywhere.
dartSdkVersionBounds: "'>=$dartSdk <3.0.0'",
implementationTests: boolArgDeprecated('implementation-tests'),
......@@ -309,6 +330,7 @@ class CreateCommand extends CreateBase {
final Directory relativeDir = globals.fs.directory(projectDirPath);
int generatedFileCount = 0;
final PubContext pubContext;
switch (template) {
case FlutterProjectType.app:
generatedFileCount += await generateApp(
......@@ -319,6 +341,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.skeleton:
generatedFileCount += await generateApp(
......@@ -329,6 +352,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
generateMetadata: false,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.module:
generatedFileCount += await _generateModule(
......@@ -337,6 +361,7 @@ class CreateCommand extends CreateBase {
overwrite: overwrite,
printStatusWhenWriting: !creatingNewProject,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.package:
generatedFileCount += await _generatePackage(
......@@ -345,6 +370,7 @@ class CreateCommand extends CreateBase {
overwrite: overwrite,
printStatusWhenWriting: !creatingNewProject,
);
pubContext = PubContext.createPackage;
break;
case FlutterProjectType.plugin:
generatedFileCount += await _generateMethodChannelPlugin(
......@@ -354,6 +380,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.createPlugin;
break;
case FlutterProjectType.ffiPlugin:
generatedFileCount += await _generateFfiPlugin(
......@@ -363,8 +390,26 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.createPlugin;
break;
}
if (boolArgDeprecated('pub')) {
final FlutterProject project = FlutterProject.fromDirectory(relativeDir);
await pub.get(
context: pubContext,
project: project,
offline: boolArgDeprecated('offline'),
);
await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: includeAndroid,
iosPlatform: includeIos,
linuxPlatform: includeLinux,
macOSPlatform: includeMacos,
windowsPlatform: includeWindows,
webPlatform: includeWeb,
);
}
if (sampleCode != null) {
generatedFileCount += _applySample(relativeDir, sampleCode);
}
......@@ -447,18 +492,6 @@ Your $application code is in $relativeAppMain.
overwrite: overwrite,
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.create,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
final FlutterProject project = FlutterProject.fromDirectory(directory);
await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: true,
iosPlatform: true,
);
}
return generatedCount;
}
......@@ -480,13 +513,6 @@ Your $application code is in $relativeAppMain.
overwrite: overwrite,
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPackage,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}
return generatedCount;
}
......@@ -526,14 +552,6 @@ Your $application code is in $relativeAppMain.
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPlugin,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}
final FlutterProject project = FlutterProject.fromDirectory(directory);
final bool generateAndroid = templateContext['android'] == true;
if (generateAndroid) {
......@@ -604,14 +622,6 @@ Your $application code is in $relativeAppMain.
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPlugin,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}
final FlutterProject project = FlutterProject.fromDirectory(directory);
final bool generateAndroid = templateContext['android'] == true;
if (generateAndroid) {
......
......@@ -17,7 +17,6 @@ import '../build_system/build_system.dart';
import '../cache.dart';
import '../convert.dart';
import '../dart/generate_synthetic_packages.dart';
import '../dart/pub.dart';
import '../flutter_project_metadata.dart';
import '../globals.dart' as globals;
import '../project.dart';
......@@ -549,24 +548,6 @@ abstract class CreateBase extends FlutterCommand {
environment: environment,
buildSystem: globals.buildSystem,
);
await pub.get(
context: PubContext.create,
directory: directory.path,
offline: boolArgDeprecated('offline'),
// For templates that use the l10n localization tooling, make sure
// importing the generated package works right after `flutter create`.
generateSyntheticPackage: true,
);
await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: androidPlatform,
iosPlatform: iosPlatform,
linuxPlatform: linuxPlatform,
macOSPlatform: macOSPlatform,
windowsPlatform: windowsPlatform,
webPlatform: webPlatform,
);
}
final List<SupportedPlatform> platformsForMigrateConfig = <SupportedPlatform>[SupportedPlatform.root];
if (androidPlatform) {
......
......@@ -1541,7 +1541,7 @@ class AppRunLogger extends DelegatingLogger {
}
@override
bool get supportsColor => throw UnimplementedError();
bool get supportsColor => false;
@override
bool get hasTerminal => false;
......
......@@ -139,11 +139,10 @@ class PackagesGetCommand extends FlutterCommand {
try {
await pub.get(
context: PubContext.pubGet,
directory: directory,
project: flutterProject,
upgrade: upgrade,
shouldSkipThirdPartyGenerator: false,
offline: boolArgDeprecated('offline'),
generateSyntheticPackage: flutterProject.manifest.generateSyntheticPackage,
);
pubGetTimer.stop();
globals.flutterUsage.sendTiming('pub', 'get', pubGetTimer.elapsed, label: 'success');
......@@ -172,13 +171,14 @@ class PackagesGetCommand extends FlutterCommand {
}
final FlutterProject rootProject = FlutterProject.fromDirectory(globals.fs.directory(target));
// This will also resolve dependencies for the example folder,
await _runPubGet(target, rootProject);
await rootProject.regeneratePlatformSpecificTooling();
// Get/upgrade packages in example app as well
// We need to regenerate the platform specific tooling for both the project
// itself and example (if present).
await rootProject.regeneratePlatformSpecificTooling();
if (rootProject.hasExampleApp && rootProject.example.pubspecFile.existsSync()) {
final FlutterProject exampleProject = rootProject.example;
await _runPubGet(exampleProject.directory.path, exampleProject);
await exampleProject.regeneratePlatformSpecificTooling();
}
......@@ -211,7 +211,7 @@ class PackagesTestCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
await pub.batch(<String>['run', 'test', ...argResults!.rest], context: PubContext.runTest, retry: false);
await pub.batch(<String>['run', 'test', ...argResults!.rest], context: PubContext.runTest);
return FlutterCommandResult.success();
}
}
......
......@@ -16,6 +16,7 @@ import '../base/task_queue.dart';
import '../cache.dart';
import '../dart/pub.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart';
/// Map from package name to package version, used to artificially pin a pub
......@@ -399,7 +400,7 @@ class UpdatePackagesCommand extends FlutterCommand {
// needed packages to the pub cache, upgrading if requested.
await pub.get(
context: PubContext.updatePackages,
directory: tempDir.path,
project: FlutterProject.fromDirectory(tempDir),
upgrade: doUpgrade,
offline: boolArgDeprecated('offline'),
flutterRootOverride: temporaryFlutterSdk?.path,
......@@ -422,7 +423,6 @@ class UpdatePackagesCommand extends FlutterCommand {
context: PubContext.updatePackages,
directory: tempDir.path,
filter: tree.fill,
retry: false, // errors here are usually fatal since we're not hitting the network
);
}
} finally {
......@@ -502,7 +502,7 @@ class UpdatePackagesCommand extends FlutterCommand {
stopwatch.start();
await pub.get(
context: PubContext.updatePackages,
directory: dir.path,
project: FlutterProject.fromDirectory(dir),
// All dependencies should already have been downloaded by the fake
// package, so the concurrent checks can all happen offline.
offline: true,
......
......@@ -12,6 +12,7 @@ import '../cache.dart';
import '../dart/pub.dart';
import '../globals.dart' as globals;
import '../persistent_tool_state.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
import '../version.dart';
import 'channel.dart';
......@@ -330,7 +331,7 @@ class UpgradeCommandRunner {
globals.printStatus('');
await pub.get(
context: PubContext.pubUpgrade,
directory: projectRoot,
project: FlutterProject.fromDirectory(globals.fs.directory(projectRoot)),
upgrade: true,
);
}
......
......@@ -152,6 +152,7 @@ Future<T> runInContext<T>(
logger: globals.logger,
platform: globals.platform,
osUtils: globals.os,
projectFactory: globals.projectFactory,
),
CocoaPods: () => CocoaPods(
fileSystem: globals.fs,
......@@ -312,6 +313,7 @@ Future<T> runInContext<T>(
botDetector: globals.botDetector,
platform: globals.platform,
usage: globals.flutterUsage,
stdio: globals.stdio,
),
Stdio: () => Stdio(),
SystemClock: () => const SystemClock(),
......
......@@ -19,6 +19,7 @@ import 'cache.dart';
import 'dart/package_map.dart';
import 'dart/pub.dart';
import 'globals.dart' as globals;
import 'project.dart';
/// An implementation of the [Cache] which provides all of Flutter's default artifacts.
class FlutterCache extends Cache {
......@@ -29,6 +30,7 @@ class FlutterCache extends Cache {
required super.fileSystem,
required Platform platform,
required super.osUtils,
required FlutterProjectFactory projectFactory,
}) : super(logger: logger, platform: platform, artifacts: <ArtifactSet>[]) {
registerArtifact(MaterialFonts(this));
registerArtifact(GradleWrapper(this));
......@@ -54,6 +56,7 @@ class FlutterCache extends Cache {
// before the version is determined.
flutterRoot: () => Cache.flutterRoot!,
pub: () => pub,
projectFactory: projectFactory,
));
}
}
......@@ -70,14 +73,17 @@ class PubDependencies extends ArtifactSet {
required String Function() flutterRoot,
required Logger logger,
required Pub Function() pub,
required FlutterProjectFactory projectFactory,
}) : _logger = logger,
_flutterRoot = flutterRoot,
_pub = pub,
_projectFactory = projectFactory,
super(DevelopmentArtifact.universal);
final String Function() _flutterRoot;
final Logger _logger;
final Pub Function() _pub;
final FlutterProjectFactory _projectFactory;
@override
Future<bool> isUpToDate(
......@@ -118,7 +124,9 @@ class PubDependencies extends ArtifactSet {
) async {
await _pub().get(
context: PubContext.pubGet,
directory: fileSystem.path.join(_flutterRoot(), 'packages', 'flutter_tools'),
project: _projectFactory.fromDirectory(
fileSystem.directory(fileSystem.path.join(_flutterRoot(), 'packages', 'flutter_tools'))
),
offline: offline
);
}
......
......@@ -1355,7 +1355,7 @@ abstract class FlutterCommand extends Command<void> {
await pub.get(
context: PubContext.getVerifyContext(name),
generateSyntheticPackage: project.manifest.generateSyntheticPackage,
project: project,
checkUpToDate: cachePubGet,
);
await project.regeneratePlatformSpecificTooling();
......
......@@ -17,12 +17,14 @@ import 'package:flutter_tools/src/commands/analyze.dart';
import 'package:flutter_tools/src/dart/analysis.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/project_validator.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
......@@ -36,6 +38,7 @@ void main() {
late ProcessManager processManager;
late AnsiTerminal terminal;
late Logger logger;
late FakeStdio mockStdio;
setUp(() {
fileSystem = globals.localFileSystem;
......@@ -44,6 +47,7 @@ void main() {
terminal = AnsiTerminal(platform: platform, stdio: Stdio());
logger = BufferLogger(outputPreferences: OutputPreferences.test(), terminal: terminal);
tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_analysis_test.');
mockStdio = FakeStdio();
});
tearDown(() {
......@@ -80,10 +84,11 @@ void main() {
platform: const LocalPlatform(),
botDetector: globals.botDetector,
usage: globals.flutterUsage,
stdio: mockStdio,
);
await pub.get(
context: PubContext.flutterTests,
directory: tempDir.path,
project: FlutterProject.fromDirectoryTest(tempDir),
);
final AnalysisServer server = AnalysisServer(
......@@ -119,10 +124,11 @@ void main() {
platform: const LocalPlatform(),
usage: globals.flutterUsage,
botDetector: globals.botDetector,
stdio: mockStdio,
);
await pub.get(
context: PubContext.flutterTests,
directory: tempDir.path,
project: FlutterProject.fromDirectoryTest(tempDir),
);
final AnalysisServer server = AnalysisServer(
......
......@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:test/fake.dart';
import '../../src/context.dart';
......@@ -27,17 +28,18 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext? context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
bool generateSyntheticPackageForExample = false,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true,
}) async {
fs.directory(directory).childFile('.packages').createSync();
project.directory.childFile('.packages').createSync();
if (offline == true) {
calledGetOffline += 1;
} else {
......
......@@ -306,7 +306,7 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext? context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
......
......@@ -169,17 +169,18 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
required PubContext context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
bool generateSyntheticPackageForExample = false,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true,
}) async {
fileSystem.directory(directory)
fileSystem.directory(project.directory)
.childDirectory('.dart_tool')
.childFile('package_config.json')
..createSync(recursive: true)
......
......@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/update_packages.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:test/fake.dart';
import 'package:yaml/yaml.dart';
......@@ -223,20 +224,19 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
required PubContext context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
bool generateSyntheticPackageForExample = false,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true,
}) async {
if (directory != null) {
pubGetDirectories.add(directory);
}
fileSystem.directory(directory).childFile('pubspec.lock')
pubGetDirectories.add(project.directory.path);
project.directory.childFile('pubspec.lock')
..createSync(recursive: true)
..writeAsStringSync('''
# Generated by pub
......@@ -266,8 +266,6 @@ sdks:
String? directory,
MessageFilter? filter,
String failureMessage = 'pub failed',
required bool retry,
bool? showTraceForErrors,
}) async {
if (directory != null) {
pubBatchDirectories.add(directory);
......
......@@ -20,7 +20,7 @@ import '../../src/android_common.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';
import '../../src/fakes.dart' hide FakeFlutterProjectFactory;
import '../../src/test_flutter_command_runner.dart';
void main() {
......
......@@ -64,6 +64,7 @@ void main() {
late LoggingProcessManager loggingProcessManager;
late FakeProcessManager fakeProcessManager;
late BufferLogger logger;
late FakeStdio mockStdio;
setUpAll(() async {
Cache.disableLocking();
......@@ -80,6 +81,7 @@ void main() {
channel: frameworkChannel,
);
fakeProcessManager = FakeProcessManager.empty();
mockStdio = FakeStdio();
});
tearDown(() {
......@@ -171,6 +173,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -218,6 +221,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -244,6 +248,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -273,6 +278,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -298,6 +304,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
...noColorTerminalOverride,
});
......@@ -323,6 +330,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
...noColorTerminalOverride,
});
......@@ -356,6 +364,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -388,6 +397,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -415,6 +425,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -453,6 +464,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -482,6 +494,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -520,6 +533,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -550,6 +564,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -580,6 +595,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
Logger: ()=>logger,
});
......@@ -607,6 +623,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -728,6 +745,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1426,6 +1444,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1454,6 +1473,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1711,6 +1731,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1735,6 +1756,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1885,6 +1907,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -1909,13 +1932,14 @@ void main() {
},
overrides: <Type, Generator>{
ProcessManager: () => loggingProcessManager,
Pub: () => Pub(
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
},
);
......@@ -2869,6 +2893,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......
......@@ -4,21 +4,25 @@
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/format.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
group('format', () {
late Directory tempDir;
late FakeStdio mockStdio;
setUp(() {
Cache.disableLocking();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_format_test.');
mockStdio = FakeStdio();
});
tearDown(() {
......@@ -38,6 +42,8 @@ void main() {
final String formatted = srcFile.readAsStringSync();
expect(formatted, original);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
});
testUsingContext('dry-run', () async {
......
......@@ -30,6 +30,12 @@ import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
late FakeStdio mockStdio;
setUp(() {
mockStdio = FakeStdio()..stdout.terminalColumns = 80;
});
Cache.disableLocking();
group('packages get/upgrade', () {
late Directory tempDir;
......@@ -195,16 +201,25 @@ void main() {
}
}
testUsingContext('get fetches packages', () async {
testUsingContext('get fetches packages and has output from pub', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
removeGeneratedFiles(projectPath);
await runCommandIn(projectPath, 'get');
expect(mockStdio.stdout.writes.map(utf8.decode),
allOf(
contains(matches(RegExp(r'Resolving dependencies in .+flutter_project\.\.\.'))),
contains('+ flutter 0.0.0 from sdk flutter\n'),
contains(matches(RegExp(r'Changed \d+ dependencies in .+flutter_project!'))),
),
);
expectDependenciesResolved(projectPath);
expectZeroPluginsInjected(projectPath);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -212,6 +227,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -225,6 +241,7 @@ void main() {
expectDependenciesResolved(projectPath);
expectZeroPluginsInjected(projectPath);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -232,6 +249,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -245,6 +263,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesNumberPlugins, 0);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -252,6 +271,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -267,6 +287,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesNumberPlugins, 1);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -274,6 +295,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -287,6 +309,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesProjectModule, false);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -294,6 +317,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -307,6 +331,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesProjectModule, true);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -314,6 +339,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -336,6 +362,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesAndroidEmbeddingVersion, 'v1');
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -343,6 +370,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -356,6 +384,7 @@ void main() {
expect((await getCommand.usageValues).commandPackagesAndroidEmbeddingVersion, 'v2');
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -363,6 +392,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -376,7 +406,7 @@ void main() {
expectDependenciesResolved(projectPath);
expectZeroPluginsInjected(projectPath);
}, overrides: <Type, Generator>{
Stdio: () => FakeStdio()..stdout.terminalColumns = 80,
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -384,6 +414,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -397,6 +428,7 @@ void main() {
expectDependenciesResolved(projectPath);
expectModulePluginInjected(projectPath);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -404,6 +436,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -425,6 +458,7 @@ void main() {
expectDependenciesResolved(exampleProjectPath);
expectPluginInjected(exampleProjectPath);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
......@@ -432,6 +466,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
});
......@@ -468,6 +503,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -493,6 +529,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -523,6 +560,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -553,6 +591,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
......@@ -581,6 +620,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: mockStdio,
),
});
});
......
......@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/flutter_cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:test/fake.dart';
import '../src/common.dart';
......@@ -908,6 +909,7 @@ void main() {
flutterRoot: () => '',
logger: logger,
pub: () => FakePub(),
projectFactory: FakeFlutterProjectFactory(),
);
expect(await pubDependencies.isUpToDate(fileSystem), false); // no package config
......@@ -950,6 +952,7 @@ void main() {
flutterRoot: () => '',
logger: logger,
pub: () => pub,
projectFactory: FakeFlutterProjectFactory()
);
await pubDependencies.update(FakeArtifactUpdater(), logger, fileSystem, FakeOperatingSystemUtils());
......@@ -1155,7 +1158,7 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext? context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
......
......@@ -20,6 +20,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/pre_run_validator.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:test/fake.dart';
......@@ -814,11 +815,12 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext context,
String directory,
FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
bool generateSyntheticPackageForExample = false,
String flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
......
......@@ -75,6 +75,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: globals.stdio,
),
});
......@@ -122,6 +123,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: globals.stdio,
),
});
......@@ -153,6 +155,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: globals.stdio,
),
});
......@@ -183,6 +186,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: globals.stdio,
),
});
......@@ -232,6 +236,7 @@ void main() {
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
stdio: globals.stdio,
),
});
}
......
......@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:test/fake.dart';
......@@ -561,3 +562,13 @@ class FakeStopwatchFactory implements StopwatchFactory {
return stopwatches[name] ?? FakeStopwatch();
}
}
class FakeFlutterProjectFactory implements FlutterProjectFactory {
@override
FlutterProject fromDirectory(Directory directory) {
return FlutterProject.fromDirectoryTest(directory);
}
@override
Map<String, FlutterProject> get projects => throw UnimplementedError();
}
......@@ -35,7 +35,7 @@ Future<String> createProject(Directory temp, { List<String>? arguments }) async
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', ...arguments, projectPath]);
// Created `.packages` since it's not created when the flag `--no-pub` is passed.
// Create `.packages` since it's not created when the flag `--no-pub` is passed.
globals.fs.file(globals.fs.path.join(projectPath, '.packages')).createSync();
return projectPath;
}
......
......@@ -4,6 +4,7 @@
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/project.dart';
class ThrowingPub implements Pub {
@override
......@@ -12,8 +13,6 @@ class ThrowingPub implements Pub {
String? directory,
MessageFilter? filter,
String? failureMessage = 'pub failed',
bool? retry,
bool? showTraceForErrors,
}) {
throw UnsupportedError('Attempted to invoke pub during test.');
}
......@@ -21,13 +20,14 @@ class ThrowingPub implements Pub {
@override
Future<void> get({
PubContext? context,
String? directory,
required FlutterProject project,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool checkLastModified = true,
bool skipPubspecYamlCheck = false,
bool generateSyntheticPackage = false,
bool generateSyntheticPackageForExample = false,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment