Unverified Commit 2a679bd8 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Look up breakpoints rather than relying on magic numbers (#19708)

* Look up breakpoints rather than relying on magic numbers

* Make breakpoint comment more obvious
parent bdf0dd46
......@@ -26,7 +26,7 @@ class BasicProject extends TestProject {
@override
Widget build(BuildContext context) {
topLevelFunction();
return new MaterialApp(
return new MaterialApp( // BREAKPOINT
title: 'Flutter Demo',
home: new Container(),
);
......@@ -34,18 +34,13 @@ class BasicProject extends TestProject {
}
topLevelFunction() {
print("test");
print("topLevelFunction"); // TOP LEVEL BREAKPOINT
}
''';
@override
String get breakpointFile => buildMethodBreakpointFile;
@override
int get breakpointLine => buildMethodBreakpointLine;
String get buildMethodBreakpointFile => fs.path.join(dir.path, 'lib', 'main.dart');
int get buildMethodBreakpointLine => 9;
String get buildMethodBreakpointFile => breakpointFile;
int get buildMethodBreakpointLine => breakpointLine;
String get topLevelFunctionBreakpointFile => fs.path.join(dir.path, 'lib', 'main.dart');
int get topLevelFunctionBreakpointLine => 17;
int get topLevelFunctionBreakpointLine => lineContaining(main, '// TOP LEVEL BREAKPOINT');
}
......@@ -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;
int get breakpointLine;
String get breakpointFile => fs.path.join(dir.path, 'lib', 'main.dart');
int get breakpointLine => lineContaining(main, '// BREAKPOINT');
Future<void> setUpIn(Directory dir) async {
this.dir = dir;
......@@ -29,4 +29,11 @@ abstract class TestProject {
void cleanup() {
dir?.deleteSync(recursive: true);
}
int lineContaining(String contents, String search) {
final int index = contents.split('\n').indexWhere((String l) => l.contains(search));
if (index == -1)
throw new Exception("Did not find '$search' inside the file");
return index;
}
}
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