Skip to content

Commit

Permalink
Switch to URIs for breakpoints and unskip tests on Windows (#22510)
Browse files Browse the repository at this point in the history
* Switch to URIs for breakpoints and unskip tests on Windows

addBreakpointWithScriptUri expects Uris. By coincidence, FS paths work on Mac/Linux but they fail on Windows. One of the issues in the skip comment is fixed, the other one seems not relevant here.

* Apply symlink resolution to all integration tests

The default temp folders we get include symlinks which breaks breakpoints.

* Save 🙄

* Fix typo
  • Loading branch information
DanTup committed Oct 19, 2018
1 parent bb0290a commit f87a2a3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
Expand Up @@ -6,13 +6,13 @@ import 'dart:async';

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';

import 'package:vm_service_client/vm_service_client.dart';

import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';

void main() {
group('expression evaluation', () {
Expand All @@ -21,7 +21,7 @@ void main() {
FlutterTestDriver _flutter;

setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_expression_test.');
tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir);
});
Expand All @@ -33,13 +33,13 @@ void main() {

Future<VMIsolate> breakInBuildMethod(FlutterTestDriver flutter) async {
return _flutter.breakAt(
_project.buildMethodBreakpointFile,
Uri.file(_project.buildMethodBreakpointFile),
_project.buildMethodBreakpointLine);
}

Future<VMIsolate> breakInTopLevelFunction(FlutterTestDriver flutter) async {
return _flutter.breakAt(
_project.topLevelFunctionBreakpointFile,
Uri.file(_project.topLevelFunctionBreakpointFile),
_project.topLevelFunctionBreakpointLine);
}

Expand Down Expand Up @@ -108,8 +108,5 @@ void main() {
await breakInBuildMethod(_flutter);
await evaluateComplexReturningExpressions();
});
// TODO(dantup): Unskip after flutter-tester is fixed on Windows:
// https://github.com/flutter/flutter/issues/17833.
// https://github.com/flutter/flutter/issues/21348.
}, timeout: const Timeout.factor(6), skip: platform.isWindows);
}, timeout: const Timeout.factor(6));
}
Expand Up @@ -8,14 +8,15 @@ import 'package:flutter_tools/src/base/file_system.dart';
import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';

void main() {
FlutterTestDriver _flutterRun, _flutterAttach;
final BasicProject _project = BasicProject();
Directory tempDir;

setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_attach_test.');
tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir);
_flutterRun = FlutterTestDriver(tempDir, logPrefix: 'RUN');
_flutterAttach = FlutterTestDriver(tempDir, logPrefix: 'ATTACH');
Expand Down
Expand Up @@ -9,14 +9,15 @@ import 'package:process/process.dart';

import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_utils.dart';

void main() {
group('flutter_run', () {
Directory tempDir;
final BasicProject _project = BasicProject();

setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_run_integration_test.');
tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir);
});

Expand Down
9 changes: 4 additions & 5 deletions packages/flutter_tools/test/integration/hot_reload_test.dart
Expand Up @@ -9,6 +9,7 @@ import 'package:vm_service_client/vm_service_client.dart';
import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';

void main() {
group('hot', () {
Expand All @@ -17,7 +18,7 @@ void main() {
FlutterTestDriver _flutter;

setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_hot_reload_test_app.');
tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir);
});
Expand All @@ -37,12 +38,10 @@ void main() {
await _flutter.hotRestart();
});

test('reload hits breakpoints with file:// prefixes after reload', () async {
test('reload hits breakpoints after reload', () async {
await _flutter.run(withDebugger: true);

// Hit breakpoint using a file:// URI.
final VMIsolate isolate = await _flutter.breakAt(
Uri.file(_project.breakpointFile).toString(),
Uri.file(_project.breakpointFile),
_project.breakpointLine);
expect(isolate.pauseEvent, isInstanceOf<VMPauseBreakpointEvent>());
});
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_tools/test/integration/lifetime_test.dart
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';

/// This duration is arbitrary but is ideally:
/// a) long enough to ensure that if the app is crashing at startup, we notice
Expand All @@ -23,7 +24,7 @@ void main() {
Directory tempDir;

setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_lifetime_test.');
tempDir = createResolvedTempDirectorySync();
await _project.setUpIn(tempDir);
_flutter = FlutterTestDriver(tempDir);
});
Expand Down
Expand Up @@ -16,8 +16,8 @@ abstract class TestProject {
String get main;

// Valid locations for a breakpoint for tests that just need to break somewhere.
String get breakpointFile => fs.file(fs.path.join(
dir.path, 'lib', 'main.dart')).resolveSymbolicLinksSync();
String get breakpointFile => fs.path.join(
dir.path, 'lib', 'main.dart');
int get breakpointLine => lineContaining(main, '// BREAKPOINT');

Future<void> setUpIn(Directory dir) async {
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter_tools/test/integration/test_driver.dart
Expand Up @@ -237,10 +237,10 @@ class FlutterTestDriver {
return await vm.isolates.single.load();
}

Future<void> addBreakpoint(String path, int line) async {
Future<void> addBreakpoint(Uri uri, int line) async {
final VMIsolate isolate = await getFlutterIsolate();
_debugPrint('Sending breakpoint for $path:$line');
await isolate.addBreakpoint(path, line);
_debugPrint('Sending breakpoint for $uri:$line');
await isolate.addBreakpoint(uri, line);
}

Future<VMIsolate> waitForPause() async {
Expand All @@ -266,15 +266,15 @@ class FlutterTestDriver {
return wait ? waitForPause() : null;
}

Future<VMIsolate> breakAt(String path, int line, { bool restart = false }) async {
Future<VMIsolate> breakAt(Uri uri, int line, { bool restart = false }) async {
if (restart) {
// For a hot restart, we need to send the breakpoints after the restart
// so we need to pause during the restart to avoid races.
await hotRestart(pause: true);
await addBreakpoint(path, line);
await addBreakpoint(uri, line);
return resume();
} else {
await addBreakpoint(path, line);
await addBreakpoint(uri, line);
await hotReload();
return waitForPause();
}
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter_tools/test/integration/test_utils.dart
Expand Up @@ -11,6 +11,14 @@ import 'package:flutter_tools/src/base/process_manager.dart';

import '../src/common.dart';

/// Creates a temporary directory but resolves any symlinks to return the real
/// underlying path to avoid issues with breakpoints/hot reload.
/// https://github.com/flutter/flutter/pull/21741
Directory createResolvedTempDirectorySync() {
final Directory tempDir = fs.systemTempDirectory.createTempSync('flutter_expression_test.');
return fs.directory(tempDir.resolveSymbolicLinksSync());
}

void writeFile(String path, String content) {
fs.file(path)
..createSync(recursive: true)
Expand Down

0 comments on commit f87a2a3

Please sign in to comment.