-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
12 changed files
with
653 additions
and
503 deletions.
There are no files selected for viewing
511 changes: 8 additions & 503 deletions
511
pkg/analyzer/test/generated/compile_time_error_code.dart
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
pkg/analyzer/test/src/diagnostics/redirect_generative_to_missing_constructor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(RedirectGenerativeToNonGenerativeConstructorTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class RedirectGenerativeToNonGenerativeConstructorTest | ||
extends DriverResolutionTest { | ||
test_missing() async { | ||
await assertErrorsInCode(r''' | ||
class A { | ||
A() : this.noSuchConstructor(); | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, 18, | ||
24), | ||
]); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...analyzer/test/src/diagnostics/redirect_generative_to_non_generative_constructor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(RedirectGenerativeToNonGenerativeConstructorTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class RedirectGenerativeToNonGenerativeConstructorTest | ||
extends DriverResolutionTest { | ||
test_nonGenerative() async { | ||
await assertErrorsInCode(r''' | ||
class A { | ||
A() : this.x(); | ||
factory A.x() => null; | ||
} | ||
''', [ | ||
error( | ||
CompileTimeErrorCode | ||
.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR, | ||
18, | ||
8), | ||
]); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
pkg/analyzer/test/src/diagnostics/referenced_before_declaration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(ReferencedBeforeDeclarationTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ReferencedBeforeDeclarationTest extends DriverResolutionTest { | ||
test_hideInBlock_comment() async { | ||
await assertNoErrorsInCode(r''' | ||
main() { | ||
/// [v] is a variable. | ||
var v = 2; | ||
} | ||
print(x) {} | ||
'''); | ||
} | ||
|
||
test_hideInBlock_function() async { | ||
await assertErrorsInCode(r''' | ||
var v = 1; | ||
main() { | ||
print(v); | ||
v() {} | ||
} | ||
print(x) {} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 28, 1, | ||
expectedMessages: [message('/test/lib/test.dart', 34, 1)]), | ||
]); | ||
} | ||
|
||
test_hideInBlock_local() async { | ||
await assertErrorsInCode(r''' | ||
var v = 1; | ||
main() { | ||
print(v); | ||
var v = 2; | ||
} | ||
print(x) {} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 28, 1, | ||
expectedMessages: [message('/test/lib/test.dart', 38, 1)]), | ||
]); | ||
} | ||
|
||
test_hideInBlock_subBlock() async { | ||
await assertErrorsInCode(r''' | ||
var v = 1; | ||
main() { | ||
{ | ||
print(v); | ||
} | ||
var v = 2; | ||
} | ||
print(x) {} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 34, 1, | ||
expectedMessages: [message('/test/lib/test.dart', 48, 1)]), | ||
]); | ||
} | ||
|
||
test_inInitializer_closure() async { | ||
await assertErrorsInCode(r''' | ||
main() { | ||
var v = () => v; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 25, 1, | ||
expectedMessages: [message('/test/lib/test.dart', 15, 1)]), | ||
]); | ||
} | ||
|
||
test_inInitializer_directly() async { | ||
await assertErrorsInCode(r''' | ||
main() { | ||
var v = v; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 19, 1, | ||
expectedMessages: [message('/test/lib/test.dart', 15, 1)]), | ||
]); | ||
} | ||
|
||
test_type_localFunction() async { | ||
await assertErrorsInCode(r''' | ||
void testTypeRef() { | ||
String s = ''; | ||
int String(int x) => x + 1; | ||
print(s + String); | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 23, 6, | ||
expectedMessages: [message('/test/lib/test.dart', 44, 6)]), | ||
]); | ||
} | ||
|
||
test_type_localVariable() async { | ||
await assertErrorsInCode(r''' | ||
void testTypeRef() { | ||
String s = ''; | ||
var String = ''; | ||
print(s + String); | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 23, 6, | ||
expectedMessages: [message('/test/lib/test.dart', 44, 6)]), | ||
]); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(RethrowOutsideCatchTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class RethrowOutsideCatchTest extends DriverResolutionTest { | ||
test_withoutCatch() async { | ||
await assertErrorsInCode(r''' | ||
f() { | ||
rethrow; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, 8, 7), | ||
]); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
pkg/analyzer/test/src/diagnostics/return_in_generative_constructor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(ReturnInGenerativeConstructorTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ReturnInGenerativeConstructorTest extends DriverResolutionTest { | ||
test_blockBody() async { | ||
await assertErrorsInCode(r''' | ||
class A { | ||
A() { return 0; } | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, 25, 1), | ||
]); | ||
} | ||
|
||
test_expressionFunctionBody() async { | ||
await assertErrorsInCode(r''' | ||
class A { | ||
A() => null; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, 16, 8), | ||
]); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(ReturnInGeneratorTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ReturnInGeneratorTest extends DriverResolutionTest { | ||
test_asyncStar() async { | ||
await assertErrorsInCode(r''' | ||
f() async* { | ||
return 0; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 9), | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 6), | ||
]); | ||
} | ||
|
||
test_syncStar() async { | ||
await assertErrorsInCode(r''' | ||
f() sync* { | ||
return 0; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 9), | ||
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 6), | ||
]); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(SharedDeferredPrefixTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class SharedDeferredPrefixTest extends DriverResolutionTest { | ||
test_hasSharedDeferredPrefix() async { | ||
newFile('/test/lib/lib1.dart', content: ''' | ||
library lib1; | ||
f1() {} | ||
'''); | ||
newFile('/test/lib/lib2.dart', content: ''' | ||
library lib2; | ||
f2() {} | ||
'''); | ||
await assertErrorsInCode(''' | ||
library root; | ||
import 'lib1.dart' deferred as lib; | ||
import 'lib2.dart' as lib; | ||
main() { lib.f1(); lib.f2(); } | ||
''', [ | ||
error(CompileTimeErrorCode.SHARED_DEFERRED_PREFIX, 33, 8), | ||
]); | ||
} | ||
} |
Oops, something went wrong.