| OLD | NEW |
| (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:io'; |
| 6 |
| 7 import 'package:analysis_server/src/services/correction/strings.dart'; |
| 8 import 'package:path/path.dart' as path; |
| 9 import 'package:test/test.dart'; |
| 10 |
| 11 import '../../tool/spec/api.dart'; |
| 12 import '../../tool/spec/from_html.dart'; |
| 13 |
| 14 // TODO(devoncarew): Several of the analysis domain methods are covered, but |
| 15 // they aren't using the below file name pattern. |
| 16 |
| 17 /// Define tests to fail if there's no mention in the coverage file. |
| 18 main() { |
| 19 Api api; |
| 20 File coverageFile; |
| 21 String pathPrefix; |
| 22 |
| 23 // parse the API file |
| 24 if (FileSystemEntity |
| 25 .isFileSync(path.join('tool', 'spec', 'spec_input.html'))) { |
| 26 api = readApi('.'); |
| 27 pathPrefix = '.'; |
| 28 } else { |
| 29 api = readApi(path.join('pkg', 'analysis_server')); |
| 30 pathPrefix = path.join('pkg', 'analysis_server'); |
| 31 } |
| 32 |
| 33 coverageFile = |
| 34 new File(path.join(pathPrefix, 'test', 'integration', 'coverage.md')); |
| 35 List<String> lines = coverageFile.readAsLinesSync(); |
| 36 |
| 37 // ## server domain |
| 38 Set<String> coveredDomains = lines |
| 39 .where((line) => line.startsWith('## ') && line.endsWith(' domain')) |
| 40 .map((line) => |
| 41 line.substring('##'.length, line.length - 'domain'.length).trim()) |
| 42 .toSet(); |
| 43 |
| 44 // - [ ] server.getVersion |
| 45 Set<String> allMembers = lines |
| 46 .where((line) => line.startsWith('- ')) |
| 47 .map((line) => line.substring('- [ ]'.length).trim()) |
| 48 .toSet(); |
| 49 Set<String> coveredMembers = lines |
| 50 .where((line) => line.startsWith('- [x]')) |
| 51 .map((line) => line.substring('- [x]'.length).trim()) |
| 52 .toSet(); |
| 53 |
| 54 // generate domain tests |
| 55 for (Domain domain in api.domains) { |
| 56 group('integration coverage of ${domain.name}', () { |
| 57 // domain |
| 58 test('domain', () { |
| 59 if (!coveredDomains.contains(domain.name)) { |
| 60 fail('${domain.name} domain not found in ${coverageFile.path}'); |
| 61 } |
| 62 }); |
| 63 |
| 64 // requests |
| 65 for (Request request in domain.requests) { |
| 66 String fullName = '${domain.name}.${request.method}'; |
| 67 test(fullName, () { |
| 68 if (!allMembers.contains(fullName)) { |
| 69 fail('$fullName not found in ${coverageFile.path}'); |
| 70 } |
| 71 |
| 72 final String fileName = getCamelWords(request.method) |
| 73 .map((s) => s.toLowerCase()) |
| 74 .join('_'); |
| 75 final String testName = |
| 76 path.join(domain.name, '${fileName}_test.dart'); |
| 77 final String testPath = |
| 78 path.join(pathPrefix, 'test', 'integration', testName); |
| 79 |
| 80 // Test that if checked, a test file exists; if not checked, no such |
| 81 // file exists. |
| 82 expect(FileSystemEntity.isFileSync(testPath), |
| 83 coveredMembers.contains(fullName), |
| 84 reason: '$testName state incorrect'); |
| 85 }); |
| 86 } |
| 87 }); |
| 88 } |
| 89 |
| 90 // validate no unexpected domains |
| 91 group('integration coverage', () { |
| 92 test('no unexpected domains', () { |
| 93 for (String domain in coveredDomains) { |
| 94 expect(api.domains.map((d) => d.name), contains(domain)); |
| 95 } |
| 96 }); |
| 97 }); |
| 98 } |
| OLD | NEW |