Skip to content

Commit

Permalink
Move tests for 10 diagnostic codes to diagnostics/ files
Browse files Browse the repository at this point in the history
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
srawlins authored and commit-bot@chromium.org committed Dec 6, 2019
1 parent 4b21941 commit 3281a4a
Show file tree
Hide file tree
Showing 12 changed files with 653 additions and 503 deletions.
511 changes: 8 additions & 503 deletions pkg/analyzer/test/generated/compile_time_error_code.dart

Large diffs are not rendered by default.

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),
]);
}
}
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),
]);
}
}
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 pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart
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),
]);
}
}
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 pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart
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 pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart
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),
]);
}
}
Loading

0 comments on commit 3281a4a

Please sign in to comment.