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

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

Issue 15347004: Gracefully handle pubspecs with dependencies using unknown sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for unknown sources in lockfiles. Created 7 years, 7 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
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 library lock_file_test; 5 library lock_file_test;
6 6
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 import 'package:yaml/yaml.dart'; 8 import 'package:yaml/yaml.dart';
9 9
10 import '../lib/src/lock_file.dart'; 10 import '../lib/src/lock_file.dart';
11 import '../lib/src/package.dart'; 11 import '../lib/src/package.dart';
12 import '../lib/src/source.dart'; 12 import '../lib/src/source.dart';
13 import '../lib/src/source_registry.dart'; 13 import '../lib/src/source_registry.dart';
14 import '../lib/src/utils.dart'; 14 import '../lib/src/utils.dart';
15 import '../lib/src/version.dart'; 15 import '../lib/src/version.dart';
16 import 'test_pub.dart';
16 17
17 class MockSource extends Source { 18 class MockSource extends Source {
18 final String name = 'mock'; 19 final String name = 'mock';
19 final bool shouldCache = false; 20 final bool shouldCache = false;
20 21
21 dynamic parseDescription(String filePath, String description, 22 dynamic parseDescription(String filePath, String description,
22 {bool fromLockFile: false}) { 23 {bool fromLockFile: false}) {
23 if (!description.endsWith(' desc')) throw new FormatException(); 24 if (!description.endsWith(' desc')) throw new FormatException();
24 return description; 25 return description;
25 } 26 }
26 27
27 String packageName(String description) { 28 String packageName(String description) {
28 // Strip off ' desc'. 29 // Strip off ' desc'.
29 return description.substring(0, description.length - 5); 30 return description.substring(0, description.length - 5);
30 } 31 }
31 } 32 }
32 33
33 main() { 34 main() {
35 initConfig();
36
34 var sources = new SourceRegistry(); 37 var sources = new SourceRegistry();
35 var mockSource = new MockSource(); 38 var mockSource = new MockSource();
36 sources.register(mockSource); 39 sources.register(mockSource);
37 40
38 group('LockFile', () { 41 group('LockFile', () {
39 group('parse()', () { 42 group('parse()', () {
40 test('returns an empty lockfile if the contents are empty', () { 43 test('returns an empty lockfile if the contents are empty', () {
41 var lockFile = new LockFile.parse('', sources); 44 var lockFile = new LockFile.parse('', sources);
42 expect(lockFile.packages.length, equals(0)); 45 expect(lockFile.packages.length, equals(0));
43 }); 46 });
(...skipping 14 matching lines...) Expand all
58 version: 2.3.4 61 version: 2.3.4
59 source: mock 62 source: mock
60 description: foo desc 63 description: foo desc
61 ''', sources); 64 ''', sources);
62 65
63 expect(lockFile.packages.length, equals(2)); 66 expect(lockFile.packages.length, equals(2));
64 67
65 var bar = lockFile.packages['bar']; 68 var bar = lockFile.packages['bar'];
66 expect(bar.name, equals('bar')); 69 expect(bar.name, equals('bar'));
67 expect(bar.version, equals(new Version(1, 2, 3))); 70 expect(bar.version, equals(new Version(1, 2, 3)));
68 expect(bar.source, equals(mockSource)); 71 expect(bar.source, equals(mockSource.name));
69 expect(bar.description, equals('bar desc')); 72 expect(bar.description, equals('bar desc'));
70 73
71 var foo = lockFile.packages['foo']; 74 var foo = lockFile.packages['foo'];
72 expect(foo.name, equals('foo')); 75 expect(foo.name, equals('foo'));
73 expect(foo.version, equals(new Version(2, 3, 4))); 76 expect(foo.version, equals(new Version(2, 3, 4)));
74 expect(foo.source, equals(mockSource)); 77 expect(foo.source, equals(mockSource.name));
75 expect(foo.description, equals('foo desc')); 78 expect(foo.description, equals('foo desc'));
76 }); 79 });
77 80
81 test("allows an unknown source", () {
82 var lockFile = new LockFile.parse('''
83 packages:
84 foo:
85 source: bad
86 version: 1.2.3
87 description: foo desc
88 ''', sources);
89 var foo = lockFile.packages['foo'];
90 expect(foo.source, equals('bad'));
91 });
92
78 test("throws if the version is missing", () { 93 test("throws if the version is missing", () {
79 expect(() { 94 expect(() {
80 new LockFile.parse(''' 95 new LockFile.parse('''
81 packages: 96 packages:
82 foo: 97 foo:
83 source: mock 98 source: mock
84 description: foo desc 99 description: foo desc
85 ''', sources); 100 ''', sources);
86 }, throwsFormatException); 101 }, throwsFormatException);
87 }); 102 });
(...skipping 12 matching lines...) Expand all
100 115
101 test("throws if the source is missing", () { 116 test("throws if the source is missing", () {
102 expect(() { 117 expect(() {
103 new LockFile.parse(''' 118 new LockFile.parse('''
104 packages: 119 packages:
105 foo: 120 foo:
106 version: 1.2.3 121 version: 1.2.3
107 description: foo desc 122 description: foo desc
108 ''', sources); 123 ''', sources);
109 }, throwsFormatException); 124 }, throwsFormatException);
110 });
111
112 test("throws if the source is unknown", () {
113 expect(() {
114 new LockFile.parse('''
115 packages:
116 foo:
117 version: 1.2.3
118 source: notreal
119 description: foo desc
120 ''', sources);
121 }, throwsFormatException);
122 }); 125 });
123 126
124 test("throws if the description is missing", () { 127 test("throws if the description is missing", () {
125 expect(() { 128 expect(() {
126 new LockFile.parse(''' 129 new LockFile.parse('''
127 packages: 130 packages:
128 foo: 131 foo:
129 version: 1.2.3 132 version: 1.2.3
130 source: mock 133 source: mock
131 ''', sources); 134 ''', sources);
(...skipping 27 matching lines...) Expand all
159 }); 162 });
160 163
161 group('serialize()', () { 164 group('serialize()', () {
162 var lockfile; 165 var lockfile;
163 setUp(() { 166 setUp(() {
164 lockfile = new LockFile.empty(); 167 lockfile = new LockFile.empty();
165 }); 168 });
166 169
167 test('dumps the lockfile to YAML', () { 170 test('dumps the lockfile to YAML', () {
168 lockfile.packages['foo'] = new PackageId( 171 lockfile.packages['foo'] = new PackageId(
169 'foo', mockSource, new Version.parse('1.2.3'), 'foo desc'); 172 'foo', mockSource.name, new Version.parse('1.2.3'), 'foo desc');
170 lockfile.packages['bar'] = new PackageId( 173 lockfile.packages['bar'] = new PackageId(
171 'bar', mockSource, new Version.parse('3.2.1'), 'bar desc'); 174 'bar', mockSource.name, new Version.parse('3.2.1'), 'bar desc');
172 175
173 expect(loadYaml(lockfile.serialize()), equals({ 176 expect(loadYaml(lockfile.serialize()), equals({
174 'packages': { 177 'packages': {
175 'foo': { 178 'foo': {
176 'version': '1.2.3', 179 'version': '1.2.3',
177 'source': 'mock', 180 'source': 'mock',
178 'description': 'foo desc' 181 'description': 'foo desc'
179 }, 182 },
180 'bar': { 183 'bar': {
181 'version': '3.2.1', 184 'version': '3.2.1',
182 'source': 'mock', 185 'source': 'mock',
183 'description': 'bar desc' 186 'description': 'bar desc'
184 } 187 }
185 } 188 }
186 })); 189 }));
187 }); 190 });
188 191
189 test('lockfile is alphabetized by package name', () { 192 test('lockfile is alphabetized by package name', () {
190 var testNames = ['baz', 'Qwe', 'Q', 'B', 'Bar', 'bar', 'foo']; 193 var testNames = ['baz', 'Qwe', 'Q', 'B', 'Bar', 'bar', 'foo'];
191 testNames.forEach((name) { 194 testNames.forEach((name) {
192 lockfile.packages[name] = new PackageId(name, mockSource, 195 lockfile.packages[name] = new PackageId(name, mockSource.name,
193 new Version.parse('5.5.5'), '$name desc'); 196 new Version.parse('5.5.5'), '$name desc');
194 }); 197 });
195 198
196 expect(lockfile.serialize(), 199 expect(lockfile.serialize(),
197 '# Generated by pub\n' 200 '# Generated by pub\n'
198 '# See http://pub.dartlang.org/doc/glossary.html#lockfile\n' 201 '# See http://pub.dartlang.org/doc/glossary.html#lockfile\n'
199 '\n' 202 '\n'
200 '{"packages":{' 203 '{"packages":{'
201 '"B":{"version":"5.5.5","source":"mock","description":"B desc"},' 204 '"B":{"version":"5.5.5","source":"mock","description":"B desc"},'
202 '"Bar":{"version":"5.5.5","source":"mock","description":"Bar desc"},' 205 '"Bar":{"version":"5.5.5","source":"mock","description":"Bar desc"},'
203 '"Q":{"version":"5.5.5","source":"mock","description":"Q desc"},' 206 '"Q":{"version":"5.5.5","source":"mock","description":"Q desc"},'
204 '"Qwe":{"version":"5.5.5","source":"mock","description":"Qwe desc"},' 207 '"Qwe":{"version":"5.5.5","source":"mock","description":"Qwe desc"},'
205 '"bar":{"version":"5.5.5","source":"mock","description":"bar desc"},' 208 '"bar":{"version":"5.5.5","source":"mock","description":"bar desc"},'
206 '"baz":{"version":"5.5.5","source":"mock","description":"baz desc"},' 209 '"baz":{"version":"5.5.5","source":"mock","description":"baz desc"},'
207 '"foo":{"version":"5.5.5","source":"mock","description":"foo desc"}}}' 210 '"foo":{"version":"5.5.5","source":"mock","description":"foo desc"}}}'
208 '\n' 211 '\n'
209 ); 212 );
210 }); 213 });
211 }); 214 });
212 }); 215 });
213 } 216 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/install/unknown_source_test.dart ('k') | sdk/lib/_internal/pub/test/pub_cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698