Unverified Commit 064eae8c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks and fix fake imports (#81309)

parent cbdd9c47
...@@ -74,9 +74,12 @@ const String _kDefaultIndex = ''' ...@@ -74,9 +74,12 @@ const String _kDefaultIndex = '''
/// ///
/// This is only used in development mode. /// This is only used in development mode.
class WebExpressionCompiler implements ExpressionCompiler { class WebExpressionCompiler implements ExpressionCompiler {
WebExpressionCompiler(this._generator); WebExpressionCompiler(this._generator, {
@required FileSystem fileSystem,
}) : _fileSystem = fileSystem;
final ResidentCompiler _generator; final ResidentCompiler _generator;
final FileSystem _fileSystem;
@override @override
Future<ExpressionCompilationResult> compileExpressionToJs( Future<ExpressionCompilationResult> compileExpressionToJs(
...@@ -95,7 +98,7 @@ class WebExpressionCompiler implements ExpressionCompiler { ...@@ -95,7 +98,7 @@ class WebExpressionCompiler implements ExpressionCompiler {
if (compilerOutput != null && compilerOutput.outputFilename != null) { if (compilerOutput != null && compilerOutput.outputFilename != null) {
final String content = utf8.decode( final String content = utf8.decode(
globals.fs.file(compilerOutput.outputFilename).readAsBytesSync()); _fileSystem.file(compilerOutput.outputFilename).readAsBytesSync());
return ExpressionCompilationResult( return ExpressionCompilationResult(
content, compilerOutput.errorCount > 0); content, compilerOutput.errorCount > 0);
} }
......
...@@ -256,7 +256,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -256,7 +256,7 @@ class ResidentWebRunner extends ResidentRunner {
return await asyncGuard(() async { return await asyncGuard(() async {
final ExpressionCompiler expressionCompiler = final ExpressionCompiler expressionCompiler =
debuggingOptions.webEnableExpressionEvaluation debuggingOptions.webEnableExpressionEvaluation
? WebExpressionCompiler(device.generator) ? WebExpressionCompiler(device.generator, fileSystem: _fileSystem)
: null; : null;
device.devFS = WebDevFS( device.devFS = WebDevFS(
hostname: debuggingOptions.hostname ?? 'localhost', hostname: debuggingOptions.hostname ?? 'localhost',
......
...@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -32,7 +31,7 @@ void main() { ...@@ -32,7 +31,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode', () { testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode', () {
...@@ -45,7 +44,7 @@ void main() { ...@@ -45,7 +44,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in release mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores in release mode", () {
...@@ -58,7 +57,7 @@ void main() { ...@@ -58,7 +57,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooRelease', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooRelease/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in release mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in release mode", () {
...@@ -71,7 +70,7 @@ void main() { ...@@ -71,7 +70,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaRelease', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooaRelease/app.aab');
}); });
testWithoutContext('Finds app bundle when no flavor is used in release mode', () { testWithoutContext('Finds app bundle when no flavor is used in release mode', () {
...@@ -84,7 +83,7 @@ void main() { ...@@ -84,7 +83,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'release', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/release/app.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores in debug mode', () { testWithoutContext('Finds app bundle when flavor contains underscores in debug mode', () {
...@@ -97,7 +96,7 @@ void main() { ...@@ -97,7 +96,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode', () { testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode', () {
...@@ -110,7 +109,7 @@ void main() { ...@@ -110,7 +109,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in debug mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores in debug mode", () {
...@@ -123,7 +122,7 @@ void main() { ...@@ -123,7 +122,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooDebug', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooDebug/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in debug mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in debug mode", () {
...@@ -136,7 +135,7 @@ void main() { ...@@ -136,7 +135,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaDebug', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooaDebug/app.aab');
}); });
testWithoutContext('Finds app bundle when no flavor is used in debug mode', () { testWithoutContext('Finds app bundle when no flavor is used in debug mode', () {
...@@ -149,7 +148,7 @@ void main() { ...@@ -149,7 +148,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'debug', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/debug/app.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores in profile mode', () { testWithoutContext('Finds app bundle when flavor contains underscores in profile mode', () {
...@@ -162,7 +161,7 @@ void main() { ...@@ -162,7 +161,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in profile mode', () { testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in profile mode', () {
...@@ -175,7 +174,7 @@ void main() { ...@@ -175,7 +174,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in profile mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores in profile mode", () {
...@@ -188,7 +187,7 @@ void main() { ...@@ -188,7 +187,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooProfile', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooProfile/app.aab');
}); });
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in profile mode", () { testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in profile mode", () {
...@@ -201,7 +200,7 @@ void main() { ...@@ -201,7 +200,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaProfile', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/fooaProfile/app.aab');
}); });
testWithoutContext('Finds app bundle when no flavor is used in profile mode', () { testWithoutContext('Finds app bundle when no flavor is used in profile mode', () {
...@@ -214,7 +213,7 @@ void main() { ...@@ -214,7 +213,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'profile', 'app.aab')); expect(bundle.path, '/build/app/outputs/bundle/profile/app.aab');
}); });
testWithoutContext('Finds app bundle in release mode - Gradle 3.5', () { testWithoutContext('Finds app bundle in release mode - Gradle 3.5', () {
...@@ -227,7 +226,7 @@ void main() { ...@@ -227,7 +226,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'release', 'app-release.aab')); expect(bundle.path, '/build/app/outputs/bundle/release/app-release.aab');
}); });
testWithoutContext('Finds app bundle in profile mode - Gradle 3.5', () { testWithoutContext('Finds app bundle in profile mode - Gradle 3.5', () {
...@@ -240,7 +239,7 @@ void main() { ...@@ -240,7 +239,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'profile', 'app-profile.aab')); expect(bundle.path, '/build/app/outputs/bundle/profile/app-profile.aab');
}); });
testWithoutContext('Finds app bundle in debug mode - Gradle 3.5', () { testWithoutContext('Finds app bundle in debug mode - Gradle 3.5', () {
...@@ -253,7 +252,7 @@ void main() { ...@@ -253,7 +252,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'debug', 'app-debug.aab')); expect(bundle.path, '/build/app/outputs/bundle/debug/app-debug.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores in release mode - Gradle 3.5', () { testWithoutContext('Finds app bundle when flavor contains underscores in release mode - Gradle 3.5', () {
...@@ -266,7 +265,7 @@ void main() { ...@@ -266,7 +265,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app-foo_bar-release.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 3.5', () { testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 3.5', () {
...@@ -279,7 +278,7 @@ void main() { ...@@ -279,7 +278,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app-foo_bar-release.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores in profile mode - Gradle 3.5', () { testWithoutContext('Finds app bundle when flavor contains underscores in profile mode - Gradle 3.5', () {
...@@ -292,7 +291,7 @@ void main() { ...@@ -292,7 +291,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app-foo_bar-profile.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app-foo_bar-profile.aab');
}); });
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 3.5', () { testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 3.5', () {
...@@ -305,7 +304,7 @@ void main() { ...@@ -305,7 +304,7 @@ void main() {
); );
expect(bundle, isNotNull); expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant','app', 'outputs', 'bundle', 'foo_barDebug', 'app-foo_bar-debug.aab')); expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app-foo_bar-debug.aab');
}); });
testWithoutContext('AAB not found', () { testWithoutContext('AAB not found', () {
...@@ -341,12 +340,7 @@ void main() { ...@@ -341,12 +340,7 @@ void main() {
/// Generates a fake app bundle at the location [directoryName]/[fileName]. /// Generates a fake app bundle at the location [directoryName]/[fileName].
FlutterProject generateFakeAppBundle(String directoryName, String fileName, FileSystem fileSystem) { FlutterProject generateFakeAppBundle(String directoryName, String fileName, FileSystem fileSystem) {
final FlutterProject project = MockFlutterProject(); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final AndroidProject androidProject = MockAndroidProject();
when(project.isModule).thenReturn(false);
when(project.android).thenReturn(androidProject);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('irrelevant'));
final Directory bundleDirectory = getBundleDirectory(project); final Directory bundleDirectory = getBundleDirectory(project);
bundleDirectory bundleDirectory
...@@ -359,6 +353,3 @@ FlutterProject generateFakeAppBundle(String directoryName, String fileName, File ...@@ -359,6 +353,3 @@ FlutterProject generateFakeAppBundle(String directoryName, String fileName, File
.createSync(); .createSync();
return project; return project;
} }
class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {}
...@@ -19,11 +19,19 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -19,11 +19,19 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
const String kModulePubspec = '''
name: test
flutter:
module:
androidPackage: com.example
androidX: true
''';
void main() { void main() {
Cache.flutterRoot = getFlutterRoot(); Cache.flutterRoot = getFlutterRoot();
...@@ -35,54 +43,42 @@ void main() { ...@@ -35,54 +43,42 @@ void main() {
}); });
testWithoutContext('getApkDirectory in app projects', () { testWithoutContext('getApkDirectory in app projects', () {
final FlutterProject project = MockFlutterProject(); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(false);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
expect( expect(
getApkDirectory(project).path, getApkDirectory(project).path, '/build/app/outputs/flutter-apk',
equals(fileSystem.path.join('foo', 'app', 'outputs', 'flutter-apk')),
); );
}); });
testWithoutContext('getApkDirectory in module projects', () { testWithoutContext('getApkDirectory in module projects', () {
final FlutterProject project = MockFlutterProject(); fileSystem.currentDirectory
final AndroidProject androidProject = MockAndroidProject(); .childFile('pubspec.yaml')
when(project.android).thenReturn(androidProject); .writeAsStringSync(kModulePubspec);
when(project.isModule).thenReturn(true); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
expect(project.isModule, true);
expect( expect(
getApkDirectory(project).path, getApkDirectory(project).path, '/build/host/outputs/apk',
equals(fileSystem.path.join('foo', 'host', 'outputs', 'apk')),
); );
}); });
testWithoutContext('getBundleDirectory in app projects', () { testWithoutContext('getBundleDirectory in app projects', () {
final FlutterProject project = MockFlutterProject(); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(false);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
expect( expect(
getBundleDirectory(project).path, getBundleDirectory(project).path, '/build/app/outputs/bundle',
equals(fileSystem.path.join('foo', 'app', 'outputs', 'bundle')),
); );
}); });
testWithoutContext('getBundleDirectory in module projects', () { testWithoutContext('getBundleDirectory in module projects', () {
final FlutterProject project = MockFlutterProject(); fileSystem.currentDirectory
final AndroidProject androidProject = MockAndroidProject(); .childFile('pubspec.yaml')
when(project.android).thenReturn(androidProject); .writeAsStringSync(kModulePubspec);
when(project.isModule).thenReturn(true); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
expect(project.isModule, true);
expect( expect(
getBundleDirectory(project).path, getBundleDirectory(project).path, '/build/host/outputs/bundle',
equals(fileSystem.path.join('foo', 'host', 'outputs', 'bundle')),
); );
}); });
...@@ -1028,5 +1024,3 @@ class FakeGradleUtils extends GradleUtils { ...@@ -1028,5 +1024,3 @@ class FakeGradleUtils extends GradleUtils {
} }
class FakeAndroidSdk extends Fake implements AndroidSdk {} class FakeAndroidSdk extends Fake implements AndroidSdk {}
class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {}
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
// @dart = 2.8 // @dart = 2.8
import 'dart:io' as io; // ignore: dart_io_import
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/device_port_forwarder.dart'; import 'package:flutter_tools/src/device_port_forwarder.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
...@@ -19,12 +20,20 @@ void main() { ...@@ -19,12 +20,20 @@ void main() {
}); });
testUsingContext('dispose kills process if process was available', () { testUsingContext('dispose kills process if process was available', () {
final MockProcess mockProcess = MockProcess(); final FakeProcess process = FakeProcess();
final ForwardedPort forwardedPort = ForwardedPort.withContext(123, 456, mockProcess); final ForwardedPort forwardedPort = ForwardedPort.withContext(123, 456, process);
forwardedPort.dispose(); forwardedPort.dispose();
expect(forwardedPort.context, isNotNull); expect(forwardedPort.context, isNotNull);
verify(mockProcess.kill()); expect(process.killed, true);
}); });
} }
class MockProcess extends Mock implements Process {} class FakeProcess extends Fake implements Process {
bool killed = false;
@override
bool kill([io.ProcessSignal signal = io.ProcessSignal.sigterm]) {
return killed = true;
}
}
...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/user_messages.dart'; ...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/doctor_validator.dart'; import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/fake_process_manager.dart'; import '../src/fake_process_manager.dart';
......
...@@ -14,7 +14,7 @@ import 'package:flutter_tools/src/device.dart'; ...@@ -14,7 +14,7 @@ import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/linux/application_package.dart'; import 'package:flutter_tools/src/linux/application_package.dart';
import 'package:flutter_tools/src/linux/linux_device.dart'; import 'package:flutter_tools/src/linux/linux_device.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
...@@ -139,23 +139,17 @@ void main() { ...@@ -139,23 +139,17 @@ void main() {
}); });
testWithoutContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async { testWithoutContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async {
final MockLinuxApp mockApp = MockLinuxApp(); final FakeLinuxApp mockApp = FakeLinuxApp();
final LinuxDevice device = LinuxDevice( final LinuxDevice device = LinuxDevice(
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
); );
const String debugPath = 'debug/executable';
const String profilePath = 'profile/executable'; expect(device.executablePathForDevice(mockApp, BuildMode.debug), 'debug/executable');
const String releasePath = 'release/executable'; expect(device.executablePathForDevice(mockApp, BuildMode.profile), 'profile/executable');
when(mockApp.executable(BuildMode.debug)).thenReturn(debugPath); expect(device.executablePathForDevice(mockApp, BuildMode.release), 'release/executable');
when(mockApp.executable(BuildMode.profile)).thenReturn(profilePath);
when(mockApp.executable(BuildMode.release)).thenReturn(releasePath);
expect(device.executablePathForDevice(mockApp, BuildMode.debug), debugPath);
expect(device.executablePathForDevice(mockApp, BuildMode.profile), profilePath);
expect(device.executablePathForDevice(mockApp, BuildMode.release), releasePath);
}); });
} }
...@@ -167,7 +161,21 @@ FlutterProject setUpFlutterProject(Directory directory) { ...@@ -167,7 +161,21 @@ FlutterProject setUpFlutterProject(Directory directory) {
return flutterProjectFactory.fromDirectory(directory); return flutterProjectFactory.fromDirectory(directory);
} }
class MockLinuxApp extends Mock implements LinuxApp {} class FakeLinuxApp extends Fake implements LinuxApp {
@override
String executable(BuildMode buildMode) {
switch (buildMode) {
case BuildMode.debug:
return 'debug/executable';
case BuildMode.profile:
return 'profile/executable';
case BuildMode.release:
return 'release/executable';
default:
throw StateError('Invalid mode: $buildMode');
}
}
}
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils { class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
FakeOperatingSystemUtils({ FakeOperatingSystemUtils({
HostPlatform hostPlatform = HostPlatform.linux_x64 HostPlatform hostPlatform = HostPlatform.linux_x64
......
...@@ -19,7 +19,6 @@ import 'package:flutter_tools/src/globals.dart' as globals; ...@@ -19,7 +19,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/crash_reporting.dart'; import 'package:flutter_tools/src/reporting/crash_reporting.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -180,9 +179,9 @@ void main() { ...@@ -180,9 +179,9 @@ void main() {
expect(logContents, contains('String: an exception % --')); expect(logContents, contains('String: an exception % --'));
expect(logContents, contains('CrashingFlutterCommand.runCommand')); expect(logContents, contains('CrashingFlutterCommand.runCommand'));
expect(logContents, contains('[✓] Flutter')); expect(logContents, contains('[✓] Flutter'));
print(globals.crashReporter.runtimeType);
final VerificationResult argVerification = verify(globals.crashReporter.informUser(captureAny, any)); final CrashDetails sentDetails = (globals.crashReporter as WaitingCrashReporter)._details;
final CrashDetails sentDetails = argVerification.captured.first as CrashDetails;
expect(sentDetails.command, 'flutter crash'); expect(sentDetails.command, 'flutter crash');
expect(sentDetails.error, 'an exception % --'); expect(sentDetails.error, 'an exception % --');
expect(sentDetails.stackTrace.toString(), contains('CrashingFlutterCommand.runCommand')); expect(sentDetails.stackTrace.toString(), contains('CrashingFlutterCommand.runCommand'));
...@@ -199,6 +198,7 @@ void main() { ...@@ -199,6 +198,7 @@ void main() {
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
UserMessages: () => CustomBugInstructions(), UserMessages: () => CustomBugInstructions(),
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
CrashReporter: () => WaitingCrashReporter(Future<void>.value())
}); });
}); });
} }
...@@ -331,7 +331,11 @@ class WaitingCrashReporter implements CrashReporter { ...@@ -331,7 +331,11 @@ class WaitingCrashReporter implements CrashReporter {
WaitingCrashReporter(Future<void> future) : _future = future; WaitingCrashReporter(Future<void> future) : _future = future;
final Future<void> _future; final Future<void> _future;
CrashDetails _details;
@override @override
Future<void> informUser(CrashDetails details, File crashFile) => _future; Future<void> informUser(CrashDetails details, File crashFile) {
_details = details;
return _future;
}
} }
...@@ -5,78 +5,55 @@ ...@@ -5,78 +5,55 @@
// @dart = 2.8 // @dart = 2.8
import 'package:dwds/dwds.dart'; import 'package:dwds/dwds.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/isolated/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/testbed.dart';
void main() { void main() {
Testbed testbed; FileSystem fileSystem;
setUp(() { setUp(() {
testbed = Testbed(); fileSystem = MemoryFileSystem.test();
}); });
test('WebExpressionCompiler handles successful expression compilation', () => testbed.run(() async { testWithoutContext('WebExpressionCompiler handles successful expression compilation', () async {
globals.fs.file('compilerOutput').writeAsStringSync('a'); fileSystem.file('compilerOutput').writeAsStringSync('a');
final ResidentCompiler residentCompiler = FakeResidentCompiler(const CompilerOutput('compilerOutput', 0, <Uri>[]));
final ResidentCompiler residentCompiler = MockResidentCompiler(); final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('compilerOutput', 0, <Uri>[]);
});
final ExpressionCompiler expressionCompiler =
WebExpressionCompiler(residentCompiler);
final ExpressionCompilationResult result = final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs( await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, null); null, null, 1, 1, null, null, null, null);
expectResult(result, false, 'a'); expectResult(result, false, 'a');
})); });
test('WebExpressionCompiler handles compilation error', () => testbed.run(() async {
globals.fs.file('compilerOutput').writeAsStringSync('Error: a');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('compilerOutput', 1, <Uri>[]);
});
final ExpressionCompiler expressionCompiler = testWithoutContext('WebExpressionCompiler handles compilation error', () async {
WebExpressionCompiler(residentCompiler); fileSystem.file('compilerOutput').writeAsStringSync('Error: a');
final ResidentCompiler residentCompiler = FakeResidentCompiler(const CompilerOutput('compilerOutput', 1, <Uri>[]));
final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
final ExpressionCompilationResult result = final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs( await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, null); null, null, 1, 1, null, null, null, null);
expectResult(result, true, 'Error: a'); expectResult(result, true, 'Error: a');
})); });
test('WebExpressionCompiler handles internal error', () => testbed.run(() async {
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return null;
});
final ExpressionCompiler expressionCompiler = testWithoutContext('WebExpressionCompiler handles internal error', () async {
WebExpressionCompiler(residentCompiler); final ResidentCompiler residentCompiler = FakeResidentCompiler(null);
final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
final ExpressionCompilationResult result = final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs( await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, 'a'); null, null, 1, 1, null, null, null, 'a');
expectResult(result, true, 'InternalError: frontend server failed to compile \'a\''); expectResult(result, true, 'InternalError: frontend server failed to compile \'a\'');
})); });
} }
void expectResult(ExpressionCompilationResult result, bool isError, String value) { void expectResult(ExpressionCompilationResult result, bool isError, String value) {
...@@ -86,4 +63,21 @@ void expectResult(ExpressionCompilationResult result, bool isError, String value ...@@ -86,4 +63,21 @@ void expectResult(ExpressionCompilationResult result, bool isError, String value
.having((ExpressionCompilationResult instance) => instance.result, 'result', value)); .having((ExpressionCompilationResult instance) => instance.result, 'result', value));
} }
class MockResidentCompiler extends Mock implements ResidentCompiler {} class FakeResidentCompiler extends Fake implements ResidentCompiler {
FakeResidentCompiler(this.output);
final CompilerOutput output;
@override
Future<CompilerOutput> compileExpressionToJs(
String libraryUri,
int line,
int column,
Map<String, String> jsModules,
Map<String, String> jsFrameValues,
String moduleName,
String expression,
) async {
return output;
}
}
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