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

Side by Side Diff: utils/tests/pub/descriptor.dart

Issue 12437022: Use scheduled_test for Pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-upload Created 7 years, 9 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
« no previous file with comments | « utils/pub/utils.dart ('k') | utils/tests/pub/descriptor/git.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Pub-specific scheduled_test descriptors.
6 library descriptor;
7
8 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2;
9 import '../../../pkg/scheduled_test/lib/scheduled_server.dart';
10 import '../../../pkg/scheduled_test/lib/scheduled_test.dart';
11 import '../../../pkg/scheduled_test/lib/descriptor.dart';
12
13 import '../../pub/utils.dart';
14 import 'descriptor/git.dart';
15 import 'descriptor/tar.dart';
16 import 'test_pub.dart';
17
18 export '../../../pkg/scheduled_test/lib/descriptor.dart';
19 export 'descriptor/git.dart';
20 export 'descriptor/tar.dart';
21
22 /// Creates a new [GitRepoDescriptor] with [name] and [contents].
23 GitRepoDescriptor git(String name, [Iterable<Descriptor> contents]) =>
24 new GitRepoDescriptor(name, contents == null ? <Descriptor>[] : contents);
25
26 /// Creates a new [TarRepoDescriptor] with [name] and [contents].
27 TarFileDescriptor tar(String name, [Iterable<Descriptor> contents]) =>
28 new TarFileDescriptor(name, contents == null ? <Descriptor>[] : contents);
29
30 /// Describes a package that passes all validation.
31 Descriptor get validPackage => dir(appPath, [
32 libPubspec("test_pkg", "1.0.0"),
33 file("LICENSE", "Eh, do what you want."),
34 dir("lib", [
35 file("test_pkg.dart", "int i = 1;")
36 ])
37 ]);
38
39 /// Describes a file named `pubspec.yaml` with the given YAML-serialized
40 /// [contents], which should be a serializable object.
41 ///
42 /// [contents] may contain [Future]s that resolve to serializable objects,
43 /// which may in turn contain [Future]s recursively.
44 Descriptor pubspec(Map contents) {
45 return async(awaitObject(contents).then((resolvedContents) =>
46 file("pubspec.yaml", yaml(resolvedContents))));
47 }
48
49 /// Describes a file named `pubspec.yaml` for an application package with the
50 /// given [dependencies].
51 Descriptor appPubspec(List dependencies) {
52 return pubspec({
53 "name": "myapp",
54 "dependencies": dependencyListToMap(dependencies)
55 });
56 }
57
58 /// Describes a file named `pubspec.yaml` for a library package with the given
59 /// [name], [version], and [deps]. If "sdk" is given, then it adds an SDK
60 /// constraint on that version.
61 Descriptor libPubspec(String name, String version, {List deps, String sdk}) {
62 var map = packageMap(name, version, deps);
63
64 if (sdk != null) {
65 map["environment"] = {
66 "sdk": sdk
67 };
68 }
69
70 return pubspec(map);
71 }
72
73 /// Describes a directory named `lib` containing a single dart file named
74 /// `<name>.dart` that contains a line of Dart code.
75 Descriptor libDir(String name, [String code]) {
76 // Default to printing the name if no other code was given.
77 if (code == null) {
78 code = name;
79 }
80
81 return dir("lib", [
82 file("$name.dart", 'main() => "$code";')
83 ]);
84 }
85
86 /// Describes a directory for a package installed from the mock package server.
87 /// This directory is of the form found in the global package cache.
88 Descriptor packageCacheDir(String name, String version) {
89 return dir("$name-$version", [
90 libDir(name, '$name $version')
91 ]);
92 }
93
94 /// Describes a directory for a Git package. This directory is of the form
95 /// found in the revision cache of the global package cache.
96 Descriptor gitPackageRevisionCacheDir(String name, [int modifier]) {
97 var value = name;
98 if (modifier != null) value = "$name $modifier";
99 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"),
100 (dirName) => dir(dirName, [libDir(name, value)]));
101 }
102
103 /// Describes a directory for a Git package. This directory is of the form
104 /// found in the repo cache of the global package cache.
105 Descriptor gitPackageRepoCacheDir(String name) {
106 return pattern(new RegExp("$name${r'-[a-f0-9]+'}"),
107 (dirName) => dir(dirName, [
108 dir('hooks'),
109 dir('info'),
110 dir('objects'),
111 dir('refs')
112 ]));
113 }
114
115 /// Describes the `packages/` directory containing all the given [packages],
116 /// which should be name/version pairs. The packages will be validated against
117 /// the format produced by the mock package server.
118 ///
119 /// A package with a null version should not be installed.
120 Descriptor packagesDir(Map<String, String> packages) {
121 var contents = <Descriptor>[];
122 packages.forEach((name, version) {
123 if (version == null) {
124 contents.add(nothing(name));
125 } else {
126 contents.add(dir(name, [
127 file("$name.dart", 'main() => "$name $version";')
128 ]));
129 }
130 });
131 return dir(packagesPath, contents);
132 }
133
134 /// Describes the global package cache directory containing all the given
135 /// [packages], which should be name/version pairs. The packages will be
136 /// validated against the format produced by the mock package server.
137 ///
138 /// A package's value may also be a list of versions, in which case all
139 /// versions are expected to be installed.
140 Descriptor cacheDir(Map packages) {
141 var contents = <Descriptor>[];
142 packages.forEach((name, versions) {
143 if (versions is! List) versions = [versions];
144 for (var version in versions) {
145 contents.add(packageCacheDir(name, version));
146 }
147 });
148 return dir(cachePath, [
149 dir('hosted', [
150 async(port.then((p) => dir('localhost%58$p', contents)))
151 ])
152 ]);
153 }
154
155 /// Describes the file in the system cache that contains the client's OAuth2
156 /// credentials. The URL "/token" on [server] will be used as the token
157 /// endpoint for refreshing the access token.
158 Descriptor credentialsFile(
159 ScheduledServer server,
160 String accessToken,
161 {String refreshToken,
162 DateTime expiration}) {
163 return async(server.url.then((url) {
164 return dir(cachePath, [
165 file('credentials.json', new oauth2.Credentials(
166 accessToken,
167 refreshToken,
168 url.resolve('/token'),
169 ['https://www.googleapis.com/auth/userinfo.email'],
170 expiration).toJson())
171 ]);
172 }));
173 }
174
175 /// Describes the application directory, containing only a pubspec specifying
176 /// the given [dependencies].
177 DirectoryDescriptor appDir(List dependencies) =>
178 dir(appPath, [appPubspec(dependencies)]);
OLDNEW
« no previous file with comments | « utils/pub/utils.dart ('k') | utils/tests/pub/descriptor/git.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698