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

Side by Side Diff: sdk/lib/_internal/pub_generated/test/lock_file_test.dart

Issue 896623005: Use native async/await support in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 5 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library lock_file_test;
6
7 import 'dart:async';
8
9 import 'package:pub_semver/pub_semver.dart';
10 import 'package:unittest/unittest.dart';
11 import 'package:yaml/yaml.dart';
12
13 import '../lib/src/lock_file.dart';
14 import '../lib/src/package.dart';
15 import '../lib/src/pubspec.dart';
16 import '../lib/src/source.dart';
17 import '../lib/src/source_registry.dart';
18 import 'test_pub.dart';
19
20 class MockSource extends Source {
21 final String name = 'mock';
22
23 Future<Pubspec> doDescribe(PackageId id) =>
24 throw new UnsupportedError("Cannot describe mock packages.");
25
26 Future get(PackageId id, String symlink) =>
27 throw new UnsupportedError("Cannot get a mock package.");
28
29 Future<String> getDirectory(PackageId id) =>
30 throw new UnsupportedError("Cannot get the directory for mock packages.");
31
32 dynamic parseDescription(String filePath, String description,
33 {bool fromLockFile: false}) {
34 if (!description.endsWith(' desc')) throw new FormatException();
35 return description;
36 }
37
38 bool descriptionsEqual(description1, description2) =>
39 description1 == description2;
40
41 String packageName(String description) {
42 // Strip off ' desc'.
43 return description.substring(0, description.length - 5);
44 }
45 }
46
47 main() {
48 initConfig();
49
50 var sources = new SourceRegistry();
51 var mockSource = new MockSource();
52 sources.register(mockSource);
53
54 group('LockFile', () {
55 group('parse()', () {
56 test('returns an empty lockfile if the contents are empty', () {
57 var lockFile = new LockFile.parse('', sources);
58 expect(lockFile.packages.length, equals(0));
59 });
60
61 test('returns an empty lockfile if the contents are whitespace', () {
62 var lockFile = new LockFile.parse(' \t\n ', sources);
63 expect(lockFile.packages.length, equals(0));
64 });
65
66 test('parses a series of package descriptions', () {
67 var lockFile = new LockFile.parse('''
68 packages:
69 bar:
70 version: 1.2.3
71 source: mock
72 description: bar desc
73 foo:
74 version: 2.3.4
75 source: mock
76 description: foo desc
77 ''', sources);
78
79 expect(lockFile.packages.length, equals(2));
80
81 var bar = lockFile.packages['bar'];
82 expect(bar.name, equals('bar'));
83 expect(bar.version, equals(new Version(1, 2, 3)));
84 expect(bar.source, equals(mockSource.name));
85 expect(bar.description, equals('bar desc'));
86
87 var foo = lockFile.packages['foo'];
88 expect(foo.name, equals('foo'));
89 expect(foo.version, equals(new Version(2, 3, 4)));
90 expect(foo.source, equals(mockSource.name));
91 expect(foo.description, equals('foo desc'));
92 });
93
94 test("allows an unknown source", () {
95 var lockFile = new LockFile.parse('''
96 packages:
97 foo:
98 source: bad
99 version: 1.2.3
100 description: foo desc
101 ''', sources);
102 var foo = lockFile.packages['foo'];
103 expect(foo.source, equals('bad'));
104 });
105
106 test("allows an empty dependency map", () {
107 var lockFile = new LockFile.parse('''
108 packages:
109 ''', sources);
110 expect(lockFile.packages, isEmpty);
111 });
112
113 test("throws if the top level is not a map", () {
114 expect(() {
115 new LockFile.parse('''
116 not a map
117 ''', sources);
118 }, throwsFormatException);
119 });
120
121 test("throws if the contents of 'packages' is not a map", () {
122 expect(() {
123 new LockFile.parse('''
124 packages: not a map
125 ''', sources);
126 }, throwsFormatException);
127 });
128
129 test("throws if the version is missing", () {
130 expect(() {
131 new LockFile.parse('''
132 packages:
133 foo:
134 source: mock
135 description: foo desc
136 ''', sources);
137 }, throwsFormatException);
138 });
139
140 test("throws if the version is invalid", () {
141 expect(() {
142 new LockFile.parse('''
143 packages:
144 foo:
145 version: vorpal
146 source: mock
147 description: foo desc
148 ''', sources);
149 }, throwsFormatException);
150 });
151
152 test("throws if the source is missing", () {
153 expect(() {
154 new LockFile.parse('''
155 packages:
156 foo:
157 version: 1.2.3
158 description: foo desc
159 ''', sources);
160 }, throwsFormatException);
161 });
162
163 test("throws if the description is missing", () {
164 expect(() {
165 new LockFile.parse('''
166 packages:
167 foo:
168 version: 1.2.3
169 source: mock
170 ''', sources);
171 }, throwsFormatException);
172 });
173
174 test("throws if the description is invalid", () {
175 expect(() {
176 new LockFile.parse('''
177 packages:
178 foo:
179 version: 1.2.3
180 source: mock
181 description: foo desc is bad
182 ''', sources);
183 }, throwsFormatException);
184 });
185
186 test("ignores extra stuff in file", () {
187 var lockFile = new LockFile.parse('''
188 extra:
189 some: stuff
190 packages:
191 foo:
192 bonus: not used
193 version: 1.2.3
194 source: mock
195 description: foo desc
196 ''', sources);
197 });
198 });
199
200 group('serialize()', () {
201 var lockfile;
202 setUp(() {
203 lockfile = new LockFile.empty();
204 });
205
206 test('dumps the lockfile to YAML', () {
207 lockfile.packages['foo'] =
208 new PackageId('foo', mockSource.name, new Version.parse('1.2.3'), 'f oo desc');
209 lockfile.packages['bar'] =
210 new PackageId('bar', mockSource.name, new Version.parse('3.2.1'), 'b ar desc');
211
212 expect(loadYaml(lockfile.serialize(null, sources)), equals({
213 'packages': {
214 'foo': {
215 'version': '1.2.3',
216 'source': 'mock',
217 'description': 'foo desc'
218 },
219 'bar': {
220 'version': '3.2.1',
221 'source': 'mock',
222 'description': 'bar desc'
223 }
224 }
225 }));
226 });
227 });
228 });
229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698