OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "dart:convert" show LineSplitter; | |
6 | |
7 import "package:expect/expect.dart"; | |
8 | |
9 void main() { | |
10 var st0; | |
11 var st1; | |
12 // Primitiive way to get stack trace,. | |
Ivan Posva
2015/11/24 00:53:58
-i
Lasse Reichstein Nielsen
2015/11/24 06:52:56
Good catch. Fixed.
| |
13 try { throw 0; } catch (_, s) { st0 = s; } | |
14 st1 = StackTrace.current; | |
15 | |
16 var st0s = findMain(st0); | |
17 var st1s = findMain(st1); | |
18 // Stack traces are not equal (contains at least a different line number, | |
19 // and possible different frame numbers). | |
20 // They are *similar*, so check that they agree on everything but numbers. | |
21 var digits = new RegExp(r"\d+"); | |
22 Expect.equals(st0s.replaceAll(digits, "0"), st1s.replaceAll(digits, "0")); | |
23 } | |
24 | |
25 String findMain(StackTrace stack) { | |
26 var string = "$stack"; | |
27 var lines = LineSplitter.split(string).toList(); | |
28 while (lines.isNotEmpty && !lines.first.contains("main")) { | |
29 lines.removeAt(0); | |
30 } | |
31 return lines.join("\n"); | |
32 } | |
OLD | NEW |