Skip to content

Commit f625316

Browse files
committed
Let Device.runIntegrationTest return a string
1 parent ecf5d65 commit f625316

File tree

5 files changed

+46
-60
lines changed

5 files changed

+46
-60
lines changed

tools/lib/src/device.dart

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import 'dart:io' as io;
88

99
import 'package:file/file.dart';
1010
import 'package:flutter_plugin_tools/src/common/core.dart';
11-
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
1211
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
1312

1413
import 'process_runner_apis.dart';
1514
import 'tizen_sdk.dart';
1615

17-
export 'package:flutter_plugin_tools/src/common/package_looping_command.dart'
18-
show PackageResult, RunState;
19-
2016
/// A reference to a Tizen device (either physical or emulator) that can run
2117
/// Flutter applications.
2218
///
@@ -114,24 +110,19 @@ class Device {
114110

115111
/// Runs integration test in [workingDir].
116112
///
117-
/// [workingDir] must be a valid exisiting flutter directory where
118-
/// `flutter pub get` has already been ran succesfully. For an app project,
113+
/// [workingDir] must be a valid existing Flutter project directory where
114+
/// `flutter pub get` has already been run succesfully. For an app project,
119115
/// [workingDir] is the app's source root. For a plugin project, [workingDir]
120116
/// is one of the example directories.
121117
///
122-
/// If test doesn't finish after [timeout], it's considered a failure and the
123-
/// function will return [PackageResult.fail] with time expired log.
124-
///
125-
/// Returns [PackageResult.success] when every test passes succesfully,
126-
/// otherwise returns [PackageResult.fail]. Never returns [PackageResult.skip]
127-
/// nor [PackageResult.exclude].
128-
Future<PackageResult> runIntegrationTest(
118+
/// Returns null if all tests have passed successfully before [timeout],
119+
/// otherwise returns a string with the error details.
120+
Future<String?> runIntegrationTest(
129121
Directory workingDir,
130122
Duration timeout,
131123
) async {
132124
if (!isConnected) {
133-
return PackageResult.fail(
134-
<String>['Device $name ($profile) is not connected.']);
125+
return 'Device $name ($profile) is not connected.';
135126
}
136127

137128
final io.Process process = await _processRunner.start(
@@ -166,30 +157,27 @@ class Device {
166157
// guarantee that all buffered outputs of the process have returned.
167158
await completer.future;
168159

169-
final List<String> errors = <String>[];
160+
String? error;
170161
if (timedOut) {
171-
errors.add('Timeout expired. The test may need more time to finish. '
162+
error = 'Timeout expired. The test may need more time to finish. '
172163
'If you expect the test to finish before timeout, check if the tests '
173164
'require device screen to be awake or if they require manually '
174-
'clicking the UI button for permissions.');
165+
'clicking the UI button for permissions.';
175166
} else if (lastLine.startsWith('No tests ran')) {
176-
errors.add(
177-
'Missing integration tests (use --exclude if this is intentional).');
167+
error =
168+
'Missing integration tests (use --exclude if this is intentional).';
178169
} else if (lastLine.startsWith('No devices found')) {
179-
errors.add('Device was disconnected during test.');
170+
error = 'Device was disconnected during test.';
180171
} else {
181172
final RegExpMatch? match = _logPattern.firstMatch(lastLine);
182173
if (match == null || match.group(2) == null) {
183-
throw Exception('Log message is not parsed correctly.');
174+
error = 'Could not parse the log output.';
184175
} else if (!match.group(2)!.startsWith('All tests passed!')) {
185-
errors.add('flutter-tizen test integration_test failed, see the output '
186-
'above for details.');
176+
error = 'flutter-tizen test integration_test failed, see the output '
177+
'above for details.';
187178
}
188179
}
189-
190-
return errors.isEmpty
191-
? PackageResult.success()
192-
: PackageResult.fail(errors);
180+
return error;
193181
}
194182
}
195183

@@ -240,6 +228,7 @@ class EmulatorDevice extends Device {
240228
final io.ProcessResult result =
241229
_processRunner.runSync(_tizenSdk.emCli.path, <String>['list-vm']);
242230
if (result.exitCode != 0) {
231+
print('Error: Unable to list available emulators.');
243232
throw ToolExit(result.exitCode);
244233
}
245234

@@ -377,7 +366,7 @@ class EmulatorDevice extends Device {
377366
Future<void> _poll(
378367
FutureOr<bool> Function() function, {
379368
Duration interval = const Duration(seconds: 1),
380-
Duration timeout = const Duration(minutes: 10),
369+
Duration timeout = const Duration(minutes: 5),
381370
}) async {
382371
final DateTime start = DateTime.now();
383372
while (DateTime.now().difference(start) <= timeout) {
@@ -390,7 +379,7 @@ class EmulatorDevice extends Device {
390379
}
391380

392381
@override
393-
Future<PackageResult> runIntegrationTest(
382+
Future<String?> runIntegrationTest(
394383
Directory workingDir,
395384
Duration timeout,
396385
) async {

tools/lib/src/integration_test_command.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,14 @@ class IntegrationTestCommand extends PackageLoopingCommand {
224224
}
225225

226226
for (final Device device in devices) {
227-
PackageResult packageResult =
227+
String? error =
228228
await device.runIntegrationTest(example.directory, _timeout);
229-
if (packageResult.state == RunState.failed) {
229+
if (error != null) {
230230
// Tests may fail unexpectedly on a self-hosted runner. Try again.
231-
packageResult =
232-
await device.runIntegrationTest(example.directory, _timeout);
231+
error = await device.runIntegrationTest(example.directory, _timeout);
233232
}
234-
if (packageResult.state == RunState.failed) {
235-
errors.addAll(packageResult.details);
233+
if (error != null) {
234+
errors.add(error);
236235
}
237236
}
238237
}

tools/lib/src/tizen_sdk.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class TizenSdk {
178178
if (tizenHomeDir == null || !tizenHomeDir.existsSync()) {
179179
print(
180180
'Error: Unable to locate Tizen SDK.\n'
181-
'If the Tizen SDK has been installed to a custom location, set TIZEN_SDK to that location.',
181+
'If the Tizen SDK has been installed to a custom location, set $_kTizenSdk to that location.',
182182
);
183183
throw ToolExit(exitCommandFoundErrors);
184184
}
@@ -271,7 +271,7 @@ String? findEmulatorPid(String name) {
271271
final io.ProcessResult result = processRunner.runSync('ps', <String>['aux']);
272272

273273
if (result.exitCode != 0) {
274-
print('Error: running the command `ps aux` failed.');
274+
print('Error: Unable to list running processes.');
275275
throw ToolExit(result.exitCode);
276276
}
277277

tools/test/device_test.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ void main() {
6666
Future<void>.delayed(Duration(seconds: timeoutLimit.inSeconds + 1), () {
6767
controller.close();
6868
});
69-
final PackageResult result = await device.runIntegrationTest(
69+
final String? error = await device.runIntegrationTest(
7070
fileSystem.systemTempDirectory,
7171
timeoutLimit,
7272
);
73-
expect(result.state, RunState.failed);
74-
expect(result.details.first.contains('Timeout expired'), true);
73+
expect(error, isNotNull);
74+
expect(error!.contains('Timeout expired'), true);
7575
});
7676

7777
test('correctly parses log "No tests ran"', () async {
@@ -83,12 +83,12 @@ void main() {
8383
controller.close();
8484
},
8585
);
86-
final PackageResult result = await device.runIntegrationTest(
86+
final String? error = await device.runIntegrationTest(
8787
fileSystem.systemTempDirectory,
8888
timeoutLimit,
8989
);
90-
expect(result.state, RunState.failed);
91-
expect(result.details.first.contains('Missing integration tests'), true);
90+
expect(error, isNotNull);
91+
expect(error!.contains('Missing integration tests'), true);
9292
});
9393

9494
test('correctly parses log "No devices found"', () async {
@@ -100,14 +100,12 @@ void main() {
100100
controller.close();
101101
},
102102
);
103-
final PackageResult result = await device.runIntegrationTest(
103+
final String? error = await device.runIntegrationTest(
104104
fileSystem.systemTempDirectory,
105105
timeoutLimit,
106106
);
107-
expect(result.state, RunState.failed);
108-
expect(
109-
result.details.first.contains('Device was disconnected during test'),
110-
true);
107+
expect(error, isNotNull);
108+
expect(error!.contains('Device was disconnected during test'), true);
111109
});
112110

113111
test('correctly parses log "All tests passed!"', () async {
@@ -119,11 +117,11 @@ void main() {
119117
controller.close();
120118
},
121119
);
122-
final PackageResult result = await device.runIntegrationTest(
120+
final String? error = await device.runIntegrationTest(
123121
fileSystem.systemTempDirectory,
124122
timeoutLimit,
125123
);
126-
expect(result.state, RunState.succeeded);
124+
expect(error, isNull);
127125
});
128126

129127
test('correctly parses log "Some tests failed"', () async {
@@ -135,14 +133,13 @@ void main() {
135133
controller.close();
136134
},
137135
);
138-
final PackageResult result = await device.runIntegrationTest(
136+
final String? error = await device.runIntegrationTest(
139137
fileSystem.systemTempDirectory,
140138
timeoutLimit,
141139
);
142-
expect(result.state, RunState.failed);
140+
expect(error, isNotNull);
143141
expect(
144-
result.details.first
145-
.contains('flutter-tizen test integration_test failed'),
142+
error!.contains('flutter-tizen test integration_test failed'),
146143
true,
147144
);
148145
});

tools/test/integration/device_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ Future<void> _checkSystemRequirements(String emulatorName) async {
3434
.map((String token) => token.trim())
3535
.toList();
3636
if (names.contains(emulatorName)) {
37-
throw Exception('Emulator name used for test already exists: $emulatorName. '
38-
'Emulator name is randomly generated each test, rerun test to '
39-
'choose a different name.');
37+
throw Exception(
38+
'Emulator name used for test already exists: $emulatorName. '
39+
'Emulator name is randomly generated for each test. '
40+
'Rerun the test to choose a different name.');
4041
}
4142

4243
result = await io.Process.run('flutter-tizen', <String>['-v']);
@@ -95,12 +96,12 @@ void main() {
9596
await io.Process.run('flutter-tizen', <String>['pub', 'get'],
9697
workingDirectory: testDataDir.parent.absolute.path);
9798

98-
final PackageResult result = await device.runIntegrationTest(
99+
final String? error = await device.runIntegrationTest(
99100
testDataDir, const Duration(seconds: 60));
100101

101102
await io.Process.run('flutter-tizen', <String>['clean'],
102103
workingDirectory: testDataDir.parent.absolute.path);
103-
expect(result.state, RunState.succeeded);
104+
expect(error, isNull);
104105
});
105106

106107
tearDown(() async {

0 commit comments

Comments
 (0)