Chromium Code Reviews| Index: pkg/front_end/test/fasta/messages_test.dart |
| diff --git a/pkg/front_end/test/fasta/messages_test.dart b/pkg/front_end/test/fasta/messages_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..378210a51c845540d401b3e63973768d7c081b6d |
| --- /dev/null |
| +++ b/pkg/front_end/test/fasta/messages_test.dart |
| @@ -0,0 +1,60 @@ |
| +// 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:io'; |
| + |
| +import 'package:yaml/yaml.dart' show loadYaml; |
| + |
| +main(List<String> arguments) async { |
| + Uri messagesFile = Platform.script.resolve("../../messages.yaml"); |
|
ahe
2017/09/01 12:27:55
I think this is more reliable:
Uri.base.resolve("
|
| + Map yaml = loadYaml(await new File.fromUri(messagesFile).readAsStringSync()); |
|
ahe
2017/09/01 12:27:54
Remove Sync.
|
| + |
| + int untestedExampleCount = 0; |
| + int missingExamplesCount = 0; |
| + int missingAnalyzerCode = 0; |
| + int missingDart2jsCode = 0; |
| + List<String> keys = yaml.keys.toList()..sort(); |
| + for (String name in keys) { |
| + var description = yaml[name]; |
| + while (description is String) { |
| + description = yaml[description]; |
| + } |
| + Map map = description; |
| + |
| + int localUntestedExampleCount = countExamples(map, name, 'bytes'); |
| + localUntestedExampleCount += countExamples(map, name, 'declaration'); |
| + localUntestedExampleCount += countExamples(map, name, 'expression'); |
| + localUntestedExampleCount += countExamples(map, name, 'script'); |
| + localUntestedExampleCount += countExamples(map, name, 'statement'); |
| + if (localUntestedExampleCount == 0) ++missingExamplesCount; |
| + untestedExampleCount += localUntestedExampleCount; |
| + |
| + if (map['analyzerCode'] == null) ++missingAnalyzerCode; |
| + if (map['dart2jsCode'] == null) ++missingDart2jsCode; |
| + } |
| + |
| + print('$untestedExampleCount examples not tested'); |
| + print('$missingExamplesCount error codes missing examples'); |
| + print('$missingAnalyzerCode error codes missing analyzer code'); |
| + print('$missingDart2jsCode error codes missing dart2js code'); |
|
ahe
2017/09/01 12:27:54
We don't need dart2js error codes for all errors.
|
| + |
| + // TODO(danrubel): Update this test to assert each count == 0. |
| + // Allow them to be non-zero until messages.yaml has been updated. |
| + return untestedExampleCount == 0 || |
| + missingExamplesCount == 0 || |
| + missingAnalyzerCode == 0 || |
| + missingDart2jsCode == 0 |
| + ? 1 |
| + : 0; |
|
ahe
2017/09/01 12:27:54
In Dart, main's return value is ignored. So how ab
|
| +} |
| + |
| +int countExamples(Map map, String name, String key) { |
| + var example = map[key]; |
| + if (example == null) return 0; |
| + if (example is String) return 1; |
| + if (example is List) return example.length; |
| + if (example is Map) return example.length; |
| + |
| + throw 'Unknown value for $name $key --> ${example.runtimeType}\n $example'; |
| +} |