Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: tests/language/error_stacktrace_test.dart

Issue 2774783002: Re-land "Format all multitests" (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/language/enum_syntax_test.dart ('k') | tests/language/external_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Dart test program for testing throw statement 4 // Dart test program for testing throw statement
5 5
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 7
8 class MyException { 8 class MyException {
9 const MyException(String message) : message_ = message; 9 const MyException(String message) : message_ = message;
10 final String message_; 10 final String message_;
11 } 11 }
12 12
13 class Helper1 { 13 class Helper1 {
14 static int func1() { 14 static int func1() {
15 return func2(); 15 return func2();
16 } 16 }
17
17 static int func2() { 18 static int func2() {
18 return func3(); 19 return func3();
19 } 20 }
21
20 static int func3() { 22 static int func3() {
21 return func4(); 23 return func4();
22 } 24 }
25
23 static int func4() { 26 static int func4() {
24 var i = 0; 27 var i = 0;
25 try { 28 try {
26 i = 10; 29 i = 10;
27 func5(); 30 func5();
28 } on ArgumentError catch (e) { 31 } on ArgumentError catch (e) {
29 i = 100; 32 i = 100;
30 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw"); 33 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw");
31 } 34 }
32 return i; 35 return i;
33 } 36 }
37
34 static void func5() { 38 static void func5() {
35 // Throw an Error. 39 // Throw an Error.
36 throw new ArgumentError("ArgumentError in func5"); 40 throw new ArgumentError("ArgumentError in func5");
37 } 41 }
38 } 42 }
39 43
40 class Helper2 { 44 class Helper2 {
41 static int func1() { 45 static int func1() {
42 return func2(); 46 return func2();
43 } 47 }
48
44 static int func2() { 49 static int func2() {
45 return func3(); 50 return func3();
46 } 51 }
52
47 static int func3() { 53 static int func3() {
48 return func4(); 54 return func4();
49 } 55 }
56
50 static int func4() { 57 static int func4() {
51 var i = 0; 58 var i = 0;
52 try { 59 try {
53 i = 10; 60 i = 10;
54 func5(); 61 func5();
55 } on ArgumentError catch (e, s) { 62 } on ArgumentError catch (e, s) {
56 i = 200; 63 i = 200;
57 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw"); 64 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw");
58 Expect.equals(e.stackTrace.toString(), s.toString()); 65 Expect.equals(e.stackTrace.toString(), s.toString());
59 } 66 }
60 return i; 67 return i;
61 } 68 }
69
62 static List func5() { 70 static List func5() {
63 // Throw an Error. 71 // Throw an Error.
64 throw new ArgumentError("ArgumentError in func5"); 72 throw new ArgumentError("ArgumentError in func5");
65 } 73 }
66 } 74 }
67 75
68 class Helper3 { 76 class Helper3 {
69 static int func1() { 77 static int func1() {
70 return func2(); 78 return func2();
71 } 79 }
80
72 static int func2() { 81 static int func2() {
73 return func3(); 82 return func3();
74 } 83 }
84
75 static int func3() { 85 static int func3() {
76 return func4(); 86 return func4();
77 } 87 }
88
78 static int func4() { 89 static int func4() {
79 var i = 0; 90 var i = 0;
80 try { 91 try {
81 i = 10; 92 i = 10;
82 func5(); 93 func5();
83 } on MyException catch (e) { 94 } on MyException catch (e) {
84 i = 300; 95 i = 300;
85 try { 96 try {
86 // There should be no stackTrace in this normal exception object. 97 // There should be no stackTrace in this normal exception object.
87 // We should get a NoSuchMethodError. 98 // We should get a NoSuchMethodError.
88 var trace = e.stackTrace; //# static type warning 99 var trace = e.stackTrace; //# static type warning
89 } on NoSuchMethodError catch (e) { 100 } on NoSuchMethodError catch (e) {
90 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); 101 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw");
91 } 102 }
92 } 103 }
93 return i; 104 return i;
94 } 105 }
106
95 static List func5() { 107 static List func5() {
96 // Throw an Exception (any random object). 108 // Throw an Exception (any random object).
97 throw new MyException("MyException in func5"); 109 throw new MyException("MyException in func5");
98 } 110 }
99 } 111 }
100 112
101 class ErrorStackTraceTest { 113 class ErrorStackTraceTest {
102 static testMain() { 114 static testMain() {
103 Expect.equals(100, Helper1.func1()); 115 Expect.equals(100, Helper1.func1());
104 Expect.equals(200, Helper2.func1()); 116 Expect.equals(200, Helper2.func1());
105 Expect.equals(300, Helper3.func1()); 117 Expect.equals(300, Helper3.func1());
106 } 118 }
107 } 119 }
108 120
109 main() { 121 main() {
110 ErrorStackTraceTest.testMain(); 122 ErrorStackTraceTest.testMain();
111 } 123 }
OLDNEW
« no previous file with comments | « tests/language/enum_syntax_test.dart ('k') | tests/language/external_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698