|
| 1 | +// Copyright (c) 2024, 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:test_reflective_loader/test_reflective_loader.dart'; |
| 6 | + |
| 7 | +import '../rule_test_support.dart'; |
| 8 | + |
| 9 | +main() { |
| 10 | + defineReflectiveSuite(() { |
| 11 | + defineReflectiveTests(AlwaysDeclareReturnTypesTest); |
| 12 | + }); |
| 13 | +} |
| 14 | + |
| 15 | +@reflectiveTest |
| 16 | +class AlwaysDeclareReturnTypesTest extends LintRuleTest { |
| 17 | + @override |
| 18 | + String get lintRule => 'always_declare_return_types'; |
| 19 | + |
| 20 | + test_augmentationClass() async { |
| 21 | + var a = newFile('$testPackageLibPath/a.dart', r''' |
| 22 | +import augment 'b.dart'; |
| 23 | +
|
| 24 | +class A { } |
| 25 | +'''); |
| 26 | + |
| 27 | + var b = newFile('$testPackageLibPath/b.dart', r''' |
| 28 | +augment library 'a.dart'; |
| 29 | +
|
| 30 | +augment class A { |
| 31 | + f() { } |
| 32 | +} |
| 33 | +'''); |
| 34 | + |
| 35 | + result = await resolveFile(a.path); |
| 36 | + await assertNoDiagnosticsIn(errors); |
| 37 | + |
| 38 | + result = await resolveFile(b.path); |
| 39 | + await assertDiagnosticsIn(errors, [ |
| 40 | + lint(47, 1), |
| 41 | + ]); |
| 42 | + } |
| 43 | + |
| 44 | + test_augmentationTopLevelFunction() async { |
| 45 | + var a = newFile('$testPackageLibPath/a.dart', r''' |
| 46 | +import augment 'b.dart'; |
| 47 | +'''); |
| 48 | + |
| 49 | + var b = newFile('$testPackageLibPath/b.dart', r''' |
| 50 | +augment library 'a.dart'; |
| 51 | +
|
| 52 | +f() { } |
| 53 | +'''); |
| 54 | + |
| 55 | + result = await resolveFile(a.path); |
| 56 | + await assertNoDiagnosticsIn(errors); |
| 57 | + |
| 58 | + result = await resolveFile(b.path); |
| 59 | + await assertDiagnosticsIn(errors, [ |
| 60 | + lint(27, 1), |
| 61 | + ]); |
| 62 | + } |
| 63 | + |
| 64 | + /// Augmentation target chain variations tested in `augmentedTopLevelFunction{*}`. |
| 65 | + test_augmentedMethod() async { |
| 66 | + var a = newFile('$testPackageLibPath/a.dart', r''' |
| 67 | +import augment 'b.dart'; |
| 68 | +
|
| 69 | +class A { |
| 70 | + f() { } |
| 71 | +} |
| 72 | +'''); |
| 73 | + |
| 74 | + var b = newFile('$testPackageLibPath/b.dart', r''' |
| 75 | +augment library 'a.dart'; |
| 76 | +
|
| 77 | +augment class A { |
| 78 | + augment f() { } |
| 79 | +} |
| 80 | +'''); |
| 81 | + |
| 82 | + result = await resolveFile(a.path); |
| 83 | + await assertDiagnosticsIn(errors, [ |
| 84 | + lint(38, 1), |
| 85 | + ]); |
| 86 | + |
| 87 | + result = await resolveFile(b.path); |
| 88 | + await assertNoDiagnosticsIn(errors); |
| 89 | + } |
| 90 | + |
| 91 | + test_augmentedTopLevelFunction() async { |
| 92 | + var a = newFile('$testPackageLibPath/a.dart', r''' |
| 93 | +import augment 'b.dart'; |
| 94 | +
|
| 95 | +f() { } |
| 96 | +'''); |
| 97 | + |
| 98 | + var b = newFile('$testPackageLibPath/b.dart', r''' |
| 99 | +augment library 'a.dart'; |
| 100 | +
|
| 101 | +augment f() { } |
| 102 | +'''); |
| 103 | + |
| 104 | + result = await resolveFile(a.path); |
| 105 | + await assertDiagnosticsIn(errors, [ |
| 106 | + lint(26, 1), |
| 107 | + ]); |
| 108 | + |
| 109 | + result = await resolveFile(b.path); |
| 110 | + await assertNoDiagnosticsIn(errors); |
| 111 | + } |
| 112 | + |
| 113 | + test_augmentedTopLevelFunction_chain() async { |
| 114 | + var a = newFile('$testPackageLibPath/a.dart', r''' |
| 115 | +import augment 'b.dart'; |
| 116 | +
|
| 117 | +f() { } |
| 118 | +'''); |
| 119 | + |
| 120 | + var b = newFile('$testPackageLibPath/b.dart', r''' |
| 121 | +augment library 'a.dart'; |
| 122 | +
|
| 123 | +augment dynamic f() { } |
| 124 | +augment f() { } |
| 125 | +'''); |
| 126 | + |
| 127 | + result = await resolveFile(a.path); |
| 128 | + await assertDiagnosticsIn(errors, [ |
| 129 | + lint(26, 1), |
| 130 | + ]); |
| 131 | + |
| 132 | + result = await resolveFile(b.path); |
| 133 | + await assertNoDiagnosticsIn(errors); |
| 134 | + } |
| 135 | +} |
0 commit comments