Unverified Commit 97127730 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Fill in Fuchsia version string (#34516)

parent 8418daae
......@@ -358,7 +358,20 @@ class FuchsiaDevice extends Device {
Future<TargetPlatform> get targetPlatform async => TargetPlatform.fuchsia;
@override
Future<String> get sdkNameAndVersion async => 'Fuchsia';
Future<String> get sdkNameAndVersion async {
const String versionPath = '/pkgfs/packages/build-info/0/data/version';
final RunResult catResult = await shell('cat $versionPath');
if (catResult.exitCode != 0) {
printTrace('Failed to cat $versionPath: ${catResult.stderr}');
return 'Fuchsia';
}
final String version = catResult.stdout.trim();
if (version.isEmpty) {
printTrace('$versionPath was empty');
return 'Fuchsia';
}
return 'Fuchsia $version';
}
@override
DeviceLogReader getLogReader({ApplicationPackage app}) =>
......
......@@ -571,6 +571,69 @@ void main() {
});
});
group('sdkNameAndVersion: ', () {
MockFile sshConfig;
MockProcessManager mockSuccessProcessManager;
MockProcessResult mockSuccessProcessResult;
MockProcessManager mockFailureProcessManager;
MockProcessResult mockFailureProcessResult;
MockProcessManager emptyStdoutProcessManager;
MockProcessResult emptyStdoutProcessResult;
setUp(() {
sshConfig = MockFile();
when(sshConfig.absolute).thenReturn(sshConfig);
mockSuccessProcessManager = MockProcessManager();
mockSuccessProcessResult = MockProcessResult();
when(mockSuccessProcessManager.run(any)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(mockSuccessProcessResult));
when(mockSuccessProcessResult.exitCode).thenReturn(0);
when<String>(mockSuccessProcessResult.stdout).thenReturn('version');
when<String>(mockSuccessProcessResult.stderr).thenReturn('');
mockFailureProcessManager = MockProcessManager();
mockFailureProcessResult = MockProcessResult();
when(mockFailureProcessManager.run(any)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(mockFailureProcessResult));
when(mockFailureProcessResult.exitCode).thenReturn(1);
when<String>(mockFailureProcessResult.stdout).thenReturn('');
when<String>(mockFailureProcessResult.stderr).thenReturn('');
emptyStdoutProcessManager = MockProcessManager();
emptyStdoutProcessResult = MockProcessResult();
when(emptyStdoutProcessManager.run(any)).thenAnswer((Invocation invocation) =>
Future<ProcessResult>.value(emptyStdoutProcessResult));
when(emptyStdoutProcessResult.exitCode).thenReturn(0);
when<String>(emptyStdoutProcessResult.stdout).thenReturn('');
when<String>(emptyStdoutProcessResult.stderr).thenReturn('');
});
testUsingContext('returns what we get from the device on success', () async {
final FuchsiaDevice device = FuchsiaDevice('123');
expect(await device.sdkNameAndVersion, equals('Fuchsia version'));
}, overrides: <Type, Generator>{
ProcessManager: () => mockSuccessProcessManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
});
testUsingContext('returns "Fuchsia" when device command fails', () async {
final FuchsiaDevice device = FuchsiaDevice('123');
expect(await device.sdkNameAndVersion, equals('Fuchsia'));
}, overrides: <Type, Generator>{
ProcessManager: () => mockFailureProcessManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
});
testUsingContext('returns "Fuchsia" when device gives an empty result', () async {
final FuchsiaDevice device = FuchsiaDevice('123');
expect(await device.sdkNameAndVersion, equals('Fuchsia'));
}, overrides: <Type, Generator>{
ProcessManager: () => emptyStdoutProcessManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
});
});
}
class FuchsiaModulePackage extends ApplicationPackage {
......
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