analyzer: Move error_supporession_test.dart
Work towards https://github.com/dart-lang/sdk/issues/60635
Also rename the test methods to use camelCase and to read more like
sentences.
Change-Id: If4ef85aeeefc5f1364ffbcba2e73df36981fc951
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432961
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/test/generated/test_all.dart b/pkg/analyzer/test/generated/test_all.dart
index e1dec1f..3f3be83 100644
--- a/pkg/analyzer/test/generated/test_all.dart
+++ b/pkg/analyzer/test/generated/test_all.dart
@@ -9,7 +9,6 @@
import 'collection_literal_parser_test.dart' as collection_literal_parser;
import 'complex_parser_test.dart' as complex_parser;
import 'error_parser_test.dart' as error_parser;
-import 'error_suppression_test.dart' as error_suppression;
import 'expression_parser_test.dart' as expression_parser;
import 'extension_methods_parser_test.dart' as extension_methods_parser;
import 'formal_parameter_parser_test.dart' as formal_parameter_parser;
@@ -49,7 +48,6 @@
collection_literal_parser.main();
complex_parser.main();
error_parser.main();
- error_suppression.main();
expression_parser.main();
extension_methods_parser.main();
formal_parameter_parser.main();
diff --git a/pkg/analyzer/test/generated/error_suppression_test.dart b/pkg/analyzer/test/src/ignore_comments/diagnostic_suppression_test.dart
similarity index 81%
rename from pkg/analyzer/test/generated/error_suppression_test.dart
rename to pkg/analyzer/test/src/ignore_comments/diagnostic_suppression_test.dart
index 274a686..6e20079 100644
--- a/pkg/analyzer/test/generated/error_suppression_test.dart
+++ b/pkg/analyzer/test/src/ignore_comments/diagnostic_suppression_test.dart
@@ -7,7 +7,7 @@
import 'package:linter/src/lint_codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../src/dart/resolution/context_collection_resolution.dart';
+import '../../src/dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
@@ -30,7 +30,7 @@
);
}
- test_error_code_mismatch() async {
+ test_codeMismatch() async {
await assertErrorsInCode(
'''
// ignore: $ignoredCode
@@ -44,7 +44,7 @@
);
}
- test_ignore_first() async {
+ test_ignoreFirstOfMultiple() async {
await assertErrorsInCode(
'''
// ignore: unnecessary_cast
@@ -56,7 +56,7 @@
);
}
- test_ignore_first_trailing() async {
+ test_ignoreFirstOfMultipleWithTrailingComment() async {
await assertErrorsInCode(
'''
int x = (0 as int); // ignore: unnecessary_cast
@@ -67,7 +67,7 @@
);
}
- test_ignore_for_file() async {
+ test_ignoreForFile() async {
await assertErrorsInCode(
'''
int x = (0 as int); //UNNECESSARY_CAST
@@ -78,7 +78,7 @@
);
}
- test_ignore_for_file_whitespace_variant() async {
+ test_ignoreForFileWithMuchWhitespace() async {
await assertNoErrorsInCode('''
//ignore_for_file: unused_element , unnecessary_cast
int x = (0 as int); //UNNECESSARY_CAST
@@ -86,13 +86,47 @@
''');
}
- test_ignore_only_trailing() async {
+ test_ignoreForFileWithTypeMatchesLint() async {
+ await assertNoErrorsInCode('''
+// ignore_for_file: type=lint
+void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
+''');
+ }
+
+ test_ignoreForFileWithTypeMatchesUpperCase() async {
+ await assertNoErrorsInCode('''
+// ignore_for_file: TYPE=LINT
+void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
+''');
+ }
+
+ test_ignoreForFileWithTypeMatchesWarning() async {
+ await assertNoErrorsInCode('''
+// ignore_for_file: type=warning
+void f() {
+ var x = 1;
+}
+''');
+ }
+
+ test_ignoreForFileWithTypeMismatchLintVsWarning() async {
+ await assertErrorsInCode(
+ '''
+// ignore_for_file: type=lint
+int a = 0;
+int _x = 1;
+''',
+ [error(WarningCode.UNUSED_ELEMENT, 45, 2)],
+ );
+ }
+
+ test_ignoreOnlyDiagnosticWithTrailingComment() async {
await assertNoErrorsInCode('''
int x = (0 as int); // ignore: unnecessary_cast
''');
}
- test_ignore_second() async {
+ test_ignoreSecondDiagnostic() async {
await assertErrorsInCode(
'''
//UNNECESSARY_CAST
@@ -104,7 +138,7 @@
);
}
- test_ignore_second_trailing() async {
+ test_ignoreSecondDiagnosticWithTrailingComment() async {
await assertErrorsInCode(
'''
//UNNECESSARY_CAST
@@ -115,120 +149,24 @@
);
}
- test_ignore_uniqueName() async {
- writeTestPackageConfigWithMeta();
+ test_ignoreTypeMatches() async {
await assertNoErrorsInCode('''
-import 'package:meta/meta.dart';
-
-int f({@Required('x') int? a}) => 0;
-
-// ignore: missing_required_param_with_details
-int x = f();
+// ignore: type=lint
+void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
''');
}
- test_ignore_upper_case() async {
- await assertNoErrorsInCode('''
-int x = (0 as int); // ignore: UNNECESSARY_CAST
-''');
- }
-
- test_invalid_error_code() async {
+ test_ignoreTypeMismatchLintVsWarning() async {
await assertErrorsInCode(
'''
-// ignore: right_format_wrong_code
-int x = '';
-var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
+// ignore: type=lint
+int _x = 1;
''',
- [
- error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 43, 2),
- error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 59, 2),
- ],
+ [error(WarningCode.UNUSED_ELEMENT, 25, 2)],
);
}
- test_missing_error_codes() async {
- await assertErrorsInCode(
- '''
-int x = 3;
-// ignore:
-String y = x + ''; //INVALID_ASSIGNMENT, ARGUMENT_TYPE_NOT_ASSIGNABLE
-''',
- [
- error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 33, 6),
- error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 37, 2),
- ],
- );
- }
-
- test_missing_metadata_suffix() async {
- await assertErrorsInCode(
- '''
-// ignore invalid_assignment
-String y = 3; //INVALID_ASSIGNMENT
-''',
- [error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 40, 1)],
- );
- }
-
- test_multiple_comments() async {
- await assertErrorsInCode(
- '''
-int x = (0 as int); //This is the first comment...
-// ignore: $ignoredCode
-String _foo = ''; //UNUSED_ELEMENT
-''',
- [error(WarningCode.UNNECESSARY_CAST, 9, 8)],
- );
- }
-
- test_multiple_ignore_for_files() async {
- await assertNoErrorsInCode('''
-int x = (0 as int); //UNNECESSARY_CAST
-String _foo = ''; //UNUSED_ELEMENT
-// ignore_for_file: unnecessary_cast,$ignoredCode
-''');
- }
-
- test_multiple_ignores() async {
- await assertNoErrorsInCode('''
-int x = 3;
-// ignore: unnecessary_cast, $ignoredCode
-int _y = x as int; //UNNECESSARY_CAST, UNUSED_ELEMENT
-''');
- }
-
- test_multiple_ignores_trailing() async {
- await assertNoErrorsInCode('''
-int x = 3;
-int _y = x as int; // ignore: unnecessary_cast, $ignoredCode
-''');
- }
-
- test_no_ignores() async {
- await assertErrorsInCode(
- '''
-int x = ''; //INVALID_ASSIGNMENT
-var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
-''',
- [
- error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 8, 2),
- error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 45, 2),
- ],
- );
- }
-
- test_trailing_not_above() async {
- await assertErrorsInCode(
- '''
-int x = (0 as int); // ignore: unnecessary_cast
-int y = (0 as int);
-''',
- [error(WarningCode.UNNECESSARY_CAST, 57, 8)],
- );
- }
-
- test_type_ignore_badType() async {
+ test_ignoreTypeWithBadType() async {
await assertErrorsInCode(
'''
// ignore: type=wrong
@@ -244,65 +182,127 @@
);
}
- test_type_ignore_match() async {
+ test_ignoreUniqueName() async {
+ writeTestPackageConfigWithMeta();
await assertNoErrorsInCode('''
-// ignore: type=lint
-void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
+import 'package:meta/meta.dart';
+
+int f({@Required('x') int? a}) => 0;
+
+// ignore: missing_required_param_with_details
+int x = f();
''');
}
- test_type_ignore_mismatch_lintVsWarning() async {
+ test_ignoreUpperCase() async {
+ await assertNoErrorsInCode('''
+int x = (0 as int); // ignore: UNNECESSARY_CAST
+''');
+ }
+
+ test_invalidCode() async {
await assertErrorsInCode(
'''
-// ignore: type=lint
-int _x = 1;
+// ignore: right_format_wrong_code
+int x = '';
+var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
''',
- [error(WarningCode.UNUSED_ELEMENT, 25, 2)],
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 43, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 59, 2),
+ ],
);
}
- test_type_ignoreForFile_match_lint() async {
- await assertNoErrorsInCode('''
-// ignore_for_file: type=lint
-void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
-''');
- }
-
- test_type_ignoreForFile_match_upperCase() async {
- await assertNoErrorsInCode('''
-// ignore_for_file: TYPE=LINT
-void f(arg1(int)) {} // AVOID_TYPES_AS_PARAMETER_NAMES
-''');
- }
-
- test_type_ignoreForFile_match_warning() async {
- await assertNoErrorsInCode('''
-// ignore_for_file: type=warning
-void f() {
- var x = 1;
-}
-''');
- }
-
- test_type_ignoreForFile_mismatch_lintVsWarning() async {
+ test_missingCodes() async {
await assertErrorsInCode(
'''
-// ignore_for_file: type=lint
-int a = 0;
-int _x = 1;
+int x = 3;
+// ignore:
+String y = x + ''; //INVALID_ASSIGNMENT, ARGUMENT_TYPE_NOT_ASSIGNABLE
''',
- [error(WarningCode.UNUSED_ELEMENT, 45, 2)],
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 33, 6),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 37, 2),
+ ],
);
}
- test_undefined_function_within_flutter_can_be_ignored() async {
+ test_missingMetadataSuffix() async {
+ await assertErrorsInCode(
+ '''
+// ignore invalid_assignment
+String y = 3; //INVALID_ASSIGNMENT
+''',
+ [error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 40, 1)],
+ );
+ }
+
+ test_multipleCodesInIgnore() async {
+ await assertNoErrorsInCode('''
+int x = 3;
+// ignore: unnecessary_cast, $ignoredCode
+int _y = x as int; //UNNECESSARY_CAST, UNUSED_ELEMENT
+''');
+ }
+
+ test_multipleCodesInIgnoreForFile() async {
+ await assertNoErrorsInCode('''
+int x = (0 as int); //UNNECESSARY_CAST
+String _foo = ''; //UNUSED_ELEMENT
+// ignore_for_file: unnecessary_cast,$ignoredCode
+''');
+ }
+
+ test_multipleCodesInIgnoreTrailingComment() async {
+ await assertNoErrorsInCode('''
+int x = 3;
+int _y = x as int; // ignore: unnecessary_cast, $ignoredCode
+''');
+ }
+
+ test_multipleCommentsPreceding() async {
+ await assertErrorsInCode(
+ '''
+int x = (0 as int); //This is the first comment...
+// ignore: $ignoredCode
+String _foo = ''; //UNUSED_ELEMENT
+''',
+ [error(WarningCode.UNNECESSARY_CAST, 9, 8)],
+ );
+ }
+
+ test_noIgnores() async {
+ await assertErrorsInCode(
+ '''
+int x = ''; //INVALID_ASSIGNMENT
+var y = x + ''; //ARGUMENT_TYPE_NOT_ASSIGNABLE
+''',
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 8, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 45, 2),
+ ],
+ );
+ }
+
+ test_trailingCommentDoesNotCountAsAbove() async {
+ await assertErrorsInCode(
+ '''
+int x = (0 as int); // ignore: unnecessary_cast
+int y = (0 as int);
+''',
+ [error(WarningCode.UNNECESSARY_CAST, 57, 8)],
+ );
+ }
+
+ test_undefinedFunctionWithinFlutterCanBeIgnored() async {
await assertErrorsInFile('$workspaceRootPath/flutterlib/flutter.dart', '''
// ignore: undefined_function
f() => g();
''', []);
}
- test_undefined_function_within_flutter_without_ignore() async {
+ test_undefinedFunctionWithinFlutterWithoutIgnore() async {
await assertErrorsInFile(
'$workspaceRootPath/flutterlib/flutter.dart',
'''
@@ -312,7 +312,7 @@
);
}
- test_undefined_prefixed_name_within_flutter_can_be_ignored() async {
+ test_undefinedPrefixedNameWithinFlutterCanBeIgnored() async {
await assertErrorsInFile('$workspaceRootPath/flutterlib/flutter.dart', '''
import 'dart:collection' as c;
// ignore: undefined_prefixed_name
diff --git a/pkg/analyzer/test/src/ignore_comments/test_all.dart b/pkg/analyzer/test/src/ignore_comments/test_all.dart
index b1e1bf1..7db1109 100644
--- a/pkg/analyzer/test/src/ignore_comments/test_all.dart
+++ b/pkg/analyzer/test/src/ignore_comments/test_all.dart
@@ -4,10 +4,12 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'diagnostic_suppression_test.dart' as diagnostic_suppression_test;
import 'ignore_info_test.dart' as ignore_info;
main() {
defineReflectiveSuite(() {
+ diagnostic_suppression_test.main();
ignore_info.main();
}, name: 'src');
}