@@ -34,13 +34,18 @@ class Expectations {
3434/// Convert the annotated [code] to a [Test] object using [configs] to split
3535/// the annotations by prefix.
3636Test processTestCode (String code, Iterable <String > configs) {
37- AnnotatedCode annotatedCode =
38- AnnotatedCode .fromText (code, commentStart, commentEnd);
37+ AnnotatedCode annotatedCode = AnnotatedCode .fromText (
38+ code,
39+ commentStart,
40+ commentEnd,
41+ );
3942
4043 Map <String , Expectations > expectationMap = < String , Expectations > {};
4144
42- splitByPrefixes (annotatedCode, configs)
43- .forEach ((String config, AnnotatedCode annotatedCode) {
45+ splitByPrefixes (annotatedCode, configs).forEach ((
46+ String config,
47+ AnnotatedCode annotatedCode,
48+ ) {
4449 Map <int , StackTraceLine > stackTraceMap = < int , StackTraceLine > {};
4550 List <StackTraceLine > unexpectedLines = < StackTraceLine > [];
4651
@@ -56,7 +61,11 @@ Test processTestCode(String code, Iterable<String> configs) {
5661 indexText = text;
5762 }
5863 StackTraceLine stackTraceLine = StackTraceLine (
59- methodName, inputFileName, annotation.lineNo, annotation.columnNo);
64+ methodName,
65+ inputFileName,
66+ annotation.lineNo,
67+ annotation.columnNo,
68+ );
6069 if (indexText == '' ) {
6170 unexpectedLines.add (stackTraceLine);
6271 } else {
@@ -104,33 +113,43 @@ String? identityConverter(String? name) => name;
104113/// If forcedTmpDir is given that directory is used as the out directory and
105114/// will not be cleaned up. Note that if *not* giving a temporary directory and
106115/// the test fails the directory will not be cleaned up.
107- Future testStackTrace (Test test, String config, CompileFunc compile,
108- {bool printJs = false ,
109- bool writeJs = false ,
110- bool verbose = false ,
111- List <String > Function (String input, String output) jsPreambles =
112- emptyPreamble,
113- List <LineException > beforeExceptions = const < LineException > [],
114- List <LineException > afterExceptions = const < LineException > [],
115- bool useJsMethodNamesOnAbsence = false ,
116- String ? Function (String ? name) jsNameConverter = identityConverter,
117- Directory ? forcedTmpDir,
118- int stackTraceLimit = 10 ,
119- expandDart2jsInliningData = false }) async {
120- Expect .isTrue (test.expectationMap.keys.contains (config),
121- "No expectations found for '$config ' in ${test .expectationMap .keys }" );
116+ Future testStackTrace (
117+ Test test,
118+ String config,
119+ CompileFunc compile, {
120+ bool printJs = false ,
121+ bool writeJs = false ,
122+ bool verbose = false ,
123+ List <String > Function (String input, String output) jsPreambles =
124+ emptyPreamble,
125+ List <LineException > beforeExceptions = const < LineException > [],
126+ List <LineException > afterExceptions = const < LineException > [],
127+ bool useJsMethodNamesOnAbsence = false ,
128+ String ? Function (String ? name) jsNameConverter = identityConverter,
129+ Directory ? forcedTmpDir,
130+ int stackTraceLimit = 10 ,
131+ expandDart2jsInliningData = false ,
132+ }) async {
133+ Expect .isTrue (
134+ test.expectationMap.keys.contains (config),
135+ "No expectations found for '$config ' in ${test .expectationMap .keys }" ,
136+ );
122137
123138 Directory tmpDir =
124139 forcedTmpDir ?? await Directory .systemTemp.createTemp ('stacktrace-test' );
125140 String input = '${tmpDir .path }/$inputFileName ' ;
126141 File (input).writeAsStringSync (test.code);
127142 String output = '${tmpDir .path }/out.js' ;
128143
129- Expect .isTrue (await compile (input, output),
130- 'Unsuccessful compilation of test:\n ${test .code }' );
144+ Expect .isTrue (
145+ await compile (input, output),
146+ 'Unsuccessful compilation of test:\n ${test .code }' ,
147+ );
131148 File sourceMapFile = File ('$output .map' );
132149 Expect .isTrue (
133- sourceMapFile.existsSync (), 'Source map not generated for $input ' );
150+ sourceMapFile.existsSync (),
151+ 'Source map not generated for $input ' ,
152+ );
134153 String sourceMapText = sourceMapFile.readAsStringSync ();
135154 SingleMapping sourceMap = parseSingleMapping (jsonDecode (sourceMapText));
136155 String jsOutput = File (output).readAsStringSync ();
@@ -169,7 +188,10 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
169188 List <StackTraceLine > dartStackTrace = < StackTraceLine > [];
170189 for (StackTraceLine line in jsStackTrace) {
171190 TargetEntry ? targetEntry = _findColumn (
172- line.lineNo! - 1 , line.columnNo! - 1 , _findLine (sourceMap, line));
191+ line.lineNo! - 1 ,
192+ line.columnNo! - 1 ,
193+ _findLine (sourceMap, line),
194+ );
173195 if (targetEntry == null || targetEntry.sourceUrlId == null ) {
174196 dartStackTrace.add (line);
175197 } else {
@@ -180,8 +202,10 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
180202 if (expandDart2jsInliningData) {
181203 SourceFile file = SourceFile .fromString (jsOutput);
182204 int offset = file.getOffset (line.lineNo! - 1 , line.columnNo! - 1 );
183- Map <int , List <FrameEntry >> frames =
184- _loadInlinedFrameData (sourceMap, sourceMapText);
205+ Map <int , List <FrameEntry >> frames = _loadInlinedFrameData (
206+ sourceMap,
207+ sourceMapText,
208+ );
185209 List <int > indices = frames.keys.toList ()..sort ();
186210 int key = binarySearch <int >(indices, (i) => i > offset) - 1 ;
187211 int depth = 0 ;
@@ -191,12 +215,15 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
191215 if (frame.isEmpty) break outer;
192216 if (frame.isPush) {
193217 if (depth <= 0 ) {
194- dartStackTrace.add (StackTraceLine (
218+ dartStackTrace.add (
219+ StackTraceLine (
195220 '${frame .inlinedMethodName }(inlined)' ,
196221 fileName,
197222 targetLine,
198223 targetColumn,
199- isMapped: true ));
224+ isMapped: true ,
225+ ),
226+ );
200227 fileName = frame.callUri! ;
201228 targetLine = frame.callLine! + 1 ;
202229 targetColumn = frame.callColumn! + 1 ;
@@ -220,9 +247,15 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
220247 methodName = jsNameConverter (line.methodName);
221248 }
222249
223- dartStackTrace.add (StackTraceLine (
224- methodName, fileName, targetLine, targetColumn,
225- isMapped: true ));
250+ dartStackTrace.add (
251+ StackTraceLine (
252+ methodName,
253+ fileName,
254+ targetLine,
255+ targetColumn,
256+ isMapped: true ,
257+ ),
258+ );
226259 }
227260 }
228261
@@ -276,22 +309,25 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
276309 print (dartStackTrace.join ('\n ' ));
277310 }
278311 Expect .equals (
279- expectedIndex,
280- expectations.expectedLines.length,
281- 'Missing stack trace lines for test:\n ${test .code }\n '
282- 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
283- 'Expected:\n ${expectations .expectedLines .join ('\n ' )}\n ' );
312+ expectedIndex,
313+ expectations.expectedLines.length,
314+ 'Missing stack trace lines for test:\n ${test .code }\n '
315+ 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
316+ 'Expected:\n ${expectations .expectedLines .join ('\n ' )}\n ' ,
317+ );
284318 Expect .isTrue (
285- unexpectedLines.isEmpty,
286- 'Unexpected stack trace lines for test:\n ${test .code }\n '
287- 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
288- 'Unexpected:\n ${expectations .unexpectedLines .join ('\n ' )}\n ' );
319+ unexpectedLines.isEmpty,
320+ 'Unexpected stack trace lines for test:\n ${test .code }\n '
321+ 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
322+ 'Unexpected:\n ${expectations .unexpectedLines .join ('\n ' )}\n ' ,
323+ );
289324 Expect .isTrue (
290- unexpectedBeforeLines.isEmpty && unexpectedAfterLines.isEmpty,
291- 'Unexpected stack trace lines:\n ${test .code }\n '
292- 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
293- 'Unexpected before:\n ${unexpectedBeforeLines .join ('\n ' )}\n\n '
294- 'Unexpected after:\n ${unexpectedAfterLines .join ('\n ' )}\n ' );
325+ unexpectedBeforeLines.isEmpty && unexpectedAfterLines.isEmpty,
326+ 'Unexpected stack trace lines:\n ${test .code }\n '
327+ 'Actual:\n ${dartStackTrace .join ('\n ' )}\n\n '
328+ 'Unexpected before:\n ${unexpectedBeforeLines .join ('\n ' )}\n\n '
329+ 'Unexpected after:\n ${unexpectedAfterLines .join ('\n ' )}\n ' ,
330+ );
295331
296332 if (forcedTmpDir == null ) {
297333 print ("Deleting '${tmpDir .path }'." );
@@ -306,8 +342,13 @@ class StackTraceLine {
306342 int ? columnNo;
307343 bool isMapped;
308344
309- StackTraceLine (this .methodName, this .fileName, this .lineNo, this .columnNo,
310- {this .isMapped = false });
345+ StackTraceLine (
346+ this .methodName,
347+ this .fileName,
348+ this .lineNo,
349+ this .columnNo, {
350+ this .isMapped = false ,
351+ });
311352
312353 /// Creates a [StackTraceLine] by parsing a d8 stack trace line [text] . The
313354 /// expected formats are
@@ -338,8 +379,9 @@ class StackTraceLine {
338379 if (lastValue != null ) {
339380 int secondToLastColon = text.lastIndexOf (':' , lastColon - 1 );
340381 if (secondToLastColon != - 1 ) {
341- int ? secondToLastValue =
342- int .tryParse (text.substring (secondToLastColon + 1 , lastColon));
382+ int ? secondToLastValue = int .tryParse (
383+ text.substring (secondToLastColon + 1 , lastColon),
384+ );
343385 if (secondToLastValue != null ) {
344386 lineNo = secondToLastValue;
345387 columnNo = lastValue;
@@ -391,15 +433,18 @@ class StackTraceLine {
391433///
392434/// Copied from [SingleMapping._findLine] .
393435TargetLineEntry ? _findLine (SingleMapping sourceMap, StackTraceLine stLine) {
394- String filename = stLine.fileName!
395- .substring (stLine.fileName! .lastIndexOf (RegExp ('[\\ /]' )) + 1 );
436+ String filename = stLine.fileName! .substring (
437+ stLine.fileName! .lastIndexOf (RegExp ('[\\ /]' )) + 1 ,
438+ );
396439 if (sourceMap.targetUrl != filename) return null ;
397440 return _findLineInternal (sourceMap, stLine.lineNo! - 1 );
398441}
399442
400443TargetLineEntry ? _findLineInternal (SingleMapping sourceMap, int line) {
401- int index =
402- binarySearch <TargetLineEntry >(sourceMap.lines, (e) => e.line > line);
444+ int index = binarySearch <TargetLineEntry >(
445+ sourceMap.lines,
446+ (e) => e.line > line,
447+ );
403448 return (index <= 0 ) ? null : sourceMap.lines[index - 1 ];
404449}
405450
@@ -442,7 +487,11 @@ class LineException {
442487/// Search backwards in [sources] for a function declaration that includes the
443488/// [start] offset.
444489TargetEntry ? findEnclosingFunction (
445- String sources, SourceFile file, int start, SingleMapping mapping) {
490+ String sources,
491+ SourceFile file,
492+ int start,
493+ SingleMapping mapping,
494+ ) {
446495 var index = start;
447496 while (true ) {
448497 index = nextDeclarationCandidate (sources, index);
@@ -479,7 +528,9 @@ int nextDeclarationCandidate(String sources, int start) {
479528}
480529
481530Map <int , List <FrameEntry >> _loadInlinedFrameData (
482- SingleMapping mapping, String sourceMapText) {
531+ SingleMapping mapping,
532+ String sourceMapText,
533+ ) {
483534 var json = jsonDecode (sourceMapText);
484535 return Dart2jsMapping (mapping, json).frames;
485536}
0 commit comments