Skip to content

Commit 01c217e

Browse files
committed
Analyzer: Move tests for 5 codes to diagnostics/
Change-Id: I6545819d659f18b0bbd0cf79b10c564a0bd66777 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155848 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 1a829bb commit 01c217e

9 files changed

+293
-196
lines changed

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 0 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -178,134 +178,6 @@ f(p) { return const A(p); }
178178
]);
179179
}
180180

181-
test_constWithNonType() async {
182-
await assertErrorsInCode(r'''
183-
int A;
184-
f() {
185-
return const A();
186-
}
187-
''', [
188-
error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 28, 1),
189-
]);
190-
}
191-
192-
test_constWithNonType_fromLibrary() async {
193-
newFile('/test/lib/lib1.dart');
194-
await assertErrorsInCode('''
195-
import 'lib1.dart' as lib;
196-
void f() {
197-
const lib.A();
198-
}
199-
''', [
200-
error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 50, 1),
201-
]);
202-
}
203-
204-
test_constWithTypeParameters_direct() async {
205-
await assertErrorsInCode(r'''
206-
class A<T> {
207-
static const V = const A<T>();
208-
const A();
209-
}
210-
''', [
211-
error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 40, 1),
212-
error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 40, 1),
213-
]);
214-
}
215-
216-
test_constWithTypeParameters_indirect() async {
217-
await assertErrorsInCode(r'''
218-
class A<T> {
219-
static const V = const A<List<T>>();
220-
const A();
221-
}
222-
''', [
223-
error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 45, 1),
224-
error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 45, 1),
225-
]);
226-
}
227-
228-
test_constWithUndefinedConstructor() async {
229-
await assertErrorsInCode(r'''
230-
class A {
231-
const A();
232-
}
233-
f() {
234-
return const A.noSuchConstructor();
235-
}
236-
''', [
237-
error(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, 48, 17),
238-
]);
239-
}
240-
241-
test_constWithUndefinedConstructorDefault() async {
242-
await assertErrorsInCode(r'''
243-
class A {
244-
const A.name();
245-
}
246-
f() {
247-
return const A();
248-
}
249-
''', [
250-
error(
251-
CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 51, 1),
252-
]);
253-
}
254-
255-
test_extraPositionalArguments_const() async {
256-
await assertErrorsInCode(r'''
257-
class A {
258-
const A();
259-
}
260-
main() {
261-
const A(0);
262-
}
263-
''', [
264-
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 43, 3),
265-
]);
266-
}
267-
268-
test_extraPositionalArguments_const_super() async {
269-
await assertErrorsInCode(r'''
270-
class A {
271-
const A();
272-
}
273-
class B extends A {
274-
const B() : super(0);
275-
}
276-
''', [
277-
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 64, 3),
278-
]);
279-
}
280-
281-
test_extraPositionalArgumentsCouldBeNamed_const() async {
282-
await assertErrorsInCode(r'''
283-
class A {
284-
const A({int x});
285-
}
286-
main() {
287-
const A(0);
288-
}
289-
''', [
290-
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 50,
291-
3),
292-
]);
293-
}
294-
295-
test_extraPositionalArgumentsCouldBeNamed_const_super() async {
296-
await assertErrorsInCode(r'''
297-
class A {
298-
const A({int x});
299-
}
300-
class B extends A {
301-
const B() : super(0);
302-
}
303-
''', [
304-
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 71,
305-
3),
306-
]);
307-
}
308-
309181
test_fromEnvironment_bool_badArgs() async {
310182
await assertErrorsInCode(r'''
311183
var b1 = const bool.fromEnvironment(1);
@@ -359,80 +231,13 @@ main() { new C().f(<S>(S s) => s); }
359231
]);
360232
}
361233

362-
test_genericFunctionTypeAsBound_class() async {
363-
await assertErrorsInCode(r'''
364-
class C<T extends S Function<S>(S)> {
365-
}
366-
''', [
367-
error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 18, 16),
368-
]);
369-
}
370-
371-
test_genericFunctionTypeAsBound_genericFunction() async {
372-
await assertErrorsInCode(r'''
373-
T Function<T extends S Function<S>(S)>(T) fun;
374-
''', [
375-
error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 21, 16),
376-
]);
377-
}
378-
379-
test_genericFunctionTypeAsBound_genericFunctionTypedef() async {
380-
await assertErrorsInCode(r'''
381-
typedef foo = T Function<T extends S Function<S>(S)>(T t);
382-
''', [
383-
error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 35, 16),
384-
]);
385-
}
386-
387-
test_genericFunctionTypeAsBound_parameterOfFunction() async {
388-
await assertNoErrorsInCode(r'''
389-
class C<T extends void Function(S Function<S>(S))> {}
390-
''');
391-
}
392-
393-
test_genericFunctionTypeAsBound_typedef() async {
394-
await assertErrorsInCode(r'''
395-
typedef T foo<T extends S Function<S>(S)>(T t);
396-
''', [
397-
error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPE_CANNOT_BE_BOUND, 24, 16),
398-
]);
399-
}
400-
401234
test_genericFunctionTypedParameter() async {
402235
var code = '''
403236
void g(T f<T>(T x)) {}
404237
''';
405238
await assertNoErrorsInCode(code);
406239
}
407240

408-
test_importInternalLibrary() async {
409-
// Note, in these error cases we may generate an UNUSED_IMPORT hint, while
410-
// we could prevent the hint from being generated by testing the import
411-
// directive for the error, this is such a minor corner case that we don't
412-
// think we should add the additional computation time to figure out such
413-
// cases.
414-
await assertErrorsInCode('''
415-
import 'dart:_interceptors';
416-
''', [
417-
error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 20),
418-
error(HintCode.UNUSED_IMPORT, 7, 20),
419-
]);
420-
}
421-
422-
test_importOfNonLibrary() async {
423-
newFile("/test/lib/part.dart", content: r'''
424-
part of lib;
425-
class A{}
426-
''');
427-
await assertErrorsInCode(r'''
428-
library lib;
429-
import 'part.dart';
430-
A a;
431-
''', [
432-
error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 20, 11),
433-
]);
434-
}
435-
436241
test_length_of_erroneous_constant() async {
437242
// Attempting to compute the length of constant that couldn't be evaluated
438243
// (due to an error) should not crash the analyzer (see dartbug.com/23383)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2020, 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(ConstWithNonTypeTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ConstWithNonTypeTest extends DriverResolutionTest {
18+
test_fromLibrary() async {
19+
newFile('/test/lib/lib1.dart');
20+
await assertErrorsInCode('''
21+
import 'lib1.dart' as lib;
22+
void f() {
23+
const lib.A();
24+
}
25+
''', [
26+
error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 50, 1),
27+
]);
28+
}
29+
30+
test_variable() async {
31+
await assertErrorsInCode(r'''
32+
int A;
33+
f() {
34+
return const A();
35+
}
36+
''', [
37+
error(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 28, 1),
38+
]);
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2020, 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(ConstWithTypeParametersTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ConstWithTypeParametersTest extends DriverResolutionTest {
18+
test_direct() async {
19+
await assertErrorsInCode(r'''
20+
class A<T> {
21+
static const V = const A<T>();
22+
const A();
23+
}
24+
''', [
25+
error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 40, 1),
26+
error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 40, 1),
27+
]);
28+
}
29+
30+
test_indirect() async {
31+
await assertErrorsInCode(r'''
32+
class A<T> {
33+
static const V = const A<List<T>>();
34+
const A();
35+
}
36+
''', [
37+
error(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 45, 1),
38+
error(CompileTimeErrorCode.TYPE_PARAMETER_REFERENCED_BY_STATIC, 45, 1),
39+
]);
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2020, 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(ConstWithUndefinedConstructorTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ConstWithUndefinedConstructorTest extends DriverResolutionTest {
18+
test_named() async {
19+
await assertErrorsInCode(r'''
20+
class A {
21+
const A();
22+
}
23+
f() {
24+
return const A.noSuchConstructor();
25+
}
26+
''', [
27+
error(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, 48, 17),
28+
]);
29+
}
30+
31+
test_unnamed() async {
32+
await assertErrorsInCode(r'''
33+
class A {
34+
const A.name();
35+
}
36+
f() {
37+
return const A();
38+
}
39+
''', [
40+
error(
41+
CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 51, 1),
42+
]);
43+
}
44+
}

0 commit comments

Comments
 (0)