@@ -34,13 +34,18 @@ class Expectations {
34
34
/// Convert the annotated [code] to a [Test] object using [configs] to split
35
35
/// the annotations by prefix.
36
36
Test 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
+ );
39
42
40
43
Map <String , Expectations > expectationMap = < String , Expectations > {};
41
44
42
- splitByPrefixes (annotatedCode, configs)
43
- .forEach ((String config, AnnotatedCode annotatedCode) {
45
+ splitByPrefixes (annotatedCode, configs).forEach ((
46
+ String config,
47
+ AnnotatedCode annotatedCode,
48
+ ) {
44
49
Map <int , StackTraceLine > stackTraceMap = < int , StackTraceLine > {};
45
50
List <StackTraceLine > unexpectedLines = < StackTraceLine > [];
46
51
@@ -56,7 +61,11 @@ Test processTestCode(String code, Iterable<String> configs) {
56
61
indexText = text;
57
62
}
58
63
StackTraceLine stackTraceLine = StackTraceLine (
59
- methodName, inputFileName, annotation.lineNo, annotation.columnNo);
64
+ methodName,
65
+ inputFileName,
66
+ annotation.lineNo,
67
+ annotation.columnNo,
68
+ );
60
69
if (indexText == '' ) {
61
70
unexpectedLines.add (stackTraceLine);
62
71
} else {
@@ -104,33 +113,43 @@ String? identityConverter(String? name) => name;
104
113
/// If forcedTmpDir is given that directory is used as the out directory and
105
114
/// will not be cleaned up. Note that if *not* giving a temporary directory and
106
115
/// 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
+ );
122
137
123
138
Directory tmpDir =
124
139
forcedTmpDir ?? await Directory .systemTemp.createTemp ('stacktrace-test' );
125
140
String input = '${tmpDir .path }/$inputFileName ' ;
126
141
File (input).writeAsStringSync (test.code);
127
142
String output = '${tmpDir .path }/out.js' ;
128
143
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
+ );
131
148
File sourceMapFile = File ('$output .map' );
132
149
Expect .isTrue (
133
- sourceMapFile.existsSync (), 'Source map not generated for $input ' );
150
+ sourceMapFile.existsSync (),
151
+ 'Source map not generated for $input ' ,
152
+ );
134
153
String sourceMapText = sourceMapFile.readAsStringSync ();
135
154
SingleMapping sourceMap = parseSingleMapping (jsonDecode (sourceMapText));
136
155
String jsOutput = File (output).readAsStringSync ();
@@ -169,7 +188,10 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
169
188
List <StackTraceLine > dartStackTrace = < StackTraceLine > [];
170
189
for (StackTraceLine line in jsStackTrace) {
171
190
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
+ );
173
195
if (targetEntry == null || targetEntry.sourceUrlId == null ) {
174
196
dartStackTrace.add (line);
175
197
} else {
@@ -180,8 +202,10 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
180
202
if (expandDart2jsInliningData) {
181
203
SourceFile file = SourceFile .fromString (jsOutput);
182
204
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
+ );
185
209
List <int > indices = frames.keys.toList ()..sort ();
186
210
int key = binarySearch <int >(indices, (i) => i > offset) - 1 ;
187
211
int depth = 0 ;
@@ -191,12 +215,15 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
191
215
if (frame.isEmpty) break outer;
192
216
if (frame.isPush) {
193
217
if (depth <= 0 ) {
194
- dartStackTrace.add (StackTraceLine (
218
+ dartStackTrace.add (
219
+ StackTraceLine (
195
220
'${frame .inlinedMethodName }(inlined)' ,
196
221
fileName,
197
222
targetLine,
198
223
targetColumn,
199
- isMapped: true ));
224
+ isMapped: true ,
225
+ ),
226
+ );
200
227
fileName = frame.callUri! ;
201
228
targetLine = frame.callLine! + 1 ;
202
229
targetColumn = frame.callColumn! + 1 ;
@@ -220,9 +247,15 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
220
247
methodName = jsNameConverter (line.methodName);
221
248
}
222
249
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
+ );
226
259
}
227
260
}
228
261
@@ -276,22 +309,25 @@ Future testStackTrace(Test test, String config, CompileFunc compile,
276
309
print (dartStackTrace.join ('\n ' ));
277
310
}
278
311
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
+ );
284
318
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
+ );
289
324
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
+ );
295
331
296
332
if (forcedTmpDir == null ) {
297
333
print ("Deleting '${tmpDir .path }'." );
@@ -306,8 +342,13 @@ class StackTraceLine {
306
342
int ? columnNo;
307
343
bool isMapped;
308
344
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
+ });
311
352
312
353
/// Creates a [StackTraceLine] by parsing a d8 stack trace line [text] . The
313
354
/// expected formats are
@@ -338,8 +379,9 @@ class StackTraceLine {
338
379
if (lastValue != null ) {
339
380
int secondToLastColon = text.lastIndexOf (':' , lastColon - 1 );
340
381
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
+ );
343
385
if (secondToLastValue != null ) {
344
386
lineNo = secondToLastValue;
345
387
columnNo = lastValue;
@@ -391,15 +433,18 @@ class StackTraceLine {
391
433
///
392
434
/// Copied from [SingleMapping._findLine] .
393
435
TargetLineEntry ? _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
+ );
396
439
if (sourceMap.targetUrl != filename) return null ;
397
440
return _findLineInternal (sourceMap, stLine.lineNo! - 1 );
398
441
}
399
442
400
443
TargetLineEntry ? _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
+ );
403
448
return (index <= 0 ) ? null : sourceMap.lines[index - 1 ];
404
449
}
405
450
@@ -442,7 +487,11 @@ class LineException {
442
487
/// Search backwards in [sources] for a function declaration that includes the
443
488
/// [start] offset.
444
489
TargetEntry ? findEnclosingFunction (
445
- String sources, SourceFile file, int start, SingleMapping mapping) {
490
+ String sources,
491
+ SourceFile file,
492
+ int start,
493
+ SingleMapping mapping,
494
+ ) {
446
495
var index = start;
447
496
while (true ) {
448
497
index = nextDeclarationCandidate (sources, index);
@@ -479,7 +528,9 @@ int nextDeclarationCandidate(String sources, int start) {
479
528
}
480
529
481
530
Map <int , List <FrameEntry >> _loadInlinedFrameData (
482
- SingleMapping mapping, String sourceMapText) {
531
+ SingleMapping mapping,
532
+ String sourceMapText,
533
+ ) {
483
534
var json = jsonDecode (sourceMapText);
484
535
return Dart2jsMapping (mapping, json).frames;
485
536
}
0 commit comments