Skip to content

Commit 3281a4a

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Move tests for 10 diagnostic codes to diagnostics/ files
Change-Id: Ic5e4f344c17b2c18c134b816a771fb61732dd934 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127452 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
1 parent 4b21941 commit 3281a4a

12 files changed

+653
-503
lines changed

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 8 additions & 503 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(RedirectGenerativeToNonGenerativeConstructorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class RedirectGenerativeToNonGenerativeConstructorTest
18+
extends DriverResolutionTest {
19+
test_missing() async {
20+
await assertErrorsInCode(r'''
21+
class A {
22+
A() : this.noSuchConstructor();
23+
}
24+
''', [
25+
error(CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, 18,
26+
24),
27+
]);
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(RedirectGenerativeToNonGenerativeConstructorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class RedirectGenerativeToNonGenerativeConstructorTest
18+
extends DriverResolutionTest {
19+
test_nonGenerative() async {
20+
await assertErrorsInCode(r'''
21+
class A {
22+
A() : this.x();
23+
factory A.x() => null;
24+
}
25+
''', [
26+
error(
27+
CompileTimeErrorCode
28+
.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR,
29+
18,
30+
8),
31+
]);
32+
}
33+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ReferencedBeforeDeclarationTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ReferencedBeforeDeclarationTest extends DriverResolutionTest {
18+
test_hideInBlock_comment() async {
19+
await assertNoErrorsInCode(r'''
20+
main() {
21+
/// [v] is a variable.
22+
var v = 2;
23+
}
24+
print(x) {}
25+
''');
26+
}
27+
28+
test_hideInBlock_function() async {
29+
await assertErrorsInCode(r'''
30+
var v = 1;
31+
main() {
32+
print(v);
33+
v() {}
34+
}
35+
print(x) {}
36+
''', [
37+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 28, 1,
38+
expectedMessages: [message('/test/lib/test.dart', 34, 1)]),
39+
]);
40+
}
41+
42+
test_hideInBlock_local() async {
43+
await assertErrorsInCode(r'''
44+
var v = 1;
45+
main() {
46+
print(v);
47+
var v = 2;
48+
}
49+
print(x) {}
50+
''', [
51+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 28, 1,
52+
expectedMessages: [message('/test/lib/test.dart', 38, 1)]),
53+
]);
54+
}
55+
56+
test_hideInBlock_subBlock() async {
57+
await assertErrorsInCode(r'''
58+
var v = 1;
59+
main() {
60+
{
61+
print(v);
62+
}
63+
var v = 2;
64+
}
65+
print(x) {}
66+
''', [
67+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 34, 1,
68+
expectedMessages: [message('/test/lib/test.dart', 48, 1)]),
69+
]);
70+
}
71+
72+
test_inInitializer_closure() async {
73+
await assertErrorsInCode(r'''
74+
main() {
75+
var v = () => v;
76+
}
77+
''', [
78+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 25, 1,
79+
expectedMessages: [message('/test/lib/test.dart', 15, 1)]),
80+
]);
81+
}
82+
83+
test_inInitializer_directly() async {
84+
await assertErrorsInCode(r'''
85+
main() {
86+
var v = v;
87+
}
88+
''', [
89+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 19, 1,
90+
expectedMessages: [message('/test/lib/test.dart', 15, 1)]),
91+
]);
92+
}
93+
94+
test_type_localFunction() async {
95+
await assertErrorsInCode(r'''
96+
void testTypeRef() {
97+
String s = '';
98+
int String(int x) => x + 1;
99+
print(s + String);
100+
}
101+
''', [
102+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 23, 6,
103+
expectedMessages: [message('/test/lib/test.dart', 44, 6)]),
104+
]);
105+
}
106+
107+
test_type_localVariable() async {
108+
await assertErrorsInCode(r'''
109+
void testTypeRef() {
110+
String s = '';
111+
var String = '';
112+
print(s + String);
113+
}
114+
''', [
115+
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 23, 6,
116+
expectedMessages: [message('/test/lib/test.dart', 44, 6)]),
117+
]);
118+
}
119+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(RethrowOutsideCatchTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class RethrowOutsideCatchTest extends DriverResolutionTest {
18+
test_withoutCatch() async {
19+
await assertErrorsInCode(r'''
20+
f() {
21+
rethrow;
22+
}
23+
''', [
24+
error(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, 8, 7),
25+
]);
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ReturnInGenerativeConstructorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ReturnInGenerativeConstructorTest extends DriverResolutionTest {
18+
test_blockBody() async {
19+
await assertErrorsInCode(r'''
20+
class A {
21+
A() { return 0; }
22+
}
23+
''', [
24+
error(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, 25, 1),
25+
]);
26+
}
27+
28+
test_expressionFunctionBody() async {
29+
await assertErrorsInCode(r'''
30+
class A {
31+
A() => null;
32+
}
33+
''', [
34+
error(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, 16, 8),
35+
]);
36+
}
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ReturnInGeneratorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ReturnInGeneratorTest extends DriverResolutionTest {
18+
test_asyncStar() async {
19+
await assertErrorsInCode(r'''
20+
f() async* {
21+
return 0;
22+
}
23+
''', [
24+
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 9),
25+
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 6),
26+
]);
27+
}
28+
29+
test_syncStar() async {
30+
await assertErrorsInCode(r'''
31+
f() sync* {
32+
return 0;
33+
}
34+
''', [
35+
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 9),
36+
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 6),
37+
]);
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2019, 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 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(SharedDeferredPrefixTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class SharedDeferredPrefixTest extends DriverResolutionTest {
18+
test_hasSharedDeferredPrefix() async {
19+
newFile('/test/lib/lib1.dart', content: '''
20+
library lib1;
21+
f1() {}
22+
''');
23+
newFile('/test/lib/lib2.dart', content: '''
24+
library lib2;
25+
f2() {}
26+
''');
27+
await assertErrorsInCode('''
28+
library root;
29+
import 'lib1.dart' deferred as lib;
30+
import 'lib2.dart' as lib;
31+
main() { lib.f1(); lib.f2(); }
32+
''', [
33+
error(CompileTimeErrorCode.SHARED_DEFERRED_PREFIX, 33, 8),
34+
]);
35+
}
36+
}

0 commit comments

Comments
 (0)