OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 |
11 import 'dart:async'; | 11 import 'dart:async'; |
12 import 'dart:convert'; | 12 import 'dart:convert'; |
13 import 'dart:io'; | 13 import 'dart:io'; |
14 import 'dart:json' as json; | |
15 import 'dart:math'; | 14 import 'dart:math'; |
16 | 15 |
17 import 'package:http/testing.dart'; | 16 import 'package:http/testing.dart'; |
18 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
19 import 'package:scheduled_test/scheduled_process.dart'; | 18 import 'package:scheduled_test/scheduled_process.dart'; |
20 import 'package:scheduled_test/scheduled_server.dart'; | 19 import 'package:scheduled_test/scheduled_server.dart'; |
21 import 'package:scheduled_test/scheduled_test.dart'; | 20 import 'package:scheduled_test/scheduled_test.dart'; |
22 import 'package:unittest/compact_vm_config.dart'; | 21 import 'package:unittest/compact_vm_config.dart'; |
23 | 22 |
24 import '../lib/src/entrypoint.dart'; | 23 import '../lib/src/entrypoint.dart'; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 var name = spec['name']; | 190 var name = spec['name']; |
192 var version = spec['version']; | 191 var version = spec['version']; |
193 var versions = _servedPackages.putIfAbsent(name, () => []); | 192 var versions = _servedPackages.putIfAbsent(name, () => []); |
194 versions.add(spec); | 193 versions.add(spec); |
195 } | 194 } |
196 | 195 |
197 _servedApiPackageDir.contents.clear(); | 196 _servedApiPackageDir.contents.clear(); |
198 _servedPackageDir.contents.clear(); | 197 _servedPackageDir.contents.clear(); |
199 for (var name in _servedPackages.keys) { | 198 for (var name in _servedPackages.keys) { |
200 _servedApiPackageDir.contents.addAll([ | 199 _servedApiPackageDir.contents.addAll([ |
201 d.file('$name', json.stringify({ | 200 d.file('$name', JSON.encode({ |
202 'name': name, | 201 'name': name, |
203 'uploaders': ['nweiz@google.com'], | 202 'uploaders': ['nweiz@google.com'], |
204 'versions': _servedPackages[name].map(packageVersionApiMap).toList() | 203 'versions': _servedPackages[name].map(packageVersionApiMap).toList() |
205 })), | 204 })), |
206 d.dir(name, [ | 205 d.dir(name, [ |
207 d.dir('versions', _servedPackages[name].map((pubspec) { | 206 d.dir('versions', _servedPackages[name].map((pubspec) { |
208 return d.file(pubspec['version'], json.stringify( | 207 return d.file(pubspec['version'], JSON.encode( |
209 packageVersionApiMap(pubspec, full: true))); | 208 packageVersionApiMap(pubspec, full: true))); |
210 })) | 209 })) |
211 ]) | 210 ]) |
212 ]); | 211 ]); |
213 | 212 |
214 _servedPackageDir.contents.add(d.dir(name, [ | 213 _servedPackageDir.contents.add(d.dir(name, [ |
215 d.dir('versions', _servedPackages[name].map((pubspec) { | 214 d.dir('versions', _servedPackages[name].map((pubspec) { |
216 var version = pubspec['version']; | 215 var version = pubspec['version']; |
217 return d.tar('$version.tar.gz', [ | 216 return d.tar('$version.tar.gz', [ |
218 d.file('pubspec.yaml', json.stringify(pubspec)), | 217 d.file('pubspec.yaml', JSON.encode(pubspec)), |
219 d.libDir(name, '$name $version') | 218 d.libDir(name, '$name $version') |
220 ]); | 219 ]); |
221 })) | 220 })) |
222 ])); | 221 ])); |
223 } | 222 } |
224 }); | 223 }); |
225 }, 'initializing the package server'); | 224 }, 'initializing the package server'); |
226 } | 225 } |
227 | 226 |
228 /// Converts [value] into a YAML string. | 227 /// Converts [value] into a YAML string. |
229 String yaml(value) => json.stringify(value); | 228 String yaml(value) => JSON.encode(value); |
230 | 229 |
231 /// The full path to the created sandbox directory for an integration test. | 230 /// The full path to the created sandbox directory for an integration test. |
232 String get sandboxDir => _sandboxDir; | 231 String get sandboxDir => _sandboxDir; |
233 String _sandboxDir; | 232 String _sandboxDir; |
234 | 233 |
235 /// The path of the package cache directory used for tests. Relative to the | 234 /// The path of the package cache directory used for tests. Relative to the |
236 /// sandbox directory. | 235 /// sandbox directory. |
237 final String cachePath = "cache"; | 236 final String cachePath = "cache"; |
238 | 237 |
239 /// The path of the mock SDK directory used for tests. Relative to the sandbox | 238 /// The path of the mock SDK directory used for tests. Relative to the sandbox |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 failures.addAll(expected.map((line) => '| $line')); | 733 failures.addAll(expected.map((line) => '| $line')); |
735 failures.add('Got:'); | 734 failures.add('Got:'); |
736 failures.addAll(results); | 735 failures.addAll(results); |
737 } | 736 } |
738 } | 737 } |
739 | 738 |
740 void _validateOutputJson(List<String> failures, String pipe, | 739 void _validateOutputJson(List<String> failures, String pipe, |
741 expected, String actualText) { | 740 expected, String actualText) { |
742 var actual; | 741 var actual; |
743 try { | 742 try { |
744 actual = json.parse(actualText); | 743 actual = JSON.decode(actualText); |
745 } on FormatException catch(error) { | 744 } on FormatException catch(error) { |
746 failures.add('Expected $pipe JSON:'); | 745 failures.add('Expected $pipe JSON:'); |
747 failures.add(expected); | 746 failures.add(expected); |
748 failures.add('Got invalid JSON:'); | 747 failures.add('Got invalid JSON:'); |
749 failures.add(actualText); | 748 failures.add(actualText); |
750 } | 749 } |
751 | 750 |
752 // Do a deep comparison of the JSON objects. | 751 // Do a deep comparison of the JSON objects. |
753 expect(actual, equals(expected)); | 752 expect(actual, equals(expected)); |
754 } | 753 } |
(...skipping 30 matching lines...) Expand all Loading... |
785 bool matches(item, Map matchState) { | 784 bool matches(item, Map matchState) { |
786 if (item is! Pair) return false; | 785 if (item is! Pair) return false; |
787 return _firstMatcher.matches(item.first, matchState) && | 786 return _firstMatcher.matches(item.first, matchState) && |
788 _lastMatcher.matches(item.last, matchState); | 787 _lastMatcher.matches(item.last, matchState); |
789 } | 788 } |
790 | 789 |
791 Description describe(Description description) { | 790 Description describe(Description description) { |
792 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 791 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
793 } | 792 } |
794 } | 793 } |
OLD | NEW |