Add pre-stable support for create on Windows (#51895)
Adds initial support for flutter create of apps and plugins. This is derived from the current FDE example app and sample plugin, adding template values where relevant. Since the APIs/tooling/template aren't stable yet, the app template includes a version marker, which will be updated each time there's a breaking change. The build now checks that the template version matches the version known by that version of the tool, and gives a specific error message when there's a mismatch, which improves over the current breaking change experience of hitting whatever build failure the breaking change causes and having to figure out that the problem is that the runner is out of date. It also adds a warning to the create output about the fact that it won't be stable. Plugins don't currently have a version marker since in practice this is not a significant problem for plugins yet the way it is for runners; we can add it later if that changes. Fixes #30704
This commit is contained in:
@@ -15,13 +15,13 @@ import 'package:flutter_tools/src/windows/visual_studio.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:xml/xml.dart' as xml;
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
const String flutterRoot = r'C:\flutter';
|
||||
const String solutionPath = r'C:\windows\Runner.sln';
|
||||
const String visualStudioPath = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community';
|
||||
const String vcvarsPath = visualStudioPath + r'\VC\Auxiliary\Build\vcvars64.bat';
|
||||
@@ -30,17 +30,19 @@ final Platform windowsPlatform = FakePlatform(
|
||||
operatingSystem: 'windows',
|
||||
environment: <String, String>{
|
||||
'PROGRAMFILES(X86)': r'C:\Program Files (x86)\',
|
||||
'FLUTTER_ROOT': r'C:\',
|
||||
'FLUTTER_ROOT': flutterRoot,
|
||||
}
|
||||
);
|
||||
final Platform notWindowsPlatform = FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{
|
||||
'FLUTTER_ROOT': r'C:\',
|
||||
'FLUTTER_ROOT': flutterRoot,
|
||||
}
|
||||
);
|
||||
|
||||
void main() {
|
||||
FileSystem fileSystem;
|
||||
|
||||
MockProcessManager mockProcessManager;
|
||||
MockProcess mockProcess;
|
||||
MockVisualStudio mockVisualStudio;
|
||||
@@ -50,6 +52,8 @@ void main() {
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
|
||||
Cache.flutterRoot = flutterRoot;
|
||||
mockProcessManager = MockProcessManager();
|
||||
mockProcess = MockProcess();
|
||||
mockVisualStudio = MockVisualStudio();
|
||||
@@ -66,15 +70,35 @@ void main() {
|
||||
|
||||
// Creates the mock files necessary to look like a Flutter project.
|
||||
void setUpMockCoreProjectFiles() {
|
||||
globals.fs.file('pubspec.yaml').createSync();
|
||||
globals.fs.file('.packages').createSync();
|
||||
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('.packages').createSync();
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
// Creates the mock files necessary to run a build.
|
||||
void setUpMockProjectFilesForBuild() {
|
||||
globals.fs.file(solutionPath).createSync(recursive: true);
|
||||
void setUpMockProjectFilesForBuild({int templateVersion}) {
|
||||
fileSystem.file(solutionPath).createSync(recursive: true);
|
||||
setUpMockCoreProjectFiles();
|
||||
|
||||
final String versionFileSubpath = fileSystem.path.join('flutter', '.template_version');
|
||||
const int expectedTemplateVersion = 10; // Arbitrary value for tests.
|
||||
final File sourceTemplateVersionfile = fileSystem.file(fileSystem.path.join(
|
||||
fileSystem.path.absolute(Cache.flutterRoot),
|
||||
'packages',
|
||||
'flutter_tools',
|
||||
'templates',
|
||||
'app',
|
||||
'windows.tmpl',
|
||||
versionFileSubpath,
|
||||
));
|
||||
sourceTemplateVersionfile.createSync(recursive: true);
|
||||
sourceTemplateVersionfile.writeAsStringSync(expectedTemplateVersion.toString());
|
||||
|
||||
final File projectTemplateVersionFile = fileSystem.file(
|
||||
fileSystem.path.join('windows', versionFileSubpath));
|
||||
templateVersion ??= expectedTemplateVersion;
|
||||
projectTemplateVersionFile.createSync(recursive: true);
|
||||
projectTemplateVersionFile.writeAsStringSync(templateVersion.toString());
|
||||
}
|
||||
|
||||
testUsingContext('Windows build fails when there is no vcvars64.bat', () async {
|
||||
@@ -88,7 +112,7 @@ void main() {
|
||||
), throwsToolExit());
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => windowsPlatform,
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
@@ -105,7 +129,7 @@ void main() {
|
||||
), throwsToolExit(message: 'No Windows desktop project configured'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => windowsPlatform,
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
@@ -122,11 +146,43 @@ void main() {
|
||||
), throwsToolExit());
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => notWindowsPlatform,
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('Windows build fails with instructions when template is too old', () async {
|
||||
final BuildWindowsCommand command = BuildWindowsCommand()
|
||||
..visualStudioOverride = mockVisualStudio;
|
||||
applyMocksToCommand(command);
|
||||
setUpMockProjectFilesForBuild(templateVersion: 1);
|
||||
|
||||
expect(createTestCommandRunner(command).run(
|
||||
const <String>['windows']
|
||||
), throwsToolExit(message: 'flutter create .'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => windowsPlatform,
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('Windows build fails with instructions when template is too new', () async {
|
||||
final BuildWindowsCommand command = BuildWindowsCommand()
|
||||
..visualStudioOverride = mockVisualStudio;
|
||||
applyMocksToCommand(command);
|
||||
setUpMockProjectFilesForBuild(templateVersion: 999);
|
||||
|
||||
expect(createTestCommandRunner(command).run(
|
||||
const <String>['windows']
|
||||
), throwsToolExit(message: 'Upgrade Flutter'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => windowsPlatform,
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('Windows build does not spew stdout to status logger', () async {
|
||||
final BuildWindowsCommand command = BuildWindowsCommand()
|
||||
..visualStudioOverride = mockVisualStudio;
|
||||
@@ -135,11 +191,11 @@ void main() {
|
||||
when(mockVisualStudio.vcvarsPath).thenReturn(vcvarsPath);
|
||||
|
||||
when(mockProcessManager.start(<String>[
|
||||
r'C:\packages\flutter_tools\bin\vs_build.bat',
|
||||
fileSystem.path.join(flutterRoot, 'packages', 'flutter_tools', 'bin', 'vs_build.bat'),
|
||||
vcvarsPath,
|
||||
globals.fs.path.basename(solutionPath),
|
||||
fileSystem.path.basename(solutionPath),
|
||||
'Release',
|
||||
], workingDirectory: globals.fs.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
], workingDirectory: fileSystem.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
return mockProcess;
|
||||
});
|
||||
|
||||
@@ -149,7 +205,7 @@ void main() {
|
||||
expect(testLogger.statusText, isNot(contains('STDOUT STUFF')));
|
||||
expect(testLogger.traceText, contains('STDOUT STUFF'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => windowsPlatform,
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
@@ -163,11 +219,11 @@ void main() {
|
||||
when(mockVisualStudio.vcvarsPath).thenReturn(vcvarsPath);
|
||||
|
||||
when(mockProcessManager.start(<String>[
|
||||
r'C:\packages\flutter_tools\bin\vs_build.bat',
|
||||
fileSystem.path.join(flutterRoot, 'packages', 'flutter_tools', 'bin', 'vs_build.bat'),
|
||||
vcvarsPath,
|
||||
globals.fs.path.basename(solutionPath),
|
||||
fileSystem.path.basename(solutionPath),
|
||||
'Release',
|
||||
], workingDirectory: globals.fs.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
], workingDirectory: fileSystem.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
return mockProcess;
|
||||
});
|
||||
|
||||
@@ -176,14 +232,14 @@ void main() {
|
||||
);
|
||||
|
||||
// Spot-check important elements from the properties file.
|
||||
final File propsFile = globals.fs.file(r'C:\windows\flutter\ephemeral\Generated.props');
|
||||
final File propsFile = fileSystem.file(r'C:\windows\flutter\ephemeral\Generated.props');
|
||||
expect(propsFile.existsSync(), true);
|
||||
final xml.XmlDocument props = xml.parse(propsFile.readAsStringSync());
|
||||
expect(props.findAllElements('PropertyGroup').first.getAttribute('Label'), 'UserMacros');
|
||||
expect(props.findAllElements('ItemGroup').length, 1);
|
||||
expect(props.findAllElements('FLUTTER_ROOT').first.text, r'C:\');
|
||||
expect(props.findAllElements('FLUTTER_ROOT').first.text, flutterRoot);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => windowsPlatform,
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
@@ -197,11 +253,11 @@ void main() {
|
||||
when(mockVisualStudio.vcvarsPath).thenReturn(vcvarsPath);
|
||||
|
||||
when(mockProcessManager.start(<String>[
|
||||
r'C:\packages\flutter_tools\bin\vs_build.bat',
|
||||
fileSystem.path.join(flutterRoot, 'packages', 'flutter_tools', 'bin', 'vs_build.bat'),
|
||||
vcvarsPath,
|
||||
globals.fs.path.basename(solutionPath),
|
||||
fileSystem.path.basename(solutionPath),
|
||||
'Release',
|
||||
], workingDirectory: globals.fs.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
], workingDirectory: fileSystem.path.dirname(solutionPath))).thenAnswer((Invocation invocation) async {
|
||||
return mockProcess;
|
||||
});
|
||||
|
||||
@@ -211,7 +267,7 @@ void main() {
|
||||
|
||||
expect(testLogger.statusText, contains('🚧'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => windowsPlatform,
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/create.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
@@ -23,6 +24,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
testbed = Testbed(setup: () {
|
||||
Cache.flutterRoot = 'flutter';
|
||||
final List<String> paths = <String>[
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter', 'pubspec.yaml'),
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_driver', 'pubspec.yaml'),
|
||||
@@ -34,6 +36,13 @@ void main() {
|
||||
for (final String path in paths) {
|
||||
globals.fs.file(path).createSync(recursive: true);
|
||||
}
|
||||
// Set up enough of the packages to satisfy the templating code.
|
||||
final File packagesFile = globals.fs.file(
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_tools', '.packages'));
|
||||
final Directory templateImagesDirectory = globals.fs.directory('flutter_template_images');
|
||||
templateImagesDirectory.createSync(recursive: true);
|
||||
packagesFile.createSync(recursive: true);
|
||||
packagesFile.writeAsStringSync('flutter_template_images:file:///${templateImagesDirectory.uri}');
|
||||
}, overrides: <Type, Generator>{
|
||||
DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider(),
|
||||
});
|
||||
|
||||
@@ -631,6 +631,66 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('app supports Windows if requested', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', projectDir.path]);
|
||||
|
||||
expect(projectDir.childDirectory('windows').childFile('Runner.sln').existsSync(), true);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('app does not include Windows by default', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', projectDir.path]);
|
||||
|
||||
expect(projectDir.childDirectory('windows').childFile('Runner.sln').existsSync(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('plugin supports Windows if requested', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
|
||||
expect(projectDir.childDirectory('windows').childFile('plugin.vcxproj').existsSync(), true);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('plugin does not include Windows by default', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
|
||||
expect(projectDir.childDirectory('windows').childFile('plugin.vcxproj').existsSync(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('plugin uses new platform schema', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
|
||||
@@ -261,7 +261,7 @@ void main() {
|
||||
'foo': Uri.parse('file:///foo/lib/'),
|
||||
'bar': Uri.parse('file:///bar/lib/'),
|
||||
'fizz': Uri.parse('file:///fizz/lib/'),
|
||||
});
|
||||
}, fileSystem: fileSystem);
|
||||
|
||||
final LicenseResult result = licenseCollector.obtainLicenses(packageMap);
|
||||
|
||||
|
||||
@@ -636,6 +636,15 @@ void testInMemory(String description, Future<void> testMethod()) {
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childDirectory('schema'), testFileSystem);
|
||||
// Set up enough of the packages to satisfy the templating code.
|
||||
final File packagesFile = testFileSystem.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childFile('.packages');
|
||||
final Directory dummyTemplateImagesDirectory = testFileSystem.directory(Cache.flutterRoot).parent;
|
||||
dummyTemplateImagesDirectory.createSync(recursive: true);
|
||||
packagesFile.createSync(recursive: true);
|
||||
packagesFile.writeAsStringSync('flutter_template_images:${dummyTemplateImagesDirectory.uri}');
|
||||
|
||||
final FlutterProjectFactory flutterProjectFactory = FlutterProjectFactory();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class ThrowingPub implements Pub {
|
||||
bool retry,
|
||||
bool showTraceForErrors,
|
||||
}) {
|
||||
throw UnsupportedError('Attempted to inovke pub during test.');
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -29,11 +29,11 @@ class ThrowingPub implements Pub {
|
||||
bool checkLastModified = true,
|
||||
bool skipPubspecYamlCheck = false,
|
||||
}) {
|
||||
throw UnsupportedError('Attempted to inovke pub during test.');
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> interactively(List<String> arguments, {String directory}) {
|
||||
throw UnsupportedError('Attempted to inovke pub during test.');
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/template.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -18,13 +20,69 @@ void main() {
|
||||
});
|
||||
|
||||
test('Template.render throws ToolExit when FileSystem exception is raised', () => testbed.run(() {
|
||||
final Template template = Template(globals.fs.directory('examples'), globals.fs.currentDirectory);
|
||||
final Template template = Template(globals.fs.directory('examples'), globals.fs.currentDirectory, null, fileSystem: globals.fs);
|
||||
final MockDirectory mockDirectory = MockDirectory();
|
||||
when(mockDirectory.createSync(recursive: true)).thenThrow(const FileSystemException());
|
||||
|
||||
expect(() => template.render(mockDirectory, <String, Object>{}),
|
||||
throwsToolExit());
|
||||
}));
|
||||
|
||||
test('Template.render replaces .img.tmpl files with files from the image source', () => testbed.run(() {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem();
|
||||
final Directory templateDir = fileSystem.directory('templates');
|
||||
final Directory imageSourceDir = fileSystem.directory('template_images');
|
||||
final Directory destination = fileSystem.directory('target');
|
||||
const String imageName = 'some_image.png';
|
||||
templateDir.childFile('$imageName.img.tmpl').createSync(recursive: true);
|
||||
final File sourceImage = imageSourceDir.childFile(imageName);
|
||||
sourceImage.createSync(recursive: true);
|
||||
sourceImage.writeAsStringSync('Ceci n\'est pas une pipe');
|
||||
|
||||
final Template template = Template(templateDir, templateDir, imageSourceDir, fileSystem: fileSystem);
|
||||
template.render(destination, <String, Object>{});
|
||||
|
||||
final File destinationImage = destination.childFile(imageName);
|
||||
expect(destinationImage.existsSync(), true);
|
||||
expect(destinationImage.readAsBytesSync(), equals(sourceImage.readAsBytesSync()));
|
||||
}));
|
||||
|
||||
test('Template.fromName runs pub get if .packages is missing', () => testbed.run(() async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem();
|
||||
|
||||
// Attempting to run pub in a test throws.
|
||||
await expectLater(Template.fromName('app', fileSystem: fileSystem),
|
||||
throwsUnsupportedError);
|
||||
}));
|
||||
|
||||
test('Template.fromName runs pub get if .packages is missing flutter_template_images', () => testbed.run(() async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem();
|
||||
Cache.flutterRoot = '/flutter';
|
||||
final File packagesFile = fileSystem.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childFile('.packages');
|
||||
packagesFile.createSync(recursive: true);
|
||||
|
||||
// Attempting to run pub in a test throws.
|
||||
await expectLater(Template.fromName('app', fileSystem: fileSystem),
|
||||
throwsUnsupportedError);
|
||||
}));
|
||||
|
||||
test('Template.fromName runs pub get if flutter_template_images directory is missing', () => testbed.run(() async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem();
|
||||
Cache.flutterRoot = '/flutter';
|
||||
final File packagesFile = fileSystem.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childFile('.packages');
|
||||
packagesFile.createSync(recursive: true);
|
||||
packagesFile.writeAsStringSync('flutter_template_images:file:///flutter_template_images');
|
||||
|
||||
// Attempting to run pub in a test throws.
|
||||
await expectLater(Template.fromName('app', fileSystem: fileSystem),
|
||||
throwsUnsupportedError);
|
||||
}));
|
||||
}
|
||||
|
||||
class MockDirectory extends Mock implements Directory {}
|
||||
|
||||
Reference in New Issue
Block a user