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

Side by Side Diff: tests/corelib_2/error_stack_trace_test.dart

Issue 2987793002: Migrate test block 7 to Dart 2.0. (Closed)
Patch Set: Test modifications Created 3 years, 4 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
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 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 void argument() { 7 void argument() {
8 throw new ArgumentError(499); 8 throw new ArgumentError(499);
9 } 9 }
10 10
Bob Nystrom 2017/07/25 22:05:43 Oof, this test is complicated. I believe the inten
jcollins 2017/08/02 21:03:26 Acknowledged.
11 void noSuchMethod() { 11 void noSuchMethod() {
12 (499).doesNotExist(); 12 (499).doesNotExist(); //# static: compile-time error
Bob Nystrom 2017/07/25 22:05:43 This is still a valid runtime error, but we need t
jcollins 2017/08/02 21:03:26 So, in other words, in Dart 2.0 the only time a ru
Bob Nystrom 2017/08/02 21:12:36 Exactly right.
13 } 13 }
14 14
15 void nullThrown() { 15 void nullThrown() {
16 throw null; 16 throw null;
17 } 17 }
18 18
19 void range() { 19 void range() {
20 throw new RangeError.range(0, 1, 2); 20 throw new RangeError.range(0, 1, 2);
21 } 21 }
22 22
23 void fallThrough() { 23 void fallThrough() {
Bob Nystrom 2017/07/25 22:05:43 FallThrough errors should not exist at runtime in
24 nested() {} 24 nested() {}
25 25
26 switch (5) { 26 switch (5) {
27 case 5: 27 case 5://# static: compile-time error
28 nested(); 28 nested();//# static: compile-time error
jcollins 2017/08/02 21:03:26 This case has become more interesting once we've p
Bob Nystrom 2017/08/02 21:12:36 In strong mode, that static warning should get pro
29 default: 29 default:
30 Expect.fail("Should not reach"); 30 Expect.fail("Should not reach");
31 } 31 }
32 } 32 }
33 33
34 abstract class A { 34 abstract class A {
35 foo(); 35 foo();
36 } 36 }
37 37
Bob Nystrom 2017/07/25 22:05:43 Likewise, there is no AbstractClassInstantiationEr
jcollins 2017/08/02 21:03:26 done
38 void abstractClassInstantiation() { 38 void abstractClassInstantiation() {
39 new A(); 39 new A();//# static: compile-time error
40 } 40 }
41 41
42 void unsupported() { 42 void unsupported() {
43 throw new UnsupportedError("unsupported"); 43 throw new UnsupportedError("unsupported");
44 } 44 }
45 45
46 void unimplemented() { 46 void unimplemented() {
47 throw new UnimplementedError("unimplemented"); 47 throw new UnimplementedError("unimplemented");
48 } 48 }
49 49
50 void state() { 50 void state() {
51 return [1, 2].single; 51 return [1, 2].single;//# static: compile-time error
Bob Nystrom 2017/07/25 22:05:43 As far as I can tell, this shouldn't have a static
jcollins 2017/08/02 21:03:26 This has a static error because the code returns a
Bob Nystrom 2017/08/02 21:12:36 Ha, oh, right.
jcollins 2017/08/03 15:54:18 Making this more minimal makes sense, done.
52 } 52 }
53 53
54 void type() { 54 void type() {
55 return 1 + "string"; 55 return 1 + "string";//# static: compile-time error
Bob Nystrom 2017/07/25 22:05:43 I don't believe Dart 2.0 has TypeError. But it *do
jcollins 2017/08/02 21:03:25 Done.
56 } 56 }
57 57
58 main() { 58 main() {
59 List<Function> errorFunctions = [ 59 List<Function> errorFunctions = [
60 argument, 60 argument,
61 noSuchMethod, 61 noSuchMethod, //# static: ok
62 nullThrown, 62 nullThrown,
63 range, 63 range,
64 fallThrough, 64 fallThrough, //# static: ok
65 abstractClassInstantiation, 65 abstractClassInstantiation, //# static: ok
66 unsupported, 66 unsupported,
67 unimplemented, 67 unimplemented,
68 state, 68 state, //# static: ok
69 type 69 type //# static: ok
70 ]; 70 ];
71 71
72 for (var f in errorFunctions) { 72 for (var f in errorFunctions) {
73 bool hasThrown = false; 73 bool hasThrown = false;
74 try { 74 try {
75 f(); 75 f();
76 } catch (e) { 76 } catch (e, stackTrace) {
77 hasThrown = true; 77 hasThrown = true;
78 Expect.isTrue( 78 Expect.isTrue(
79 e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace"); 79 stackTrace is StackTrace, "$e doesn't have a non-null stack trace");
Bob Nystrom 2017/07/25 22:05:43 I don't think this change is right. My reading is
jcollins 2017/08/02 21:03:26 I had asked around about this and the understandin
Bob Nystrom 2017/08/02 21:12:36 Oh, interesting. I didn't realize there were any A
jcollins 2017/08/03 15:54:18 Since I've already done the work of figuring out w
80 } 80 }
81 Expect.isTrue(hasThrown); 81 Expect.isTrue(hasThrown);
82 } 82 }
83 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698