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 { ...@@ -26,7 +26,7 @@ class BasicProject extends TestProject {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
topLevelFunction(); topLevelFunction();
return new MaterialApp( return new MaterialApp( // BREAKPOINT
title: 'Flutter Demo', title: 'Flutter Demo',
home: new Container(), home: new Container(),
); );
...@@ -34,18 +34,13 @@ class BasicProject extends TestProject { ...@@ -34,18 +34,13 @@ class BasicProject extends TestProject {
} }
topLevelFunction() { topLevelFunction() {
print("test"); print("topLevelFunction"); // TOP LEVEL BREAKPOINT
} }
'''; ''';
@override String get buildMethodBreakpointFile => breakpointFile;
String get breakpointFile => buildMethodBreakpointFile; int get buildMethodBreakpointLine => breakpointLine;
@override
int get breakpointLine => buildMethodBreakpointLine;
String get buildMethodBreakpointFile => fs.path.join(dir.path, 'lib', 'main.dart');
int get buildMethodBreakpointLine => 9;
String get topLevelFunctionBreakpointFile => fs.path.join(dir.path, 'lib', 'main.dart'); 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 { ...@@ -16,8 +16,8 @@ abstract class TestProject {
String get main; String get main;
// Valid locations for a breakpoint for tests that just need to break somewhere. // Valid locations for a breakpoint for tests that just need to break somewhere.
String get breakpointFile; String get breakpointFile => fs.path.join(dir.path, 'lib', 'main.dart');
int get breakpointLine; int get breakpointLine => lineContaining(main, '// BREAKPOINT');
Future<void> setUpIn(Directory dir) async { Future<void> setUpIn(Directory dir) async {
this.dir = dir; this.dir = dir;
...@@ -29,4 +29,11 @@ abstract class TestProject { ...@@ -29,4 +29,11 @@ abstract class TestProject {
void cleanup() { void cleanup() {
dir?.deleteSync(recursive: true); 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