Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: pkg/analyzer/test/error/error_test.dart

Issue 2990273002: Add missed files from previous CL (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/error/test_all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 'dart:core';
6 import 'dart:io';
7
8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:path/path.dart' as path;
10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12
13 import '../generated/parser_test.dart';
14
15 main() {
16 defineReflectiveSuite(() {
17 defineReflectiveTests(ErrorCodeValuesTest);
18 });
19 }
20
21 @reflectiveTest
22 class ErrorCodeValuesTest extends ParserTestCase {
23 List<String> _rootComponents;
24
25 List<String> get rootComponents {
26 if (_rootComponents == null) {
27 List<String> components = path.split(Platform.script.toFilePath());
28 _rootComponents =
29 components.sublist(0, components.indexOf('analyzer') + 1);
30 }
31 return _rootComponents;
32 }
33
34 bool bad() {
35 return false;
36 }
37
38 List<String> getDeclaredCodes(List<String> relativeComponents) {
39 List<String> declaredCodes = <String>[];
40 CompilationUnit definingUnit = parseFile(relativeComponents);
41 for (CompilationUnitMember declaration in definingUnit.declarations) {
42 if (declaration is ClassDeclaration) {
43 ExtendsClause extendsClause = declaration.extendsClause;
44 if (extendsClause != null &&
45 extendsClause.superclass.name.name == 'ErrorCode') {
46 String className = declaration.name.name;
47 for (ClassMember member in declaration.members) {
48 if (member is FieldDeclaration &&
49 member.isStatic &&
50 (member.fields.type == null ? bad() : true) &&
51 member.fields.type.toSource() == className) {
52 String fieldName = member.fields.variables[0].name.name;
53 declaredCodes.add(className + '.' + fieldName);
54 }
55 }
56 }
57 }
58 }
59 return declaredCodes;
60 }
61
62 List<String> getListedCodes() {
63 List<String> listedCodes = <String>[];
64 CompilationUnit listingUnit = parseFile(['lib', 'error', 'error.dart']);
65 TopLevelVariableDeclaration declaration = listingUnit.declarations
66 .firstWhere(
67 (member) =>
68 member is TopLevelVariableDeclaration &&
69 member.variables.variables[0].name.name == 'errorCodeValues',
70 orElse: () => null);
71 ListLiteral listLiteral = declaration.variables.variables[0].initializer;
72 for (PrefixedIdentifier element in listLiteral.elements) {
73 listedCodes.add(element.name);
74 }
75 return listedCodes;
76 }
77
78 CompilationUnit parseFile(List<String> relativeComponents) {
79 List<String> pathComponents = rootComponents.toList()
80 ..addAll(relativeComponents);
81 String filePath = path.normalize(path.joinAll(pathComponents));
82 return parseCompilationUnit(new File(filePath).readAsStringSync());
83 }
84
85 test_errorCodeValues() {
86 List<String> listedCodes = getListedCodes();
87 List<String> missingCodes = <String>[];
88 List<List<String>> declaringPaths = [
89 ['lib', 'src', 'analysis_options', 'error', 'option_codes.dart'],
90 ['lib', 'src', 'dart', 'error', 'hint_codes.dart'],
91 ['lib', 'src', 'dart', 'error', 'lint_codes.dart'],
92 ['lib', 'src', 'dart', 'error', 'todo_codes.dart'],
93 ['lib', 'src', 'html', 'error', 'html_codes.dart'],
94 ['lib', 'src', 'dart', 'error', 'syntactic_errors.dart'],
95 ['lib', 'src', 'error', 'codes.dart'],
96 ['..', 'front_end', 'lib', 'src', 'scanner', 'errors.dart']
97 ];
98 for (List<String> path in declaringPaths) {
99 for (String declaredCode in getDeclaredCodes(path)) {
100 if (!listedCodes.contains(declaredCode)) {
101 missingCodes.add(declaredCode);
102 }
103 }
104 }
105 expect(missingCodes, isEmpty);
106 }
107 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/error/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698