Unverified Commit e1538d1b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] last pass on general.shard unit tests (#60263)

Last batch of test fixes for general shard.
parent 7518a146
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -32,9 +33,10 @@ String _globalPackagesPath; ...@@ -32,9 +33,10 @@ String _globalPackagesPath;
Future<PackageConfig> loadPackageConfigWithLogging(File file, { Future<PackageConfig> loadPackageConfigWithLogging(File file, {
@required Logger logger, @required Logger logger,
bool throwOnError = true, bool throwOnError = true,
}) { }) async {
final FileSystem fileSystem = file.fileSystem; final FileSystem fileSystem = file.fileSystem;
return loadPackageConfigUri( bool didError = false;
final PackageConfig result = await loadPackageConfigUri(
file.absolute.uri, file.absolute.uri,
loader: (Uri uri) { loader: (Uri uri) {
final File configFile = fileSystem.file(uri); final File configFile = fileSystem.file(uri);
...@@ -56,7 +58,11 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, { ...@@ -56,7 +58,11 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, {
message += '\nDid you run this command from the same directory as your pubspec.yaml file?'; message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
} }
logger.printError(message); logger.printError(message);
throwToolExit(file.path); didError = true;
} }
); );
if (didError) {
throwToolExit(null);
}
return result;
} }
...@@ -66,13 +66,11 @@ FileSystem get fs => ErrorHandlingFileSystem( ...@@ -66,13 +66,11 @@ FileSystem get fs => ErrorHandlingFileSystem(
platform: platform, platform: platform,
); );
final FileSystemUtils _defaultFileSystemUtils = FileSystemUtils( FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? FileSystemUtils(
fileSystem: fs, fileSystem: fs,
platform: platform, platform: platform,
); );
FileSystemUtils get fsUtils => context.get<FileSystemUtils>() ?? _defaultFileSystemUtils;
const ProcessManager _kLocalProcessManager = LocalProcessManager(); const ProcessManager _kLocalProcessManager = LocalProcessManager();
/// The active process manager. /// The active process manager.
......
...@@ -26,8 +26,7 @@ import 'reporting/reporting.dart'; ...@@ -26,8 +26,7 @@ import 'reporting/reporting.dart';
import 'resident_runner.dart'; import 'resident_runner.dart';
import 'vmservice.dart'; import 'vmservice.dart';
ProjectFileInvalidator get projectFileInvalidator => context.get<ProjectFileInvalidator>() ?? _defaultInvalidator; ProjectFileInvalidator get projectFileInvalidator => context.get<ProjectFileInvalidator>() ?? ProjectFileInvalidator(
final ProjectFileInvalidator _defaultInvalidator = ProjectFileInvalidator(
fileSystem: globals.fs, fileSystem: globals.fs,
platform: globals.platform, platform: globals.platform,
logger: globals.logger, logger: globals.logger,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/logs.dart'; import 'package:flutter_tools/src/commands/logs.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -11,6 +12,14 @@ import '../../src/mocks.dart'; ...@@ -11,6 +12,14 @@ import '../../src/mocks.dart';
void main() { void main() {
group('logs', () { group('logs', () {
setUp(() {
Cache.disableLocking();
});
tearDown(() {
Cache.enableLocking();
});
testUsingContext('fail with a bad device id', () async { testUsingContext('fail with a bad device id', () async {
final LogsCommand command = LogsCommand(); final LogsCommand command = LogsCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
......
...@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/build_system/build_system.dart'; ...@@ -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/assets.dart';
import 'package:flutter_tools/src/build_system/targets/common.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/build_system/targets/macos.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/macos/xcode.dart'; import 'package:flutter_tools/src/macos/xcode.dart';
...@@ -26,26 +25,26 @@ import '../../../src/testbed.dart'; ...@@ -26,26 +25,26 @@ import '../../../src/testbed.dart';
const String _kInputPrefix = 'bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework'; const String _kInputPrefix = 'bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework';
const String _kOutputPrefix = 'FlutterMacOS.framework'; const String _kOutputPrefix = 'FlutterMacOS.framework';
final List<File> inputs = <File>[ final List<String> inputs = <String>[
globals.fs.file('$_kInputPrefix/FlutterMacOS'), '$_kInputPrefix/FlutterMacOS',
// Headers // Headers
globals.fs.file('$_kInputPrefix/Headers/FlutterDartProject.h'), '$_kInputPrefix/Headers/FlutterDartProject.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterEngine.h'), '$_kInputPrefix/Headers/FlutterEngine.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterViewController.h'), '$_kInputPrefix/Headers/FlutterViewController.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterBinaryMessenger.h'), '$_kInputPrefix/Headers/FlutterBinaryMessenger.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterChannels.h'), '$_kInputPrefix/Headers/FlutterChannels.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterCodecs.h'), '$_kInputPrefix/Headers/FlutterCodecs.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterMacros.h'), '$_kInputPrefix/Headers/FlutterMacros.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterPluginMacOS.h'), '$_kInputPrefix/Headers/FlutterPluginMacOS.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterPluginRegistrarMacOS.h'), '$_kInputPrefix/Headers/FlutterPluginRegistrarMacOS.h',
globals.fs.file('$_kInputPrefix/Headers/FlutterMacOS.h'), '$_kInputPrefix/Headers/FlutterMacOS.h',
// Modules // Modules
globals.fs.file('$_kInputPrefix/Modules/module.modulemap'), '$_kInputPrefix/Modules/module.modulemap',
// Resources // Resources
globals.fs.file('$_kInputPrefix/Resources/icudtl.dat'), '$_kInputPrefix/Resources/icudtl.dat',
globals.fs.file('$_kInputPrefix/Resources/Info.plist'), '$_kInputPrefix/Resources/Info.plist',
// Ignore Versions folder for now // 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() { void main() {
...@@ -53,11 +52,6 @@ void main() { ...@@ -53,11 +52,6 @@ void main() {
Environment environment; Environment environment;
Platform platform; Platform platform;
setUpAll(() {
Cache.disableLocking();
Cache.flutterRoot = '';
});
setUp(() { setUp(() {
platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{}); platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
testbed = Testbed(setup: () { testbed = Testbed(setup: () {
...@@ -82,8 +76,8 @@ void main() { ...@@ -82,8 +76,8 @@ void main() {
}); });
test('Copies files to correct cache directory', () => testbed.run(() async { test('Copies files to correct cache directory', () => testbed.run(() async {
for (final File input in inputs) { for (final String input in inputs) {
input.createSync(recursive: true); globals.fs.file(input).createSync(recursive: true);
} }
// Create output directory so we can test that it is deleted. // Create output directory so we can test that it is deleted.
environment.outputDir.childDirectory(_kOutputPrefix) environment.outputDir.childDirectory(_kOutputPrefix)
...@@ -111,8 +105,8 @@ void main() { ...@@ -111,8 +105,8 @@ void main() {
await const DebugUnpackMacOS().build(environment); await const DebugUnpackMacOS().build(environment);
expect(globals.fs.directory(_kOutputPrefix).existsSync(), true); expect(globals.fs.directory(_kOutputPrefix).existsSync(), true);
for (final File file in inputs) { for (final String path in inputs) {
expect(globals.fs.file(file.path.replaceFirst(_kInputPrefix, _kOutputPrefix)), exists); expect(globals.fs.file(path.replaceFirst(_kInputPrefix, _kOutputPrefix)), exists);
} }
})); }));
......
...@@ -538,6 +538,7 @@ void main() { ...@@ -538,6 +538,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse); expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => macPlatform, Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
}); });
testWithoutContext('uses timeout', () async { testWithoutContext('uses timeout', () async {
...@@ -596,6 +597,7 @@ void main() { ...@@ -596,6 +597,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse); expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => macPlatform, Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
}); });
testUsingContext('handles unknown architectures', () async { testUsingContext('handles unknown architectures', () async {
...@@ -644,6 +646,7 @@ void main() { ...@@ -644,6 +646,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse); expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => macPlatform, Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
}); });
}); });
......
...@@ -31,6 +31,7 @@ void main() { ...@@ -31,6 +31,7 @@ void main() {
List<int> mockTimes; List<int> mockTimes;
setUp(() { setUp(() {
Cache.disableLocking();
cache = MockitoCache(); cache = MockitoCache();
usage = MockitoUsage(); usage = MockitoUsage();
clock = MockClock(); clock = MockClock();
...@@ -43,6 +44,10 @@ void main() { ...@@ -43,6 +44,10 @@ void main() {
when(mockProcessInfo.maxRss).thenReturn(10); when(mockProcessInfo.maxRss).thenReturn(10);
}); });
tearDown(() {
Cache.enableLocking();
});
testUsingContext('help text contains global options', () { testUsingContext('help text contains global options', () {
final FakeDeprecatedCommand fake = FakeDeprecatedCommand(); final FakeDeprecatedCommand fake = FakeDeprecatedCommand();
createTestCommandRunner(fake); createTestCommandRunner(fake);
......
...@@ -40,7 +40,6 @@ void main() { ...@@ -40,7 +40,6 @@ void main() {
testbed = Testbed(overrides: <Type, Generator>{ testbed = Testbed(overrides: <Type, Generator>{
ProcessManager: () { ProcessManager: () {
print('in get process manager');
return mockProcessManager; return mockProcessManager;
} }
}); });
......
...@@ -13,8 +13,8 @@ import 'package:flutter_tools/src/base/terminal.dart'; ...@@ -13,8 +13,8 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/ios/plist_parser.dart'; import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../../src/common.dart'; import '../src/common.dart';
import '../../src/context.dart'; import '../src/context.dart';
const String base64PlistXml = const String base64PlistXml =
'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHBsaXN0I' 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHBsaXN0I'
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:io' as io;
import 'package:flutter_tools/src/android/android_workflow.dart'; import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/bot_detector.dart'; import 'package:flutter_tools/src/base/bot_detector.dart';
...@@ -158,8 +157,8 @@ void testUsingContext( ...@@ -158,8 +157,8 @@ void testUsingContext(
rethrow; rethrow;
} }
}, onError: (Object error, StackTrace stackTrace) { // ignore: deprecated_member_use }, onError: (Object error, StackTrace stackTrace) { // ignore: deprecated_member_use
io.stdout.writeln(error); print(error);
io.stdout.writeln(stackTrace); print(stackTrace);
_printBufferedErrors(context); _printBufferedErrors(context);
throw error; throw error;
}); });
......
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