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