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

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 12087008: Handle parsing the "version" file better. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « utils/tests/pub/real_version_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub
6 /// tests are integration tests that stage some stuff on the file system, run 6 /// tests are integration tests that stage some stuff on the file system, run
7 /// pub, and then validate the results. This library provides an API to build 7 /// pub, and then validate the results. This library provides an API to build
8 /// tests like that. 8 /// tests like that.
9 library test_pub; 9 library test_pub;
10 10
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 801 }
802 802
803 /// Validates that at least one file in [dir] matching [name] is valid 803 /// Validates that at least one file in [dir] matching [name] is valid
804 /// according to [validate]. [validate] should complete to an exception if 804 /// according to [validate]. [validate] should complete to an exception if
805 /// the input path is invalid. 805 /// the input path is invalid.
806 Future _validateOneMatch(String dir, Future validate(String path)) { 806 Future _validateOneMatch(String dir, Future validate(String path)) {
807 // Special-case strings to support multi-level names like "myapp/packages". 807 // Special-case strings to support multi-level names like "myapp/packages".
808 if (name is String) { 808 if (name is String) {
809 var path = join(dir, name); 809 var path = join(dir, name);
810 return exists(path).then((exists) { 810 return exists(path).then((exists) {
811 if (!exists) Expect.fail('File $name in $dir not found.'); 811 if (!exists) {
812 throw new ExpectException('File $name in $dir not found.');
813 }
812 return validate(path); 814 return validate(path);
813 }); 815 });
814 } 816 }
815 817
816 // TODO(nweiz): remove this when issue 4061 is fixed. 818 // TODO(nweiz): remove this when issue 4061 is fixed.
817 var stackTrace; 819 var stackTrace;
818 try { 820 try {
819 throw ""; 821 throw "";
820 } catch (_, localStackTrace) { 822 } catch (_, localStackTrace) {
821 stackTrace = localStackTrace; 823 stackTrace = localStackTrace;
822 } 824 }
823 825
824 return listDir(dir).then((files) { 826 return listDir(dir).then((files) {
825 var matches = files.where((file) => endsWithPattern(file, name)).toList(); 827 var matches = files.where((file) => endsWithPattern(file, name)).toList();
826 if (matches.isEmpty) { 828 if (matches.isEmpty) {
827 Expect.fail('No files in $dir match pattern $name.'); 829 throw new ExpectException('No files in $dir match pattern $name.');
828 } 830 }
829 if (matches.length == 1) return validate(matches[0]); 831 if (matches.length == 1) return validate(matches[0]);
830 832
831 var failures = []; 833 var failures = [];
832 var successes = 0; 834 var successes = 0;
833 var completer = new Completer(); 835 var completer = new Completer();
834 checkComplete() { 836 checkComplete() {
835 if (failures.length + successes != matches.length) return; 837 if (failures.length + successes != matches.length) return;
836 if (successes > 0) { 838 if (successes > 0) {
837 completer.complete(); 839 completer.complete();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 Future delete(dir) { 883 Future delete(dir) {
882 return deleteFile(join(dir, _stringName)); 884 return deleteFile(join(dir, _stringName));
883 } 885 }
884 886
885 /// Validates that this file correctly matches the actual file at [path]. 887 /// Validates that this file correctly matches the actual file at [path].
886 Future validate(String path) { 888 Future validate(String path) {
887 return _validateOneMatch(path, (file) { 889 return _validateOneMatch(path, (file) {
888 return readTextFile(file).then((text) { 890 return readTextFile(file).then((text) {
889 if (text == contents) return null; 891 if (text == contents) return null;
890 892
891 Expect.fail('File $file should contain:\n\n$contents\n\n' 893 throw new ExpectException(
892 'but contained:\n\n$text'); 894 'File $file should contain:\n\n$contents\n\n'
895 'but contained:\n\n$text');
893 }); 896 });
894 }); 897 });
895 } 898 }
896 899
897 /// Loads the contents of the file. 900 /// Loads the contents of the file.
898 InputStream load(List<String> path) { 901 InputStream load(List<String> path) {
899 if (!path.isEmpty) { 902 if (!path.isEmpty) {
900 var joinedPath = Strings.join(path, '/'); 903 var joinedPath = Strings.join(path, '/');
901 throw "Can't load $joinedPath from within $name: not a directory."; 904 throw "Can't load $joinedPath from within $name: not a directory.";
902 } 905 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1129
1127 /// A descriptor that validates that no file exists with the given name. 1130 /// A descriptor that validates that no file exists with the given name.
1128 class NothingDescriptor extends Descriptor { 1131 class NothingDescriptor extends Descriptor {
1129 NothingDescriptor(String name) : super(name); 1132 NothingDescriptor(String name) : super(name);
1130 1133
1131 Future create(dir) => new Future.immediate(null); 1134 Future create(dir) => new Future.immediate(null);
1132 Future delete(dir) => new Future.immediate(null); 1135 Future delete(dir) => new Future.immediate(null);
1133 1136
1134 Future validate(String dir) { 1137 Future validate(String dir) {
1135 return exists(join(dir, name)).then((exists) { 1138 return exists(join(dir, name)).then((exists) {
1136 if (exists) Expect.fail('File $name in $dir should not exist.'); 1139 if (exists) {
1140 throw new ExpectException('File $name in $dir should not exist.');
1141 }
1137 }); 1142 });
1138 } 1143 }
1139 1144
1140 InputStream load(List<String> path) { 1145 InputStream load(List<String> path) {
1141 if (path.isEmpty) { 1146 if (path.isEmpty) {
1142 throw "Can't load the contents of $name: it doesn't exist."; 1147 throw "Can't load the contents of $name: it doesn't exist.";
1143 } else { 1148 } else {
1144 throw "Can't load ${Strings.join(path, '/')} from within $name: $name " 1149 throw "Can't load ${Strings.join(path, '/')} from within $name: $name "
1145 "doesn't exist."; 1150 "doesn't exist.";
1146 } 1151 }
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 /// calling [completion] is unnecessary. 1551 /// calling [completion] is unnecessary.
1547 void expectLater(Future actual, matcher, {String reason, 1552 void expectLater(Future actual, matcher, {String reason,
1548 FailureHandler failureHandler, bool verbose: false}) { 1553 FailureHandler failureHandler, bool verbose: false}) {
1549 _schedule((_) { 1554 _schedule((_) {
1550 return actual.then((value) { 1555 return actual.then((value) {
1551 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1556 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1552 verbose: false); 1557 verbose: false);
1553 }); 1558 });
1554 }); 1559 });
1555 } 1560 }
OLDNEW
« no previous file with comments | « utils/tests/pub/real_version_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698