Unverified Commit 15e3df25 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Refactor Test Driver in preparation for `flutter test` integration tests (#24060)

* Refactor Test Driver in preperation for `flutter test` integration tests

* Fix indent
parent 113f8f1a
...@@ -15,15 +15,15 @@ import 'test_driver.dart'; ...@@ -15,15 +15,15 @@ import 'test_driver.dart';
import 'test_utils.dart'; import 'test_utils.dart';
void main() { void main() {
group('expression evaluation', () { group('flutter run expression evaluation', () {
Directory tempDir; Directory tempDir;
final BasicProject _project = BasicProject(); final BasicProject _project = BasicProject();
FlutterTestDriver _flutter; FlutterRunTestDriver _flutter;
setUp(() async { setUp(() async {
tempDir = createResolvedTempDirectorySync(); tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir); await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir); _flutter = FlutterRunTestDriver(tempDir);
}); });
tearDown(() async { tearDown(() async {
...@@ -43,70 +43,70 @@ void main() { ...@@ -43,70 +43,70 @@ void main() {
_project.topLevelFunctionBreakpointLine); _project.topLevelFunctionBreakpointLine);
} }
Future<void> evaluateTrivialExpressions() async {
InstanceRef res;
res = await _flutter.evaluateInFrame('"test"');
expect(res.kind == InstanceKind.kString && res.valueAsString == 'test', isTrue);
res = await _flutter.evaluateInFrame('1');
expect(res.kind == InstanceKind.kInt && res.valueAsString == 1.toString(), isTrue);
res = await _flutter.evaluateInFrame('true');
expect(res.kind == InstanceKind.kBool && res.valueAsString == true.toString(), isTrue);
}
Future<void> evaluateComplexExpressions() async {
final InstanceRef res = await _flutter.evaluateInFrame('new DateTime.now().year');
expect(res.kind == InstanceKind.kInt && res.valueAsString == DateTime.now().year.toString(), isTrue);
}
Future<void> evaluateComplexReturningExpressions() async {
final DateTime now = DateTime.now();
final InstanceRef resp = await _flutter.evaluateInFrame('new DateTime.now()');
expect(resp.classRef.name, equals('DateTime'));
// Ensure we got a reasonable approximation. The more accurate we try to
// make this, the more likely it'll fail due to differences in the time
// in the remote VM and the local VM at the time the code runs.
final InstanceRef res = await _flutter.evaluate(resp.id, r'"$year-$month-$day"');
expect(res.valueAsString,
equals('${now.year}-${now.month}-${now.day}'));
}
test('can evaluate trivial expressions in top level function', () async { test('can evaluate trivial expressions in top level function', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInTopLevelFunction(_flutter); await breakInTopLevelFunction(_flutter);
await evaluateTrivialExpressions(); await evaluateTrivialExpressions(_flutter);
}); });
test('can evaluate trivial expressions in build method', () async { test('can evaluate trivial expressions in build method', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInBuildMethod(_flutter); await breakInBuildMethod(_flutter);
await evaluateTrivialExpressions(); await evaluateTrivialExpressions(_flutter);
}); });
test('can evaluate complex expressions in top level function', () async { test('can evaluate complex expressions in top level function', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInTopLevelFunction(_flutter); await breakInTopLevelFunction(_flutter);
await evaluateComplexExpressions(); await evaluateComplexExpressions(_flutter);
}); });
test('can evaluate complex expressions in build method', () async { test('can evaluate complex expressions in build method', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInBuildMethod(_flutter); await breakInBuildMethod(_flutter);
await evaluateComplexExpressions(); await evaluateComplexExpressions(_flutter);
}); });
test('can evaluate expressions returning complex objects in top level function', () async { test('can evaluate expressions returning complex objects in top level function', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInTopLevelFunction(_flutter); await breakInTopLevelFunction(_flutter);
await evaluateComplexReturningExpressions(); await evaluateComplexReturningExpressions(_flutter);
}); });
test('can evaluate expressions returning complex objects in build method', () async { test('can evaluate expressions returning complex objects in build method', () async {
await _flutter.run(withDebugger: true); await _flutter.run(withDebugger: true);
await breakInBuildMethod(_flutter); await breakInBuildMethod(_flutter);
await evaluateComplexReturningExpressions(); await evaluateComplexReturningExpressions(_flutter);
}); });
}, timeout: const Timeout.factor(6)); }, timeout: const Timeout.factor(6));
} }
Future<void> evaluateTrivialExpressions(FlutterTestDriver flutter) async {
InstanceRef res;
res = await flutter.evaluateInFrame('"test"');
expect(res.kind == InstanceKind.kString && res.valueAsString == 'test', isTrue);
res = await flutter.evaluateInFrame('1');
expect(res.kind == InstanceKind.kInt && res.valueAsString == 1.toString(), isTrue);
res = await flutter.evaluateInFrame('true');
expect(res.kind == InstanceKind.kBool && res.valueAsString == true.toString(), isTrue);
}
Future<void> evaluateComplexExpressions(FlutterTestDriver flutter) async {
final InstanceRef res = await flutter.evaluateInFrame('new DateTime.now().year');
expect(res.kind == InstanceKind.kInt && res.valueAsString == DateTime.now().year.toString(), isTrue);
}
Future<void> evaluateComplexReturningExpressions(FlutterTestDriver flutter) async {
final DateTime now = DateTime.now();
final InstanceRef resp = await flutter.evaluateInFrame('new DateTime.now()');
expect(resp.classRef.name, equals('DateTime'));
// Ensure we got a reasonable approximation. The more accurate we try to
// make this, the more likely it'll fail due to differences in the time
// in the remote VM and the local VM at the time the code runs.
final InstanceRef res = await flutter.evaluate(resp.id, r'"$year-$month-$day"');
expect(res.valueAsString,
equals('${now.year}-${now.month}-${now.day}'));
}
...@@ -11,15 +11,15 @@ import 'test_driver.dart'; ...@@ -11,15 +11,15 @@ import 'test_driver.dart';
import 'test_utils.dart'; import 'test_utils.dart';
void main() { void main() {
FlutterTestDriver _flutterRun, _flutterAttach; FlutterRunTestDriver _flutterRun, _flutterAttach;
final BasicProject _project = BasicProject(); final BasicProject _project = BasicProject();
Directory tempDir; Directory tempDir;
setUp(() async { setUp(() async {
tempDir = createResolvedTempDirectorySync(); tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir); await _project.setUpIn(tempDir);
_flutterRun = FlutterTestDriver(tempDir, logPrefix: 'RUN'); _flutterRun = FlutterRunTestDriver(tempDir, logPrefix: 'RUN');
_flutterAttach = FlutterTestDriver(tempDir, logPrefix: 'ATTACH'); _flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH');
}); });
tearDown(() async { tearDown(() async {
...@@ -54,7 +54,7 @@ void main() { ...@@ -54,7 +54,7 @@ void main() {
await _flutterRun.run(withDebugger: true); await _flutterRun.run(withDebugger: true);
await _flutterAttach.attach(_flutterRun.vmServicePort); await _flutterAttach.attach(_flutterRun.vmServicePort);
await _flutterAttach.quit(); await _flutterAttach.quit();
_flutterAttach = FlutterTestDriver(tempDir, logPrefix: 'ATTACH-2'); _flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH-2');
await _flutterAttach.attach(_flutterRun.vmServicePort); await _flutterAttach.attach(_flutterRun.vmServicePort);
await _flutterAttach.hotReload(); await _flutterAttach.hotReload();
}); });
......
...@@ -16,12 +16,12 @@ void main() { ...@@ -16,12 +16,12 @@ void main() {
group('flutter_run', () { group('flutter_run', () {
Directory tempDir; Directory tempDir;
final BasicProject _project = BasicProject(); final BasicProject _project = BasicProject();
FlutterTestDriver _flutter; FlutterRunTestDriver _flutter;
setUp(() async { setUp(() async {
tempDir = createResolvedTempDirectorySync(); tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir); await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir); _flutter = FlutterRunTestDriver(tempDir);
}); });
tearDown(() async { tearDown(() async {
......
...@@ -17,12 +17,12 @@ void main() { ...@@ -17,12 +17,12 @@ void main() {
group('hot', () { group('hot', () {
Directory tempDir; Directory tempDir;
final HotReloadProject _project = HotReloadProject(); final HotReloadProject _project = HotReloadProject();
FlutterTestDriver _flutter; FlutterRunTestDriver _flutter;
setUp(() async { setUp(() async {
tempDir = createResolvedTempDirectorySync(); tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir); await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir); _flutter = FlutterRunTestDriver(tempDir);
}); });
tearDown(() async { tearDown(() async {
......
...@@ -20,13 +20,13 @@ const Duration requiredLifespan = Duration(seconds: 5); ...@@ -20,13 +20,13 @@ const Duration requiredLifespan = Duration(seconds: 5);
void main() { void main() {
group('flutter run', () { group('flutter run', () {
final BasicProject _project = BasicProject(); final BasicProject _project = BasicProject();
FlutterTestDriver _flutter; FlutterRunTestDriver _flutter;
Directory tempDir; Directory tempDir;
setUp(() async { setUp(() async {
tempDir = createResolvedTempDirectorySync(); tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir); await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir); _flutter = FlutterRunTestDriver(tempDir);
}); });
tearDown(() async { tearDown(() async {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'test_project.dart'; import 'project.dart';
class BasicProject extends TestProject { class BasicProject extends Project {
@override @override
final String pubspec = ''' final String pubspec = '''
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import '../test_utils.dart'; import '../test_utils.dart';
import 'test_project.dart'; import 'project.dart';
class HotReloadProject extends TestProject { class HotReloadProject extends Project {
@override @override
final String pubspec = ''' final String pubspec = '''
name: test name: test
......
...@@ -9,7 +9,7 @@ import 'package:flutter_tools/src/base/file_system.dart'; ...@@ -9,7 +9,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import '../test_utils.dart'; import '../test_utils.dart';
abstract class TestProject { abstract class Project {
Directory dir; Directory dir;
String get pubspec; String get pubspec;
...@@ -22,7 +22,9 @@ abstract class TestProject { ...@@ -22,7 +22,9 @@ abstract class TestProject {
Future<void> setUpIn(Directory dir) async { Future<void> setUpIn(Directory dir) async {
this.dir = dir; this.dir = dir;
writeFile(fs.path.join(dir.path, 'pubspec.yaml'), pubspec); writeFile(fs.path.join(dir.path, 'pubspec.yaml'), pubspec);
if (main != null) {
writeFile(fs.path.join(dir.path, 'lib', 'main.dart'), main); writeFile(fs.path.join(dir.path, 'lib', 'main.dart'), main);
}
await getPackages(dir.path); await getPackages(dir.path);
} }
......
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