Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Test correct source positions in stack trace with optimized functions. | 4 // Test correct source positions in stack trace with optimized functions. |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // (1) Test normal exception. | 7 // (1) Test normal exception. |
| 8 foo(x) => bar(x); | 8 foo(x) => bar(x); |
| 9 | 9 |
| 10 bar(x) { | 10 bar(x) { |
| 11 if (x == null) throw 42; // throw at position 11:18 | 11 if (x == null) throw 42; // throw at position 11:18 |
| 12 return x + 1; | 12 return x + 1; |
| 13 } | 13 } |
| 14 | 14 |
| 15 test1() { | 15 test1() { |
| 16 // First unoptimized. | 16 // First unoptimized. |
| 17 try { | 17 try { |
| 18 foo(null); | 18 foo(null); |
| 19 Expect.fail("Unreachable"); | 19 Expect.fail("Unreachable"); |
| 20 } catch (e, stacktrace) { | 20 } catch (e, stacktrace) { |
| 21 String s = stacktrace.toString(); | 21 String s = stacktrace.toString(); |
| 22 Expect.isFalse(s.contains("-1:-1")); | 22 print(s); |
| 23 Expect.isTrue(s.contains("11:18")); | 23 Expect.isFalse(s.contains("-1:-1"), "A"); |
| 24 Expect.isTrue(s.contains("optimized_stacktrace_line_test.dart:11"), "B"); | |
| 24 } | 25 } |
| 25 | 26 |
| 26 // Optimized. | 27 // Optimized. |
| 27 for (var i=0; i<10000; i++) foo(42); | 28 for (var i=0; i<10000; i++) foo(42); |
| 28 try { | 29 try { |
| 29 foo(null); | 30 foo(null); |
| 30 Expect.fail("Unreachable"); | 31 Expect.fail("Unreachable"); |
| 31 } catch (e, stacktrace) { | 32 } catch (e, stacktrace) { |
| 32 String s = stacktrace.toString(); | 33 String s = stacktrace.toString(); |
| 33 Expect.isFalse(s.contains("-1:-1")); | 34 print(s); |
| 34 Expect.isTrue(s.contains("11:18")); | 35 Expect.isFalse(s.contains("-1:-1"), "C"); |
| 36 Expect.isTrue(s.contains("optimized_stacktrace_line_test.dart:11"), "D"); | |
| 35 } | 37 } |
|
siva
2017/02/11 03:19:00
Ditto comment about labeling the rest of the tests
| |
| 36 } | 38 } |
| 37 | 39 |
| 38 | 40 |
| 39 // (2) Test checked mode exceptions. | 41 // (2) Test checked mode exceptions. |
| 40 maximus(x) => moritz(x); | 42 maximus(x) => moritz(x); |
| 41 | 43 |
| 42 moritz(x) { | 44 moritz(x) { |
| 43 if (x == 333) return 42 ? 0 : 1; // Throws in checked mode. | 45 if (x == 333) return 42 ? 0 : 1; // Throws in checked mode. |
| 44 if (x == 777) { | 46 if (x == 777) { |
| 45 bool b = x; // Throws in checked mode. | 47 bool b = x; // Throws in checked mode. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 69 Expect.isTrue(s.contains("maximus")); | 71 Expect.isTrue(s.contains("maximus")); |
| 70 Expect.isTrue(s.contains("moritz")); | 72 Expect.isTrue(s.contains("moritz")); |
| 71 Expect.isFalse(s.contains("-1:-1")); | 73 Expect.isFalse(s.contains("-1:-1")); |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 main() { | 77 main() { |
| 76 test1(); | 78 test1(); |
| 77 test2(); | 79 test2(); |
| 78 } | 80 } |
| OLD | NEW |