| 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 // Primitive way to get stack trace,. | |
| 13 try { | |
| 14 throw 0; | |
| 15 } catch (_, s) { | |
| 16 st0 = s; | |
| 17 } | |
| 18 st1 = StackTrace.current; | |
| 19 | |
| 20 var st0s = findMain(st0); | |
| 21 var st1s = findMain(st1); | |
| 22 // Stack traces are not equal (contains at least a different line number, | |
| 23 // and possible different frame numbers). | |
| 24 // They are *similar*, so check that they agree on everything but numbers. | |
| 25 var digits = new RegExp(r"\d+"); | |
| 26 Expect.equals(st0s.replaceAll(digits, "0"), st1s.replaceAll(digits, "0")); | |
| 27 } | |
| 28 | |
| 29 String findMain(StackTrace stack) { | |
| 30 var string = "$stack"; | |
| 31 var lines = LineSplitter.split(string).toList(); | |
| 32 while (lines.isNotEmpty && !lines.first.contains("main")) { | |
| 33 lines.removeAt(0); | |
| 34 } | |
| 35 return lines.join("\n"); | |
| 36 } | |
| OLD | NEW |