Skip to content

Commit

Permalink
[flutter_tools] last pass on general.shard unit tests (flutter#60263)
Browse files Browse the repository at this point in the history
Last batch of test fixes for general shard.
  • Loading branch information
jonahwilliams authored Jun 26, 2020
1 parent 7518a14 commit e1538d1
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 175 deletions.
12 changes: 9 additions & 3 deletions packages/flutter_tools/lib/src/dart/package_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:typed_data';

import 'package:meta/meta.dart';
Expand Down Expand Up @@ -32,9 +33,10 @@ String _globalPackagesPath;
Future<PackageConfig> loadPackageConfigWithLogging(File file, {
@required Logger logger,
bool throwOnError = true,
}) {
}) async {
final FileSystem fileSystem = file.fileSystem;
return loadPackageConfigUri(
bool didError = false;
final PackageConfig result = await loadPackageConfigUri(
file.absolute.uri,
loader: (Uri uri) {
final File configFile = fileSystem.file(uri);
Expand All @@ -56,7 +58,11 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, {
message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
}
logger.printError(message);
throwToolExit(file.path);
didError = true;
}
);
if (didError) {
throwToolExit(null);
}
return result;
}
4 changes: 1 addition & 3 deletions packages/flutter_tools/lib/src/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ FileSystem get fs => ErrorHandlingFileSystem(
platform: platform,
);

final FileSystemUtils _defaultFileSystemUtils = FileSystemUtils(
FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? FileSystemUtils(
fileSystem: fs,
platform: platform,
);

FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? _defaultFileSystemUtils;

const ProcessManager _kLocalProcessManager = LocalProcessManager();

/// The active process manager.
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter_tools/lib/src/run_hot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import 'reporting/reporting.dart';
import 'resident_runner.dart';
import 'vmservice.dart';

ProjectFileInvalidator get projectFileInvalidator => context.get<ProjectFileInvalidator>() ?? _defaultInvalidator;
final ProjectFileInvalidator _defaultInvalidator = ProjectFileInvalidator(
ProjectFileInvalidator get projectFileInvalidator => context.get<ProjectFileInvalidator>() ?? ProjectFileInvalidator(
fileSystem: globals.fs,
platform: globals.platform,
logger: globals.logger,
Expand Down
9 changes: 9 additions & 0 deletions packages/flutter_tools/test/general.shard/base/logs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/logs.dart';

import '../../src/common.dart';
Expand All @@ -11,6 +12,14 @@ import '../../src/mocks.dart';

void main() {
group('logs', () {
setUp(() {
Cache.disableLocking();
});

tearDown(() {
Cache.enableLocking();
});

testUsingContext('fail with a bad device id', () async {
final LogsCommand command = LogsCommand();
applyMocksToCommand(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/assets.dart';
import 'package:flutter_tools/src/build_system/targets/common.dart';
import 'package:flutter_tools/src/build_system/targets/macos.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/macos/xcode.dart';
Expand All @@ -26,38 +25,33 @@ import '../../../src/testbed.dart';
const String _kInputPrefix = 'bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework';
const String _kOutputPrefix = 'FlutterMacOS.framework';

final List<File> inputs = <File>[
globals.fs.file('$_kInputPrefix/FlutterMacOS'),
final List<String> inputs = <String>[
'$_kInputPrefix/FlutterMacOS',
// Headers
globals.fs.file('$_kInputPrefix/Headers/FlutterDartProject.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterEngine.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterViewController.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterBinaryMessenger.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterChannels.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterCodecs.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterMacros.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterPluginMacOS.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterPluginRegistrarMacOS.h'),
globals.fs.file('$_kInputPrefix/Headers/FlutterMacOS.h'),
'$_kInputPrefix/Headers/FlutterDartProject.h',
'$_kInputPrefix/Headers/FlutterEngine.h',
'$_kInputPrefix/Headers/FlutterViewController.h',
'$_kInputPrefix/Headers/FlutterBinaryMessenger.h',
'$_kInputPrefix/Headers/FlutterChannels.h',
'$_kInputPrefix/Headers/FlutterCodecs.h',
'$_kInputPrefix/Headers/FlutterMacros.h',
'$_kInputPrefix/Headers/FlutterPluginMacOS.h',
'$_kInputPrefix/Headers/FlutterPluginRegistrarMacOS.h',
'$_kInputPrefix/Headers/FlutterMacOS.h',
// Modules
globals.fs.file('$_kInputPrefix/Modules/module.modulemap'),
'$_kInputPrefix/Modules/module.modulemap',
// Resources
globals.fs.file('$_kInputPrefix/Resources/icudtl.dat'),
globals.fs.file('$_kInputPrefix/Resources/Info.plist'),
'$_kInputPrefix/Resources/icudtl.dat',
'$_kInputPrefix/Resources/Info.plist',
// Ignore Versions folder for now
globals.fs.file('packages/flutter_tools/lib/src/build_system/targets/macos.dart'),
'packages/flutter_tools/lib/src/build_system/targets/macos.dart',
];

void main() {
Testbed testbed;
Environment environment;
Platform platform;

setUpAll(() {
Cache.disableLocking();
Cache.flutterRoot = '';
});

setUp(() {
platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
testbed = Testbed(setup: () {
Expand All @@ -82,8 +76,8 @@ void main() {
});

test('Copies files to correct cache directory', () => testbed.run(() async {
for (final File input in inputs) {
input.createSync(recursive: true);
for (final String input in inputs) {
globals.fs.file(input).createSync(recursive: true);
}
// Create output directory so we can test that it is deleted.
environment.outputDir.childDirectory(_kOutputPrefix)
Expand Down Expand Up @@ -111,8 +105,8 @@ void main() {
await const DebugUnpackMacOS().build(environment);

expect(globals.fs.directory(_kOutputPrefix).existsSync(), true);
for (final File file in inputs) {
expect(globals.fs.file(file.path.replaceFirst(_kInputPrefix, _kOutputPrefix)), exists);
for (final String path in inputs) {
expect(globals.fs.file(path.replaceFirst(_kInputPrefix, _kOutputPrefix)), exists);
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});

testWithoutContext('uses timeout', () async {
Expand Down Expand Up @@ -596,6 +597,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});

testUsingContext('handles unknown architectures', () async {
Expand Down Expand Up @@ -644,6 +646,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});
});

Expand Down
Loading

0 comments on commit e1538d1

Please sign in to comment.