| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.integration.analysis; | 5 library test.integration.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 @override | 343 @override |
| 344 void populateMismatches(item, List<MismatchDescriber> mismatches) { | 344 void populateMismatches(item, List<MismatchDescriber> mismatches) { |
| 345 if (item is! Map) { | 345 if (item is! Map) { |
| 346 mismatches.add(simpleDescription('is not a map')); | 346 mismatches.add(simpleDescription('is not a map')); |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 if (requiredFields != null) { | 349 if (requiredFields != null) { |
| 350 requiredFields.forEach((String key, Matcher valueMatcher) { | 350 requiredFields.forEach((String key, Matcher valueMatcher) { |
| 351 if (!item.containsKey(key)) { | 351 if (!item.containsKey(key)) { |
| 352 mismatches.add( | 352 mismatches.add((Description mismatchDescription) => |
| 353 (Description mismatchDescription) => mismatchDescription | 353 mismatchDescription |
| 354 .add('is missing field ') | 354 .add('is missing field ') |
| 355 .addDescriptionOf(key) | 355 .addDescriptionOf(key) |
| 356 .add(' (') | 356 .add(' (') |
| 357 .addDescriptionOf(valueMatcher) | 357 .addDescriptionOf(valueMatcher) |
| 358 .add(')')); | 358 .add(')')); |
| 359 } else { | 359 } else { |
| 360 _checkField(key, item[key], valueMatcher, mismatches); | 360 _checkField(key, item[key], valueMatcher, mismatches); |
| 361 } | 361 } |
| 362 }); | 362 }); |
| 363 } | 363 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 374 }); | 374 }); |
| 375 } | 375 } |
| 376 | 376 |
| 377 /** | 377 /** |
| 378 * Check the type of a field called [key], having value [value], using | 378 * Check the type of a field called [key], having value [value], using |
| 379 * [valueMatcher]. If it doesn't match, record a closure in [mismatches] | 379 * [valueMatcher]. If it doesn't match, record a closure in [mismatches] |
| 380 * which can describe the mismatch. | 380 * which can describe the mismatch. |
| 381 */ | 381 */ |
| 382 void _checkField(String key, value, Matcher valueMatcher, | 382 void _checkField(String key, value, Matcher valueMatcher, |
| 383 List<MismatchDescriber> mismatches) { | 383 List<MismatchDescriber> mismatches) { |
| 384 checkSubstructure(value, valueMatcher, mismatches, | 384 checkSubstructure( |
| 385 value, |
| 386 valueMatcher, |
| 387 mismatches, |
| 385 (Description description) => | 388 (Description description) => |
| 386 description.add('field ').addDescriptionOf(key)); | 389 description.add('field ').addDescriptionOf(key)); |
| 387 } | 390 } |
| 388 } | 391 } |
| 389 | 392 |
| 390 /** | 393 /** |
| 391 * Instances of the class [Server] manage a connection to a server process, and | 394 * Instances of the class [Server] manage a connection to a server process, and |
| 392 * facilitate communication to and from the server. | 395 * facilitate communication to and from the server. |
| 393 */ | 396 */ |
| 394 class Server { | 397 class Server { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 _process.stdin.add(UTF8.encoder.convert("${line}\n")); | 586 _process.stdin.add(UTF8.encoder.convert("${line}\n")); |
| 584 return completer.future; | 587 return completer.future; |
| 585 } | 588 } |
| 586 | 589 |
| 587 /** | 590 /** |
| 588 * Start the server. If [debugServer] is `true`, the server will be started | 591 * Start the server. If [debugServer] is `true`, the server will be started |
| 589 * with "--debug", allowing a debugger to be attached. If [profileServer] is | 592 * with "--debug", allowing a debugger to be attached. If [profileServer] is |
| 590 * `true`, the server will be started with "--observe" and | 593 * `true`, the server will be started with "--observe" and |
| 591 * "--pause-isolates-on-exit", allowing the observatory to be used. | 594 * "--pause-isolates-on-exit", allowing the observatory to be used. |
| 592 */ | 595 */ |
| 593 Future start({bool debugServer: false, int diagnosticPort, | 596 Future start( |
| 594 bool profileServer: false, bool newTaskModel: false, | 597 {bool debugServer: false, |
| 598 int diagnosticPort, |
| 599 bool profileServer: false, |
| 600 bool newTaskModel: false, |
| 595 bool useAnalysisHighlight2: false}) { | 601 bool useAnalysisHighlight2: false}) { |
| 596 if (_process != null) { | 602 if (_process != null) { |
| 597 throw new Exception('Process already started'); | 603 throw new Exception('Process already started'); |
| 598 } | 604 } |
| 599 _time.start(); | 605 _time.start(); |
| 600 String dartBinary = Platform.executable; | 606 String dartBinary = Platform.executable; |
| 601 String rootDir = | 607 String rootDir = |
| 602 findRoot(Platform.script.toFilePath(windows: Platform.isWindows)); | 608 findRoot(Platform.script.toFilePath(windows: Platform.isWindows)); |
| 603 String serverPath = normalize(join(rootDir, 'bin', 'server.dart')); | 609 String serverPath = normalize(join(rootDir, 'bin', 'server.dart')); |
| 604 List<String> arguments = []; | 610 List<String> arguments = []; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 iterableMatcher = everyElement(elementMatcher); | 695 iterableMatcher = everyElement(elementMatcher); |
| 690 | 696 |
| 691 @override | 697 @override |
| 692 Description describe(Description description) => | 698 Description describe(Description description) => |
| 693 description.add('List of ').addDescriptionOf(elementMatcher); | 699 description.add('List of ').addDescriptionOf(elementMatcher); |
| 694 | 700 |
| 695 @override | 701 @override |
| 696 Description describeMismatch( | 702 Description describeMismatch( |
| 697 item, Description mismatchDescription, Map matchState, bool verbose) { | 703 item, Description mismatchDescription, Map matchState, bool verbose) { |
| 698 if (item is! List) { | 704 if (item is! List) { |
| 699 return super.describeMismatch( | 705 return super |
| 700 item, mismatchDescription, matchState, verbose); | 706 .describeMismatch(item, mismatchDescription, matchState, verbose); |
| 701 } else { | 707 } else { |
| 702 return iterableMatcher.describeMismatch( | 708 return iterableMatcher.describeMismatch( |
| 703 item, mismatchDescription, matchState, verbose); | 709 item, mismatchDescription, matchState, verbose); |
| 704 } | 710 } |
| 705 } | 711 } |
| 706 | 712 |
| 707 @override | 713 @override |
| 708 bool matches(item, Map matchState) { | 714 bool matches(item, Map matchState) { |
| 709 if (item is! List) { | 715 if (item is! List) { |
| 710 return false; | 716 return false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 737 .add(' to ') | 743 .add(' to ') |
| 738 .addDescriptionOf(valueMatcher); | 744 .addDescriptionOf(valueMatcher); |
| 739 | 745 |
| 740 @override | 746 @override |
| 741 void populateMismatches(item, List<MismatchDescriber> mismatches) { | 747 void populateMismatches(item, List<MismatchDescriber> mismatches) { |
| 742 if (item is! Map) { | 748 if (item is! Map) { |
| 743 mismatches.add(simpleDescription('is not a map')); | 749 mismatches.add(simpleDescription('is not a map')); |
| 744 return; | 750 return; |
| 745 } | 751 } |
| 746 item.forEach((key, value) { | 752 item.forEach((key, value) { |
| 747 checkSubstructure(key, keyMatcher, mismatches, | 753 checkSubstructure( |
| 754 key, |
| 755 keyMatcher, |
| 756 mismatches, |
| 748 (Description description) => | 757 (Description description) => |
| 749 description.add('key ').addDescriptionOf(key)); | 758 description.add('key ').addDescriptionOf(key)); |
| 750 checkSubstructure(value, valueMatcher, mismatches, | 759 checkSubstructure( |
| 760 value, |
| 761 valueMatcher, |
| 762 mismatches, |
| 751 (Description description) => | 763 (Description description) => |
| 752 description.add('field ').addDescriptionOf(key)); | 764 description.add('field ').addDescriptionOf(key)); |
| 753 }); | 765 }); |
| 754 } | 766 } |
| 755 } | 767 } |
| 756 | 768 |
| 757 /** | 769 /** |
| 758 * Matcher that matches a union of different types, each of which is described | 770 * Matcher that matches a union of different types, each of which is described |
| 759 * by a matcher. | 771 * by a matcher. |
| 760 */ | 772 */ |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } else if (i == mismatches.length - 1) { | 855 } else if (i == mismatches.length - 1) { |
| 844 mismatchDescription = mismatchDescription.add(', and '); | 856 mismatchDescription = mismatchDescription.add(', and '); |
| 845 } else { | 857 } else { |
| 846 mismatchDescription = mismatchDescription.add(', '); | 858 mismatchDescription = mismatchDescription.add(', '); |
| 847 } | 859 } |
| 848 } | 860 } |
| 849 mismatchDescription = mismatch(mismatchDescription); | 861 mismatchDescription = mismatch(mismatchDescription); |
| 850 } | 862 } |
| 851 return mismatchDescription; | 863 return mismatchDescription; |
| 852 } else { | 864 } else { |
| 853 return super.describeMismatch( | 865 return super |
| 854 item, mismatchDescription, matchState, verbose); | 866 .describeMismatch(item, mismatchDescription, matchState, verbose); |
| 855 } | 867 } |
| 856 } | 868 } |
| 857 | 869 |
| 858 @override | 870 @override |
| 859 bool matches(item, Map matchState) { | 871 bool matches(item, Map matchState) { |
| 860 List<MismatchDescriber> mismatches = <MismatchDescriber>[]; | 872 List<MismatchDescriber> mismatches = <MismatchDescriber>[]; |
| 861 populateMismatches(item, mismatches); | 873 populateMismatches(item, mismatches); |
| 862 if (mismatches.isEmpty) { | 874 if (mismatches.isEmpty) { |
| 863 return true; | 875 return true; |
| 864 } else { | 876 } else { |
| 865 addStateInfo(matchState, {'mismatches': mismatches}); | 877 addStateInfo(matchState, {'mismatches': mismatches}); |
| 866 return false; | 878 return false; |
| 867 } | 879 } |
| 868 } | 880 } |
| 869 | 881 |
| 870 /** | 882 /** |
| 871 * Populate [mismatches] with descriptions of all the ways in which [item] | 883 * Populate [mismatches] with descriptions of all the ways in which [item] |
| 872 * does not match. | 884 * does not match. |
| 873 */ | 885 */ |
| 874 void populateMismatches(item, List<MismatchDescriber> mismatches); | 886 void populateMismatches(item, List<MismatchDescriber> mismatches); |
| 875 | 887 |
| 876 /** | 888 /** |
| 877 * Create a [MismatchDescriber] describing a mismatch with a simple string. | 889 * Create a [MismatchDescriber] describing a mismatch with a simple string. |
| 878 */ | 890 */ |
| 879 MismatchDescriber simpleDescription(String description) => | 891 MismatchDescriber simpleDescription(String description) => |
| 880 (Description mismatchDescription) { | 892 (Description mismatchDescription) { |
| 881 mismatchDescription.add(description); | 893 mismatchDescription.add(description); |
| 882 }; | 894 }; |
| 883 } | 895 } |
| OLD | NEW |