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 @@
// 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';
......@@ -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);
......@@ -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;
}
......@@ -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.
......
......@@ -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,
......
......@@ -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';
......@@ -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);
......
......@@ -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';
......@@ -26,26 +25,26 @@ 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() {
......@@ -53,11 +52,6 @@ void main() {
Environment environment;
Platform platform;
setUpAll(() {
Cache.disableLocking();
Cache.flutterRoot = '';
});
setUp(() {
platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
testbed = Testbed(setup: () {
......@@ -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)
......@@ -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);
}
}));
......
......@@ -538,6 +538,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});
testWithoutContext('uses timeout', () async {
......@@ -596,6 +597,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});
testUsingContext('handles unknown architectures', () async {
......@@ -644,6 +646,7 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
Artifacts: () => Artifacts.test(),
});
});
......
......@@ -31,6 +31,7 @@ void main() {
List<int> mockTimes;
setUp(() {
Cache.disableLocking();
cache = MockitoCache();
usage = MockitoUsage();
clock = MockClock();
......@@ -43,6 +44,10 @@ void main() {
when(mockProcessInfo.maxRss).thenReturn(10);
});
tearDown(() {
Cache.enableLocking();
});
testUsingContext('help text contains global options', () {
final FakeDeprecatedCommand fake = FakeDeprecatedCommand();
createTestCommandRunner(fake);
......
......@@ -40,7 +40,6 @@ void main() {
testbed = Testbed(overrides: <Type, Generator>{
ProcessManager: () {
print('in get process manager');
return mockProcessManager;
}
});
......
......@@ -13,8 +13,8 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../src/common.dart';
import '../src/context.dart';
const String base64PlistXml =
'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHBsaXN0I'
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io' as io;
import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/bot_detector.dart';
......@@ -158,8 +157,8 @@ void testUsingContext(
rethrow;
}
}, onError: (Object error, StackTrace stackTrace) { // ignore: deprecated_member_use
io.stdout.writeln(error);
io.stdout.writeln(stackTrace);
print(error);
print(stackTrace);
_printBufferedErrors(context);
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