Unverified Commit 547ed88a authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Swap MockStdio to FakeStdio in tests (#74838)

parent f04616f7
...@@ -227,7 +227,7 @@ void main() { ...@@ -227,7 +227,7 @@ void main() {
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
DeviceManager: () => mockDeviceManager, DeviceManager: () => mockDeviceManager,
Stdio: () => MockStdio(), Stdio: () => FakeStdio(hasFakeTerminal: true),
}); });
testUsingContext('shows unsupported devices when no supported devices are found', () async { testUsingContext('shows unsupported devices when no supported devices are found', () async {
......
...@@ -17,12 +17,12 @@ import 'package:mockito/mockito.dart'; ...@@ -17,12 +17,12 @@ import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/mocks.dart'; import '../../src/fakes.dart';
void main() { void main() {
MemoryFileSystem fileSystem; MemoryFileSystem fileSystem;
MockStdio stdio; FakeStdio stdio;
SymbolizeCommand command; SymbolizeCommand command;
MockDwarfSymbolizationService mockDwarfSymbolizationService; MockDwarfSymbolizationService mockDwarfSymbolizationService;
...@@ -32,7 +32,7 @@ void main() { ...@@ -32,7 +32,7 @@ void main() {
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
stdio = MockStdio(); stdio = FakeStdio();
mockDwarfSymbolizationService = MockDwarfSymbolizationService(); mockDwarfSymbolizationService = MockDwarfSymbolizationService();
command = SymbolizeCommand( command = SymbolizeCommand(
stdio: stdio, stdio: stdio,
......
...@@ -26,7 +26,7 @@ import 'package:usage/usage_io.dart'; ...@@ -26,7 +26,7 @@ import 'package:usage/usage_io.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/mocks.dart'; import '../src/fakes.dart';
void main() { void main() {
setUpAll(() { setUpAll(() {
...@@ -152,7 +152,7 @@ void main() { ...@@ -152,7 +152,7 @@ void main() {
group('analytics with mocks', () { group('analytics with mocks', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
MockStdio mockStdio; FakeStdio fakeStdio;
Usage mockUsage; Usage mockUsage;
SystemClock mockClock; SystemClock mockClock;
Doctor mockDoctor; Doctor mockDoctor;
...@@ -160,7 +160,7 @@ void main() { ...@@ -160,7 +160,7 @@ void main() {
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
mockStdio = MockStdio(); fakeStdio = FakeStdio();
mockUsage = MockUsage(); mockUsage = MockUsage();
mockClock = MockClock(); mockClock = MockClock();
mockDoctor = MockDoctor(); mockDoctor = MockDoctor();
...@@ -266,7 +266,7 @@ void main() { ...@@ -266,7 +266,7 @@ void main() {
'FLUTTER_ANALYTICS_LOG_FILE': 'analytics.log', 'FLUTTER_ANALYTICS_LOG_FILE': 'analytics.log',
}, },
), ),
Stdio: () => mockStdio, Stdio: () => fakeStdio,
}); });
testUsingContext('event sends localtime', () async { testUsingContext('event sends localtime', () async {
...@@ -296,7 +296,7 @@ void main() { ...@@ -296,7 +296,7 @@ void main() {
'FLUTTER_ANALYTICS_LOG_FILE': 'analytics.log', 'FLUTTER_ANALYTICS_LOG_FILE': 'analytics.log',
}, },
), ),
Stdio: () => mockStdio, Stdio: () => fakeStdio,
}); });
}); });
......
...@@ -18,7 +18,8 @@ import 'package:mockito/mockito.dart'; ...@@ -18,7 +18,8 @@ import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/mocks.dart' show MockAndroidSdk, MockProcess, MockProcessManager, MockStdio; import '../../src/fakes.dart';
import '../../src/mocks.dart' show MockAndroidSdk, MockProcess, MockProcessManager;
import '../../src/testbed.dart'; import '../../src/testbed.dart';
class MockAndroidSdkVersion extends Mock implements AndroidSdkVersion {} class MockAndroidSdkVersion extends Mock implements AndroidSdkVersion {}
...@@ -29,7 +30,7 @@ void main() { ...@@ -29,7 +30,7 @@ void main() {
Logger logger; Logger logger;
MemoryFileSystem fileSystem; MemoryFileSystem fileSystem;
MockProcessManager processManager; MockProcessManager processManager;
MockStdio stdio; FakeStdio stdio;
setUp(() { setUp(() {
sdk = MockAndroidSdk(); sdk = MockAndroidSdk();
...@@ -37,7 +38,7 @@ void main() { ...@@ -37,7 +38,7 @@ void main() {
fileSystem.directory('/home/me').createSync(recursive: true); fileSystem.directory('/home/me').createSync(recursive: true);
logger = BufferLogger.test(); logger = BufferLogger.test();
processManager = MockProcessManager(); processManager = MockProcessManager();
stdio = MockStdio(); stdio = FakeStdio();
}); });
MockProcess Function(List<String>) processMetaFactory(List<String> stdout) { MockProcess Function(List<String>) processMetaFactory(List<String> stdout) {
......
...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/mocks.dart'; import '../src/fakes.dart';
final Platform testPlatform = FakePlatform(environment: const <String, String>{}); final Platform testPlatform = FakePlatform(environment: const <String, String>{});
...@@ -171,7 +171,7 @@ void main() { ...@@ -171,7 +171,7 @@ void main() {
final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final Logger logger = StdoutLogger( final Logger logger = StdoutLogger(
terminal: Terminal.test(supportsColor: true), terminal: Terminal.test(supportsColor: true),
stdio: MockStdio(), stdio: FakeStdio(),
outputPreferences: OutputPreferences.test(), outputPreferences: OutputPreferences.test(),
); );
final ArtifactUpdater artifactUpdater = ArtifactUpdater( final ArtifactUpdater artifactUpdater = ArtifactUpdater(
......
...@@ -16,12 +16,10 @@ import 'package:mockito/mockito.dart'; ...@@ -16,12 +16,10 @@ import 'package:mockito/mockito.dart';
import 'package:fake_async/fake_async.dart'; import 'package:fake_async/fake_async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/mocks.dart';
void main() { void main() {
group('BotDetector', () { group('BotDetector', () {
FakePlatform fakePlatform; FakePlatform fakePlatform;
MockStdio mockStdio;
MockHttpClient mockHttpClient; MockHttpClient mockHttpClient;
MockHttpClientRequest mockHttpClientRequest; MockHttpClientRequest mockHttpClientRequest;
MockHttpHeaders mockHttpHeaders; MockHttpHeaders mockHttpHeaders;
...@@ -30,7 +28,6 @@ void main() { ...@@ -30,7 +28,6 @@ void main() {
setUp(() { setUp(() {
fakePlatform = FakePlatform()..environment = <String, String>{}; fakePlatform = FakePlatform()..environment = <String, String>{};
mockStdio = MockStdio();
mockHttpClient = MockHttpClient(); mockHttpClient = MockHttpClient();
mockHttpClientRequest = MockHttpClientRequest(); mockHttpClientRequest = MockHttpClientRequest();
mockHttpHeaders = MockHttpHeaders(); mockHttpHeaders = MockHttpHeaders();
...@@ -62,17 +59,6 @@ void main() { ...@@ -62,17 +59,6 @@ void main() {
expect(persistentToolState.isRunningOnBot, isFalse); expect(persistentToolState.isRunningOnBot, isFalse);
}); });
testWithoutContext('returns false with and without a terminal attached', () async {
when(mockHttpClient.getUrl(any)).thenAnswer((_) {
throw const SocketException('HTTP connection timed out');
});
mockStdio.stdout.hasTerminal = true;
expect(await botDetector.isRunningOnBot, isFalse);
mockStdio.stdout.hasTerminal = false;
expect(await botDetector.isRunningOnBot, isFalse);
expect(persistentToolState.isRunningOnBot, isFalse);
});
testWithoutContext('can test analytics outputs on bots when outputting to a file', () async { testWithoutContext('can test analytics outputs on bots when outputting to a file', () async {
fakePlatform.environment['TRAVIS'] = 'true'; fakePlatform.environment['TRAVIS'] = 'true';
fakePlatform.environment['FLUTTER_ANALYTICS_LOG_FILE'] = '/some/file'; fakePlatform.environment['FLUTTER_ANALYTICS_LOG_FILE'] = '/some/file';
......
...@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/base/terminal.dart' show AnsiTerminal, OutputP ...@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/base/terminal.dart' show AnsiTerminal, OutputP
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/mocks.dart' show MockStdio; import '../../src/fakes.dart';
CommandHelp _createCommandHelp({ CommandHelp _createCommandHelp({
@required bool ansi, @required bool ansi,
...@@ -23,7 +23,7 @@ CommandHelp _createCommandHelp({ ...@@ -23,7 +23,7 @@ CommandHelp _createCommandHelp({
return CommandHelp( return CommandHelp(
logger: BufferLogger.test(), logger: BufferLogger.test(),
terminal: AnsiTerminal( terminal: AnsiTerminal(
stdio: MockStdio(), stdio: FakeStdio(),
platform: platform, platform: platform,
), ),
platform: platform, platform: platform,
......
...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/base/terminal.dart'; ...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:fake_async/fake_async.dart'; import 'package:fake_async/fake_async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/mocks.dart' show MockStdio; import '../../src/fakes.dart';
void main() { void main() {
BufferLogger testLogger; BufferLogger testLogger;
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
setUp(() { setUp(() {
testLogger = BufferLogger( testLogger = BufferLogger(
terminal: AnsiTerminal( terminal: AnsiTerminal(
stdio: MockStdio(), stdio: FakeStdio(),
platform: FakePlatform(stdoutSupportsAnsi: false), platform: FakePlatform(stdoutSupportsAnsi: false),
), ),
outputPreferences: OutputPreferences.test(), outputPreferences: OutputPreferences.test(),
......
...@@ -15,9 +15,9 @@ import 'package:mockito/mockito.dart'; ...@@ -15,9 +15,9 @@ import 'package:mockito/mockito.dart';
import 'package:fake_async/fake_async.dart'; import 'package:fake_async/fake_async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart' show MockProcess, import '../../src/mocks.dart' show MockProcess,
MockProcessManager, MockProcessManager,
MockStdio,
flakyProcessFactory; flakyProcessFactory;
void main() { void main() {
...@@ -90,7 +90,7 @@ void main() { ...@@ -90,7 +90,7 @@ void main() {
mockProcessManager = MockProcessManager(); mockProcessManager = MockProcessManager();
mockLogger = BufferLogger( mockLogger = BufferLogger(
terminal: AnsiTerminal( terminal: AnsiTerminal(
stdio: MockStdio(), stdio: FakeStdio(),
platform: FakePlatform(stdoutSupportsAnsi: false), platform: FakePlatform(stdoutSupportsAnsi: false),
), ),
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40), outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
...@@ -280,7 +280,7 @@ void main() { ...@@ -280,7 +280,7 @@ void main() {
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]); fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
testLogger = BufferLogger( testLogger = BufferLogger(
terminal: AnsiTerminal( terminal: AnsiTerminal(
stdio: MockStdio(), stdio: FakeStdio(),
platform: FakePlatform(stdinSupportsAnsi: false), platform: FakePlatform(stdinSupportsAnsi: false),
), ),
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40), outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
......
...@@ -22,6 +22,7 @@ import 'package:mockito/mockito.dart'; ...@@ -22,6 +22,7 @@ import 'package:mockito/mockito.dart';
import '../../../src/common.dart'; import '../../../src/common.dart';
import '../../../src/context.dart'; import '../../../src/context.dart';
import '../../../src/fakes.dart';
import '../../../src/mocks.dart' as mocks; import '../../../src/mocks.dart' as mocks;
final Platform kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false); final Platform kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
...@@ -90,7 +91,7 @@ void main() { ...@@ -90,7 +91,7 @@ void main() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
logger = BufferLogger( logger = BufferLogger(
terminal: AnsiTerminal( terminal: AnsiTerminal(
stdio: mocks.MockStdio(), stdio: FakeStdio(),
platform: kNoAnsiPlatform, platform: kNoAnsiPlatform,
), ),
outputPreferences: OutputPreferences.test(showColor: false), outputPreferences: OutputPreferences.test(showColor: false),
......
...@@ -20,6 +20,7 @@ import 'package:process/process.dart'; ...@@ -20,6 +20,7 @@ import 'package:process/process.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import 'utils.dart'; import 'utils.dart';
const String _kFlutterRoot = '/flutter/flutter'; const String _kFlutterRoot = '/flutter/flutter';
...@@ -253,20 +254,3 @@ class FakeFlutterCommand extends FlutterCommand { ...@@ -253,20 +254,3 @@ class FakeFlutterCommand extends FlutterCommand {
@override @override
String get name => 'fake'; String get name => 'fake';
} }
class FakeStdio extends Stdio {
FakeStdio({this.hasFakeTerminal});
final bool hasFakeTerminal;
@override
bool get hasTerminal => hasFakeTerminal;
@override
int get terminalColumns => hasFakeTerminal ? 80 : null;
@override
int get terminalLines => hasFakeTerminal ? 24 : null;
@override
bool get supportsAnsiEscapes => hasFakeTerminal;
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
...@@ -65,3 +66,20 @@ class FakeDyldEnvironmentArtifact extends ArtifactSet { ...@@ -65,3 +66,20 @@ class FakeDyldEnvironmentArtifact extends ArtifactSet {
Future<void> update(ArtifactUpdater artifactUpdater, Logger logger, FileSystem fileSystem, OperatingSystemUtils operatingSystemUtils) async { Future<void> update(ArtifactUpdater artifactUpdater, Logger logger, FileSystem fileSystem, OperatingSystemUtils operatingSystemUtils) async {
} }
} }
class FakeStdio extends Stdio {
FakeStdio({this.hasFakeTerminal});
final bool hasFakeTerminal;
@override
bool get hasTerminal => hasFakeTerminal;
@override
int get terminalColumns => hasFakeTerminal ? 80 : null;
@override
int get terminalLines => hasFakeTerminal ? 24 : null;
@override
bool get supportsAnsiEscapes => hasFakeTerminal;
}
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