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