From 2a679bd858ea39fcc156a8ff93191c0f3bc749bd Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 25 Jul 2018 15:31:57 +0100 Subject: [PATCH] Look up breakpoints rather than relying on magic numbers (#19708) * Look up breakpoints rather than relying on magic numbers * Make breakpoint comment more obvious --- .../test/integration/test_data/basic_project.dart | 15 +++++---------- .../test/integration/test_data/test_project.dart | 11 +++++++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/test/integration/test_data/basic_project.dart b/packages/flutter_tools/test/integration/test_data/basic_project.dart index d8cf9e44c5..e436d07629 100644 --- a/packages/flutter_tools/test/integration/test_data/basic_project.dart +++ b/packages/flutter_tools/test/integration/test_data/basic_project.dart @@ -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'); } diff --git a/packages/flutter_tools/test/integration/test_data/test_project.dart b/packages/flutter_tools/test/integration/test_data/test_project.dart index 7dfb9cfebd..af825d261b 100644 --- a/packages/flutter_tools/test/integration/test_data/test_project.dart +++ b/packages/flutter_tools/test/integration/test_data/test_project.dart @@ -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 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; + } }