Skip to content

Commit dd2dcba

Browse files
lrhnCommit Queue
authored andcommitted
Make .expect files not contain platform library implementation details.
Removes frames in stack traces for private platform members (any `dart:...` entry with a private name, any `dart:_...` entry), removes line/column number from any remaining `dart:` functions, and removes the stack frame number (which depends on the number of removed frames). Should not affect what is actually being tested, but avoids the test failing any time a line number in the platform libraries change. Change-Id: I7255a3ae5fb6ff2cbca0830ce61ddcdb7d0f43a5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406003 Commit-Queue: Lasse Nielsen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 9a8d436 commit dd2dcba

File tree

3 files changed

+66
-73
lines changed

3 files changed

+66
-73
lines changed

pkg/front_end/test/macros/application/data/tests/crash.dart.expect

Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,16 @@ library;
66
// @CrashTypesMacro()
77
// ^
88
// org-dartlang-test:///a/b/c/main.dart:7:2: Context: Error in buildTypesForClass
9-
// #0 CrashTypesMacro.buildTypesForClass (package:macro/crash.dart:13:5)
10-
// #1 executeTypesMacro (package:_macros/src/executor/execute_macro.dart:39:21)
11-
// #2 MacroExpansionClient._executeTypesPhase.<anonymous closure> (package:_macros/src/executor/client.dart:219:17)
12-
// #3 runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
13-
// #4 _rootRun (dart:async/zone.dart:1525:13)
14-
// #5 _CustomZone.run (dart:async/zone.dart:1422:19)
15-
// #6 _CustomZone.runGuarded (dart:async/zone.dart:1321:7)
16-
// #7 runPhase (package:_macros/src/executor/client.dart:385:8)
17-
// #8 MacroExpansionClient._executeTypesPhase (package:_macros/src/executor/client.dart:218:43)
18-
// #9 MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:145:18)
19-
// #10 _rootRun (dart:async/zone.dart:1525:13)
20-
// #11 _CustomZone.run (dart:async/zone.dart:1422:19)
21-
// #12 withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
22-
// #13 MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
23-
// #14 new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
24-
// #15 _rootRunUnary (dart:async/zone.dart:1546:13)
25-
// #16 _CustomZone.runUnary (dart:async/zone.dart:1429:19)
26-
// #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
27-
// #18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
28-
// #19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
29-
// #20 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
30-
// #21 _StreamController._add (dart:async/stream_controller.dart:663:7)
31-
// #22 _StreamController.add (dart:async/stream_controller.dart:618:5)
32-
// #23 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
9+
// # CrashTypesMacro.buildTypesForClass (package:macro/crash.dart:13:5)
10+
// # executeTypesMacro (package:_macros/src/executor/execute_macro.dart:39:21)
11+
// # MacroExpansionClient._executeTypesPhase.<anonymous closure> (package:_macros/src/executor/client.dart:219:17)
12+
// # runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
13+
// # runPhase (package:_macros/src/executor/client.dart:385:8)
14+
// # MacroExpansionClient._executeTypesPhase (package:_macros/src/executor/client.dart:218:43)
15+
// # MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:145:18)
16+
// # withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
17+
// # MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
18+
// # new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
3319
//
3420
// @CrashTypesMacro()
3521
// ^
@@ -38,30 +24,16 @@ library;
3824
// @CrashDeclarationsMacro()
3925
// ^
4026
// org-dartlang-test:///a/b/c/main.dart:8:2: Context: Error in buildDeclarationsForClass
41-
// #0 CrashDeclarationsMacro.buildDeclarationsForClass (package:macro/crash.dart:22:5)
42-
// #1 executeDeclarationsMacro (package:_macros/src/executor/execute_macro.dart:107:21)
43-
// #2 MacroExpansionClient._executeDeclarationsPhase.<anonymous closure> (package:_macros/src/executor/client.dart:248:11)
44-
// #3 runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
45-
// #4 _rootRun (dart:async/zone.dart:1525:13)
46-
// #5 _CustomZone.run (dart:async/zone.dart:1422:19)
47-
// #6 _CustomZone.runGuarded (dart:async/zone.dart:1321:7)
48-
// #7 runPhase (package:_macros/src/executor/client.dart:385:8)
49-
// #8 MacroExpansionClient._executeDeclarationsPhase (package:_macros/src/executor/client.dart:247:43)
50-
// #9 MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:135:18)
51-
// #10 _rootRun (dart:async/zone.dart:1525:13)
52-
// #11 _CustomZone.run (dart:async/zone.dart:1422:19)
53-
// #12 withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
54-
// #13 MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
55-
// #14 new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
56-
// #15 _rootRunUnary (dart:async/zone.dart:1546:13)
57-
// #16 _CustomZone.runUnary (dart:async/zone.dart:1429:19)
58-
// #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
59-
// #18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
60-
// #19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
61-
// #20 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
62-
// #21 _StreamController._add (dart:async/stream_controller.dart:663:7)
63-
// #22 _StreamController.add (dart:async/stream_controller.dart:618:5)
64-
// #23 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
27+
// # CrashDeclarationsMacro.buildDeclarationsForClass (package:macro/crash.dart:22:5)
28+
// # executeDeclarationsMacro (package:_macros/src/executor/execute_macro.dart:107:21)
29+
// # MacroExpansionClient._executeDeclarationsPhase.<anonymous closure> (package:_macros/src/executor/client.dart:248:11)
30+
// # runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
31+
// # runPhase (package:_macros/src/executor/client.dart:385:8)
32+
// # MacroExpansionClient._executeDeclarationsPhase (package:_macros/src/executor/client.dart:247:43)
33+
// # MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:135:18)
34+
// # withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
35+
// # MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
36+
// # new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
6537
//
6638
// @CrashDeclarationsMacro()
6739
// ^
@@ -70,30 +42,16 @@ library;
7042
// @CrashDefinitionMacro()
7143
// ^
7244
// org-dartlang-test:///a/b/c/main.dart:9:2: Context: Error in buildDefinitionForClass
73-
// #0 CrashDefinitionMacro.buildDefinitionForClass (package:macro/crash.dart:31:5)
74-
// #1 executeDefinitionMacro (package:_macros/src/executor/execute_macro.dart:167:21)
75-
// #2 MacroExpansionClient._executeDefinitionsPhase.<anonymous closure> (package:_macros/src/executor/client.dart:276:17)
76-
// #3 runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
77-
// #4 _rootRun (dart:async/zone.dart:1525:13)
78-
// #5 _CustomZone.run (dart:async/zone.dart:1422:19)
79-
// #6 _CustomZone.runGuarded (dart:async/zone.dart:1321:7)
80-
// #7 runPhase (package:_macros/src/executor/client.dart:385:8)
81-
// #8 MacroExpansionClient._executeDefinitionsPhase (package:_macros/src/executor/client.dart:275:43)
82-
// #9 MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:140:18)
83-
// #10 _rootRun (dart:async/zone.dart:1525:13)
84-
// #11 _CustomZone.run (dart:async/zone.dart:1422:19)
85-
// #12 withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
86-
// #13 MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
87-
// #14 new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
88-
// #15 _rootRunUnary (dart:async/zone.dart:1546:13)
89-
// #16 _CustomZone.runUnary (dart:async/zone.dart:1429:19)
90-
// #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
91-
// #18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
92-
// #19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
93-
// #20 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
94-
// #21 _StreamController._add (dart:async/stream_controller.dart:663:7)
95-
// #22 _StreamController.add (dart:async/stream_controller.dart:618:5)
96-
// #23 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
45+
// # CrashDefinitionMacro.buildDefinitionForClass (package:macro/crash.dart:31:5)
46+
// # executeDefinitionMacro (package:_macros/src/executor/execute_macro.dart:167:21)
47+
// # MacroExpansionClient._executeDefinitionsPhase.<anonymous closure> (package:_macros/src/executor/client.dart:276:17)
48+
// # runPhase.<anonymous closure> (package:_macros/src/executor/client.dart:385:30)
49+
// # runPhase (package:_macros/src/executor/client.dart:385:8)
50+
// # MacroExpansionClient._executeDefinitionsPhase (package:_macros/src/executor/client.dart:275:43)
51+
// # MacroExpansionClient._handleMessage.<anonymous closure> (package:_macros/src/executor/client.dart:140:18)
52+
// # withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
53+
// # MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:11)
54+
// # new MacroExpansionClient._.<anonymous closure> (package:_macros/src/executor/client.dart:37:39)
9755
//
9856
// @CrashDefinitionMacro()
9957
// ^

