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

Side by Side Diff: test/pubspec_test.dart

Issue 1215833002: Use the new test runner. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 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
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 pubspec_test; 5 library pubspec_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:pub/src/package.dart'; 9 import 'package:pub/src/package.dart';
10 import 'package:pub/src/pubspec.dart'; 10 import 'package:pub/src/pubspec.dart';
11 import 'package:pub/src/source.dart'; 11 import 'package:pub/src/source.dart';
12 import 'package:pub/src/source/path.dart'; 12 import 'package:pub/src/source/path.dart';
13 import 'package:pub/src/source_registry.dart'; 13 import 'package:pub/src/source_registry.dart';
14 import 'package:pub_semver/pub_semver.dart'; 14 import 'package:pub_semver/pub_semver.dart';
15 import 'package:unittest/unittest.dart'; 15 import 'package:test/test.dart';
16 16
17 import 'test_pub.dart'; 17 import 'test_pub.dart';
18 18
19 class MockSource extends Source { 19 class MockSource extends Source {
20 final String name = "mock"; 20 final String name = "mock";
21 21
22 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( 22 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError(
23 "Cannot describe mock packages."); 23 "Cannot describe mock packages.");
24 24
25 Future get(PackageId id, String symlink) => throw new UnsupportedError( 25 Future get(PackageId id, String symlink) => throw new UnsupportedError(
26 "Cannot get a mock package."); 26 "Cannot get a mock package.");
27 27
28 Future<String> getDirectory(PackageId id) => throw new UnsupportedError( 28 Future<String> getDirectory(PackageId id) => throw new UnsupportedError(
29 "Cannot get the directory for mock packages."); 29 "Cannot get the directory for mock packages.");
30 30
31 dynamic parseDescription(String filePath, description, 31 dynamic parseDescription(String filePath, description,
32 {bool fromLockFile: false}) { 32 {bool fromLockFile: false}) {
33 if (description != 'ok') throw new FormatException('Bad'); 33 if (description != 'ok') throw new FormatException('Bad');
34 return description; 34 return description;
35 } 35 }
36 36
37 bool descriptionsEqual(description1, description2) => 37 bool descriptionsEqual(description1, description2) =>
38 description1 == description2; 38 description1 == description2;
39 39
40 String packageName(description) => 'foo'; 40 String packageName(description) => 'foo';
41 } 41 }
42 42
43 main() { 43 main() {
44 initConfig();
45 group('parse()', () { 44 group('parse()', () {
46 var sources = new SourceRegistry(); 45 var sources = new SourceRegistry();
47 sources.register(new MockSource()); 46 sources.register(new MockSource());
48 sources.register(new PathSource()); 47 sources.register(new PathSource());
49 48
50 var throwsPubspecException = 49 var throwsPubspecException =
51 throwsA(new isInstanceOf<PubspecException>('PubspecException')); 50 throwsA(new isInstanceOf<PubspecException>());
Bob Nystrom 2015/06/26 23:04:10 Indent +4.
52 51
53 expectPubspecException(String contents, fn(Pubspec pubspec), 52 expectPubspecException(String contents, fn(Pubspec pubspec),
54 [String expectedContains]) { 53 [String expectedContains]) {
55 var expectation = throwsPubspecException; 54 var expectation = throwsPubspecException;
56 if (expectedContains != null) { 55 if (expectedContains != null) {
57 expectation = throwsA(allOf( 56 expectation = throwsA(allOf(
58 new isInstanceOf<PubspecException>('PubspecException'), 57 new isInstanceOf<PubspecException>(),
59 predicate((error) => error.message.contains(expectedContains)))); 58 predicate((error) => error.message.contains(expectedContains))));
60 } 59 }
61 60
62 var pubspec = new Pubspec.parse(contents, sources); 61 var pubspec = new Pubspec.parse(contents, sources);
63 expect(() => fn(pubspec), expectation); 62 expect(() => fn(pubspec), expectation);
64 } 63 }
65 64
66 test("doesn't eagerly throw an error for an invalid field", () { 65 test("doesn't eagerly throw an error for an invalid field", () {
67 // Shouldn't throw an error. 66 // Shouldn't throw an error.
68 new Pubspec.parse('version: not a semver', sources); 67 new Pubspec.parse('version: not a semver', sources);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 test("uses the key if the value is null", () { 522 test("uses the key if the value is null", () {
524 var pubspec = new Pubspec.parse(''' 523 var pubspec = new Pubspec.parse('''
525 executables: 524 executables:
526 command: 525 command:
527 ''', sources); 526 ''', sources);
528 expect(pubspec.executables['command'], equals('command')); 527 expect(pubspec.executables['command'], equals('command'));
529 }); 528 });
530 }); 529 });
531 }); 530 });
532 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698