[flutter_tools] Remove fromPlatform from tests (#54152)
This commit is contained in:
parent
59b2c5a39e
commit
03c566768b
@ -33,9 +33,10 @@ import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
final Generator _kNoColorOutputPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..localeName = 'en_US.UTF-8'
|
||||
..stdoutSupportsAnsi = false;
|
||||
final Generator _kNoColorOutputPlatform = () => FakePlatform(
|
||||
localeName: 'en_US.UTF-8',
|
||||
stdoutSupportsAnsi: false,
|
||||
);
|
||||
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
Platform: _kNoColorOutputPlatform,
|
||||
|
@ -20,7 +20,8 @@ import 'package:process/process.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
final Platform _kNoColorTerminalPlatform = FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Platform _kNoColorTerminalPlatform = FakePlatform(
|
||||
stdoutSupportsAnsi: false);
|
||||
|
||||
void main() {
|
||||
String analyzerSeparator;
|
||||
|
@ -31,6 +31,7 @@ import '../../src/testbed.dart';
|
||||
|
||||
const String frameworkRevision = '12345678';
|
||||
const String frameworkChannel = 'omega';
|
||||
// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
|
@ -32,15 +32,17 @@ const Map<String, dynamic> macStudioInfoPlist = <String, dynamic>{
|
||||
class MockPlistUtils extends Mock implements PlistParser {}
|
||||
|
||||
Platform linuxPlatform() {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = 'linux'
|
||||
..environment = <String, String>{'HOME': homeLinux};
|
||||
return FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': homeLinux},
|
||||
);
|
||||
}
|
||||
|
||||
Platform macPlatform() {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = 'macos'
|
||||
..environment = <String, String>{'HOME': homeMac};
|
||||
return FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
environment: <String, String>{'HOME': homeMac},
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -18,9 +18,10 @@ import '../../src/context.dart';
|
||||
const String home = '/home/me';
|
||||
|
||||
Platform linuxPlatform() {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = 'linux'
|
||||
..environment = <String, String>{'HOME': home};
|
||||
return FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': home}
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -601,9 +601,10 @@ bool testErrorMessage(String errorMessage, GradleHandledError error) {
|
||||
}
|
||||
|
||||
Platform fakePlatform(String name) {
|
||||
return FakePlatform
|
||||
.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = name;
|
||||
return FakePlatform(
|
||||
environment: <String, String>{},
|
||||
operatingSystem: name,
|
||||
);
|
||||
}
|
||||
|
||||
class FakeGradleUtils extends GradleUtils {
|
||||
|
@ -2633,9 +2633,11 @@ FlutterProject generateFakeAppBundle(String directoryName, String fileName) {
|
||||
}
|
||||
|
||||
FakePlatform fakePlatform(String name) {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = name
|
||||
..stdoutSupportsAnsi = false;
|
||||
return FakePlatform(
|
||||
environment: <String, String>{'HOME': '/path/to/home'},
|
||||
operatingSystem: name,
|
||||
stdoutSupportsAnsi: false,
|
||||
);
|
||||
}
|
||||
|
||||
class FakeGradleUtils extends GradleUtils {
|
||||
|
@ -25,7 +25,7 @@ import 'package:platform/platform.dart';
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false);
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ import 'package:quiver/testing/async.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/mocks.dart' as mocks;
|
||||
|
||||
final Platform _kNoAnsiPlatform = FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
|
||||
final String red = RegExp.escape(AnsiTerminal.red);
|
||||
final String bold = RegExp.escape(AnsiTerminal.bold);
|
||||
final String resetBold = RegExp.escape(AnsiTerminal.resetBold);
|
||||
@ -54,7 +54,7 @@ void main() {
|
||||
final BufferLogger mockLogger = BufferLogger(
|
||||
terminal: AnsiTerminal(
|
||||
stdio: mocks.MockStdio(),
|
||||
platform: FakePlatform()..stdoutSupportsAnsi = true,
|
||||
platform: FakePlatform(stdoutSupportsAnsi: true),
|
||||
),
|
||||
outputPreferences: OutputPreferences.test(showColor: true),
|
||||
);
|
||||
@ -250,8 +250,8 @@ void main() {
|
||||
AnsiStatus ansiStatus;
|
||||
|
||||
setUp(() {
|
||||
platform = FakePlatform.fromPlatform(testPlatform)..stdoutSupportsAnsi = false;
|
||||
ansiPlatform = FakePlatform.fromPlatform(testPlatform)..stdoutSupportsAnsi = true;
|
||||
platform = FakePlatform(stdoutSupportsAnsi: false);
|
||||
ansiPlatform = FakePlatform(stdoutSupportsAnsi: true);
|
||||
|
||||
terminal = AnsiTerminal(
|
||||
stdio: mockStdio,
|
||||
@ -749,7 +749,7 @@ void main() {
|
||||
final Logger logger = StdoutLogger(
|
||||
terminal: AnsiTerminal(
|
||||
stdio: mockStdio,
|
||||
platform: FakePlatform()..stdoutSupportsAnsi = true,
|
||||
platform: FakePlatform(stdoutSupportsAnsi: true),
|
||||
),
|
||||
stdio: mockStdio,
|
||||
outputPreferences: OutputPreferences.test(showColor: true),
|
||||
|
@ -25,7 +25,7 @@ void main() {
|
||||
testLogger = BufferLogger(
|
||||
terminal: AnsiTerminal(
|
||||
stdio: MockStdio(),
|
||||
platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
|
||||
platform: FakePlatform(stdoutSupportsAnsi: false),
|
||||
),
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
);
|
||||
@ -35,7 +35,7 @@ void main() {
|
||||
return Net(
|
||||
httpClientFactory: () => client,
|
||||
logger: testLogger,
|
||||
platform: FakePlatform.fromPlatform(const LocalPlatform()),
|
||||
platform: FakePlatform(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -160,10 +160,11 @@ void main() {
|
||||
ArgumentError('test exception handling'),
|
||||
),
|
||||
logger: testLogger,
|
||||
platform: FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..environment = <String, String>{
|
||||
platform: FakePlatform(
|
||||
environment: <String, String>{
|
||||
'FLUTTER_STORAGE_BASE_URL': 'example.invalid',
|
||||
},
|
||||
),
|
||||
);
|
||||
String error;
|
||||
FakeAsync().run((FakeAsync time) {
|
||||
|
@ -85,7 +85,7 @@ void main() {
|
||||
mockLogger = BufferLogger(
|
||||
terminal: AnsiTerminal(
|
||||
stdio: MockStdio(),
|
||||
platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
|
||||
platform: FakePlatform(stdoutSupportsAnsi: false),
|
||||
),
|
||||
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
|
||||
);
|
||||
@ -248,7 +248,7 @@ void main() {
|
||||
testLogger = BufferLogger(
|
||||
terminal: AnsiTerminal(
|
||||
stdio: MockStdio(),
|
||||
platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
|
||||
platform: FakePlatform(stdinSupportsAnsi: false),
|
||||
),
|
||||
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
|
||||
);
|
||||
|
@ -11,12 +11,9 @@ import '../../src/common.dart';
|
||||
typedef _InstallationMessage = String Function(Platform);
|
||||
|
||||
void main() {
|
||||
final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
macPlatform.operatingSystem = 'macos';
|
||||
final FakePlatform linuxPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
linuxPlatform.operatingSystem = 'linux';
|
||||
final FakePlatform windowsPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
windowsPlatform.operatingSystem = 'windows';
|
||||
final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
|
||||
final FakePlatform linuxPlatform = FakePlatform(operatingSystem: 'linux');
|
||||
final FakePlatform windowsPlatform = FakePlatform(operatingSystem: 'windows');
|
||||
|
||||
void _checkInstallationURL(_InstallationMessage message) {
|
||||
expect(message(macPlatform), contains('https://flutter.dev/docs/get-started/install/macos#android-setup'));
|
||||
|
@ -23,9 +23,7 @@ import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/mocks.dart' as mocks;
|
||||
|
||||
final Platform _kNoAnsiPlatform =
|
||||
FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..stdoutSupportsAnsi = false;
|
||||
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
|
||||
|
||||
void main() {
|
||||
BufferLogger logger;
|
||||
|
@ -28,12 +28,9 @@ import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
macPlatform.operatingSystem = 'macos';
|
||||
final FakePlatform linuxPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
linuxPlatform.operatingSystem = 'linux';
|
||||
final FakePlatform windowsPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
windowsPlatform.operatingSystem = 'windows';
|
||||
final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
|
||||
final FakePlatform linuxPlatform = FakePlatform(operatingSystem: 'linux');
|
||||
final FakePlatform windowsPlatform = FakePlatform(operatingSystem: 'windows');
|
||||
|
||||
group('IOSDevice', () {
|
||||
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
|
||||
|
@ -23,7 +23,7 @@ import 'package:process/process.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false);
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
};
|
||||
|
@ -44,8 +44,10 @@ void main() {
|
||||
MemoryFileSystem fileSystem;
|
||||
|
||||
setUp(() {
|
||||
osx = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
osx.operatingSystem = 'macos';
|
||||
osx = FakePlatform(
|
||||
environment: <String, String>{},
|
||||
operatingSystem: 'macos',
|
||||
);
|
||||
fileSystem = MemoryFileSystem();
|
||||
fsUtils = FileSystemUtils(fileSystem: fileSystem, platform: osx);
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
processManager = mocks.MockProcessManager();
|
||||
platform = fakePlatform('macos');
|
||||
platform = FakePlatform(operatingSystem: 'macos');
|
||||
fileSystem = MemoryFileSystem();
|
||||
fileSystem.file(xcodebuild).createSync(recursive: true);
|
||||
terminal = MockAnsiTerminal();
|
||||
@ -125,7 +125,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('xcodebuild isInstalled is false when not on MacOS', () {
|
||||
final Platform platform = fakePlatform('notMacOS');
|
||||
final Platform platform = FakePlatform(operatingSystem: 'notMacOS');
|
||||
xcodeProjectInterpreter = XcodeProjectInterpreter(
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
@ -175,6 +175,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('xcodebuild build settings is empty when xcodebuild failed to get the build settings', () async {
|
||||
platform.environment = Map<String, String>.unmodifiable(<String, String>{});
|
||||
when(processManager.runSync(
|
||||
argThat(contains(xcodebuild)),
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
@ -190,6 +191,7 @@ void main() {
|
||||
flakes: 1,
|
||||
delay: delay + const Duration(seconds: 1),
|
||||
);
|
||||
platform.environment = Map<String, String>.unmodifiable(<String, String>{});
|
||||
|
||||
expect(await xcodeProjectInterpreter.getBuildSettings(
|
||||
'', '', timeout: delay),
|
||||
@ -422,7 +424,7 @@ Information about project "Runner":
|
||||
FakePlatform platform;
|
||||
|
||||
setUp(() {
|
||||
platform = fakePlatform('ignored');
|
||||
platform = FakePlatform();
|
||||
});
|
||||
|
||||
testWithoutContext('environment variables as Xcode build settings', () {
|
||||
@ -447,7 +449,7 @@ Information about project "Runner":
|
||||
fs = MemoryFileSystem();
|
||||
mockArtifacts = MockLocalEngineArtifacts();
|
||||
mockProcessManager = MockProcessManager();
|
||||
macOS = fakePlatform('macos');
|
||||
macOS = FakePlatform(operatingSystem: 'macos');
|
||||
fs.file(xcodebuild).createSync(recursive: true);
|
||||
});
|
||||
|
||||
@ -803,10 +805,6 @@ flutter:
|
||||
});
|
||||
}
|
||||
|
||||
FakePlatform fakePlatform(String name) {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name;
|
||||
}
|
||||
|
||||
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
||||
|
@ -253,8 +253,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('available devices', () {
|
||||
final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
macPlatform.operatingSystem = 'macos';
|
||||
final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
|
||||
|
||||
testWithoutContext('Xcode not installed', () async {
|
||||
when(mockXcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
|
||||
@ -447,8 +446,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('diagnostics', () {
|
||||
final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
|
||||
macPlatform.operatingSystem = 'macos';
|
||||
final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
|
||||
|
||||
testWithoutContext('Xcode not installed', () async {
|
||||
when(mockXcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
|
||||
|
@ -29,6 +29,7 @@ import 'package:process/process.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
|
||||
final Generator kNoColorTerminalPlatform = () {
|
||||
return FakePlatform.fromPlatform(
|
||||
const LocalPlatform()
|
||||
|
Loading…
x
Reference in New Issue
Block a user