From 2041871f34fe574a8ce87b6eba0211d3405cf07d Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Fri, 4 Aug 2017 09:20:14 -0700 Subject: [PATCH] Add missed files from previous CL R=scheglov@google.com Review-Url: https://codereview.chromium.org/2990273002 . --- pkg/analyzer/test/error/error_test.dart | 107 ++++++++++++++++++++++++ pkg/analyzer/test/error/test_all.dart | 13 +++ 2 files changed, 120 insertions(+) create mode 100644 pkg/analyzer/test/error/error_test.dart create mode 100644 pkg/analyzer/test/error/test_all.dart diff --git a/pkg/analyzer/test/error/error_test.dart b/pkg/analyzer/test/error/error_test.dart new file mode 100644 index 00000000000..b8d81dea48a --- /dev/null +++ b/pkg/analyzer/test/error/error_test.dart @@ -0,0 +1,107 @@ +// Copyright (c) 2017, 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 'dart:core'; +import 'dart:io'; + +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import '../generated/parser_test.dart'; + +main() { + defineReflectiveSuite(() { + defineReflectiveTests(ErrorCodeValuesTest); + }); +} + +@reflectiveTest +class ErrorCodeValuesTest extends ParserTestCase { + List _rootComponents; + + List get rootComponents { + if (_rootComponents == null) { + List components = path.split(Platform.script.toFilePath()); + _rootComponents = + components.sublist(0, components.indexOf('analyzer') + 1); + } + return _rootComponents; + } + + bool bad() { + return false; + } + + List getDeclaredCodes(List relativeComponents) { + List declaredCodes = []; + CompilationUnit definingUnit = parseFile(relativeComponents); + for (CompilationUnitMember declaration in definingUnit.declarations) { + if (declaration is ClassDeclaration) { + ExtendsClause extendsClause = declaration.extendsClause; + if (extendsClause != null && + extendsClause.superclass.name.name == 'ErrorCode') { + String className = declaration.name.name; + for (ClassMember member in declaration.members) { + if (member is FieldDeclaration && + member.isStatic && + (member.fields.type == null ? bad() : true) && + member.fields.type.toSource() == className) { + String fieldName = member.fields.variables[0].name.name; + declaredCodes.add(className + '.' + fieldName); + } + } + } + } + } + return declaredCodes; + } + + List getListedCodes() { + List listedCodes = []; + CompilationUnit listingUnit = parseFile(['lib', 'error', 'error.dart']); + TopLevelVariableDeclaration declaration = listingUnit.declarations + .firstWhere( + (member) => + member is TopLevelVariableDeclaration && + member.variables.variables[0].name.name == 'errorCodeValues', + orElse: () => null); + ListLiteral listLiteral = declaration.variables.variables[0].initializer; + for (PrefixedIdentifier element in listLiteral.elements) { + listedCodes.add(element.name); + } + return listedCodes; + } + + CompilationUnit parseFile(List relativeComponents) { + List pathComponents = rootComponents.toList() + ..addAll(relativeComponents); + String filePath = path.normalize(path.joinAll(pathComponents)); + return parseCompilationUnit(new File(filePath).readAsStringSync()); + } + + test_errorCodeValues() { + List listedCodes = getListedCodes(); + List missingCodes = []; + List> declaringPaths = [ + ['lib', 'src', 'analysis_options', 'error', 'option_codes.dart'], + ['lib', 'src', 'dart', 'error', 'hint_codes.dart'], + ['lib', 'src', 'dart', 'error', 'lint_codes.dart'], + ['lib', 'src', 'dart', 'error', 'todo_codes.dart'], + ['lib', 'src', 'html', 'error', 'html_codes.dart'], + ['lib', 'src', 'dart', 'error', 'syntactic_errors.dart'], + ['lib', 'src', 'error', 'codes.dart'], + ['..', 'front_end', 'lib', 'src', 'scanner', 'errors.dart'] + ]; + for (List path in declaringPaths) { + for (String declaredCode in getDeclaredCodes(path)) { + if (!listedCodes.contains(declaredCode)) { + missingCodes.add(declaredCode); + } + } + } + expect(missingCodes, isEmpty); + } +} diff --git a/pkg/analyzer/test/error/test_all.dart b/pkg/analyzer/test/error/test_all.dart new file mode 100644 index 00000000000..bf82c241057 --- /dev/null +++ b/pkg/analyzer/test/error/test_all.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2017, 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:test_reflective_loader/test_reflective_loader.dart'; + +import 'error_test.dart' as error_test; + +main() { + defineReflectiveSuite(() { + error_test.main(); + }, name: 'error'); +}