pkg/front_end/test/macros/application/macro_application_test.dart

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MacroTestConfig extends CfeTestConfig {
8484
}
8585
});
8686
printer.writeConstantTable(component);
87-
String actual = buffer.toString();
87+
String actual = _sanitizeStackTraces(buffer.toString());
8888
String expectationFileName = '${testData.name}.expect';
8989
Uri expectedUri = dataDir.uri.resolve(expectationFileName);
9090
File file = new File.fromUri(expectedUri);
@@ -121,6 +121,40 @@ class MacroTestConfig extends CfeTestConfig {
121121
}
122122
}
123123

124+
/// Matches output of a stack trace
125+
final _stackFrameRE =
126+
RegExp(r'^// #(\d+ +)(new )?([^(]*)\((.*)(:\d+:\d+)\) *\n',
127+
multiLine: true);
128+
129+
/// Sanitizes stack traces, removing implementation details.
130+
///
131+
/// Recognizes stack traces and:
132+
/// - removes platform implementation details
133+
/// - removes frames from `dart:_` libraries
134+
/// - removes frames from `dart:` libraries with private names.
135+
/// - removes position of platform library code (`:12:4` -> `:-:-`).
136+
/// - removes stack frame number (always consecutive anyway).
137+
String _sanitizeStackTraces(String output) =>
138+
output.replaceAllMapped(_stackFrameRE, (m) {
139+
var frameNr = m[1]!;
140+
var newPrefix = m[2] ?? "";
141+
var name = m[3]!;
142+
var uri = m[4]!;
143+
var location = m[5]!;
144+
145+
if (uri.startsWith('dart:')) {
146+
// Remove all internal functions.
147+
if (uri.startsWith('_', 'dart:'.length) ||
148+
name.startsWith('_') ||
149+
name.contains('._')) {
150+
return "";
151+
}
152+
location = ":-:-";
153+
}
154+
frameNr = frameNr.length == 8 ? " " : " " * frameNr.length;
155+
return "// #$frameNr$newPrefix$name($uri$location)\n";
156+
});
157+
124158
bool _isMember(MemberBuilder memberBuilder, Member member) {
125159
if (memberBuilder is PropertyBuilder && memberBuilder.isField) {
126160
// Only show annotations for the field or getter.

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,7 @@ sake
27402740
same
27412741
sample
27422742
samples
2743+
sanitizes
27432744
sanity
27442745
sate
27452746
satisfied

0 commit comments

Comments
 (0)