22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- @Tags (< String > ['flutter-test-driver' ])
6- library ;
7-
85import 'package:file/file.dart' ;
96import 'package:vm_service/vm_service.dart' ;
107
11- import '../integration.shard/test_data/basic_project.dart' ;
12- import '../integration.shard/test_data/tests_project.dart' ;
13- import '../integration.shard/test_driver.dart' ;
14- import '../integration.shard/test_utils.dart' ;
15- import '../src/common.dart' ;
8+ import '../../integration.shard/test_data/basic_project.dart' ;
9+ import '../../integration.shard/test_data/tests_project.dart' ;
10+ import '../../integration.shard/test_driver.dart' ;
11+ import '../../integration.shard/test_utils.dart' ;
12+ import '../../src/common.dart' ;
13+
14+ // Created here as multiple groups use it.
15+ final RegExp stackTraceCurrentRegexp = RegExp (r'\.dart\s+[0-9]+:[0-9]+\s+get current' );
1616
17- void main () {
17+ Future < void > testAll ({ required bool useDDCLibraryBundleFormat}) async {
1818 group ('Flutter run for web' , () {
1919 final BasicProject project = BasicProject ();
2020 late Directory tempDir;
@@ -42,7 +42,10 @@ void main() {
4242 withDebugger: true ,
4343 chrome: true ,
4444 expressionEvaluation: expressionEvaluation,
45- additionalCommandArgs: < String > ['--verbose' ],
45+ additionalCommandArgs: < String > [
46+ '--verbose' ,
47+ if (useDDCLibraryBundleFormat) '--web-experimental-hot-reload' ,
48+ ],
4649 );
4750 }
4851
@@ -113,6 +116,27 @@ void main() {
113116 await start (expressionEvaluation: true );
114117 await evaluateWebLibraryBooleanFromEnvironmentInLibrary (flutter);
115118 });
119+
120+ testWithoutContext ('evaluated expression includes correctly mapped stack trace' , () async {
121+ await start (expressionEvaluation: true );
122+ await breakInTopLevelFunction (flutter);
123+ // Test that the call comes from some Dart getter called `current` (the
124+ // location of which will be compiler-specific) and that the lines and
125+ // file name of the current location is correct and reports a Dart path.
126+ await evaluateStackTraceCurrent (flutter, (String stackTrace) {
127+ final Iterable <RegExpMatch > matches = stackTraceCurrentRegexp.allMatches (stackTrace);
128+ if (matches.length != 1 ) {
129+ return false ;
130+ }
131+ int end = matches.first.end;
132+ end = stackTrace.indexOf ('package:test/main.dart 24:5' , end);
133+ if (end == - 1 ) {
134+ return false ;
135+ }
136+ end = stackTrace.indexOf ('package:test/main.dart 15:7' , end);
137+ return end != - 1 ;
138+ });
139+ });
116140 });
117141
118142 group ('Flutter test for web' , () {
@@ -181,6 +205,20 @@ void main() {
181205 await startPaused (expressionEvaluation: true );
182206 await evaluateWebLibraryBooleanFromEnvironmentInLibrary (flutter);
183207 });
208+
209+ testWithoutContext ('evaluated expression includes correctly mapped stack trace' , () async {
210+ await startPaused (expressionEvaluation: true );
211+ await breakInMethod (flutter);
212+ await evaluateStackTraceCurrent (flutter, (String stackTrace) {
213+ final Iterable <RegExpMatch > matches = stackTraceCurrentRegexp.allMatches (stackTrace);
214+ if (matches.length != 1 ) {
215+ return false ;
216+ }
217+ int end = matches.first.end;
218+ end = stackTrace.indexOf ('test.dart 6:9' , end);
219+ return end != - 1 ;
220+ });
221+ });
184222 });
185223}
186224
@@ -246,6 +284,15 @@ Future<void> evaluateWebLibraryBooleanFromEnvironmentInLibrary(FlutterTestDriver
246284 expectInstance (res, InstanceKind .kBool, true .toString ());
247285}
248286
287+ Future <void > evaluateStackTraceCurrent (
288+ FlutterTestDriver flutter,
289+ bool Function (String ) matchStackTraces,
290+ ) async {
291+ final LibraryRef library = await getRootLibrary (flutter);
292+ final ObjRef res = await flutter.evaluate (library.id! , 'StackTrace.current.toString()' );
293+ expectInstance (res, InstanceKind .kString, predicate (matchStackTraces));
294+ }
295+
249296Future <LibraryRef > getRootLibrary (FlutterTestDriver flutter) async {
250297 // `isolate.rootLib` returns incorrect library, so find the
251298 // entrypoint manually here instead.
@@ -255,12 +302,12 @@ Future<LibraryRef> getRootLibrary(FlutterTestDriver flutter) async {
255302 return isolate.libraries! .firstWhere ((LibraryRef l) => l.uri! .contains ('org-dartlang-app' ));
256303}
257304
258- void expectInstance (ObjRef result, String kind, String message ) {
305+ void expectInstance (ObjRef result, String kind, Object matcher ) {
259306 expect (
260307 result,
261308 const TypeMatcher <InstanceRef >()
262309 .having ((InstanceRef instance) => instance.kind, 'kind' , kind)
263- .having ((InstanceRef instance) => instance.valueAsString, 'valueAsString' , message ),
310+ .having ((InstanceRef instance) => instance.valueAsString, 'valueAsString' , matcher ),
264311 );
265312}
266313
0 commit comments