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

Side by Side Diff: test/run/resource_test.dart

Issue 1277773002: Support resources in "pub run" and "pub global run". (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « test/global/run/resource_test.dart ('k') | no next file » | 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) 2014, 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 import 'dart:async';
6
7 import 'package:path/path.dart' as p;
8 import 'package:scheduled_test/scheduled_test.dart';
9
10 import '../descriptor.dart' as d;
11 import '../test_pub.dart';
12
13 const TRANSFORMER = """
14 import 'dart:async';
15
16 import 'package:barback/barback.dart';
17
18 class MyTransformer extends Transformer {
19 MyTransformer.asPlugin();
20
21 String get allowedExtensions => '.in';
22
23 Future apply(Transform transform) async {
24 transform.addOutput(new Asset.fromString(
25 transform.primaryInput.id.changeExtension('.txt'),
26 await transform.primaryInput.readAsString()));
27 }
28 }
29 """;
30
31 main() {
32 integration('the spawned application can load its own resource', () {
33 d.dir(appPath, [
34 d.appPubspec(),
35 d.dir("lib", [
36 d.file("resource.txt", "hello!")
37 ]),
38 d.dir("bin", [
39 d.file("script.dart", """
40 main() async {
41 var resource = new Resource("package:myapp/resource.txt");
42
43 // TODO(nweiz): Enable this when sdk#23990 is fixed.
44 // print(resource.uri);
45
46 print(await resource.readAsString());
47 }
48 """)
49 ])
50 ]).create();
51
52 var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
53
54 // TODO(nweiz): Enable this when sdk#23990 is fixed.
55 // pub.stdout.expect(p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")));
56
57 pub.stdout.expect("hello!");
58 pub.shouldExit(0);
59 });
60
61 integration("the spawned application can load a dependency's resource", () {
62 d.dir("foo", [
63 d.libPubspec("foo", "1.0.0"),
64 d.dir("lib", [
65 d.file("resource.txt", "hello!")
66 ])
67 ]).create();
68
69 d.dir(appPath, [
70 d.appPubspec({
71 "foo": {"path": "../foo"}
72 }),
73 d.dir("bin", [
74 d.file("script.dart", """
75 main() async {
76 var resource = new Resource("package:foo/resource.txt");
77
78 // TODO(nweiz): Enable this when sdk#23990 is fixed.
79 // print(resource.uri);
80
81 print(await resource.readAsString());
82 }
83 """)
84 ])
85 ]).create();
86
87 var pub = pubRun(args: ["bin/script"], shouldGetFirst: true);
88
89 // TODO(nweiz): Enable this when sdk#23990 is fixed.
90 // pub.stdout.expect(p.toUri(p.join(sandboxDir, "foo/lib/resource.txt")));
91
92 pub.stdout.expect("hello!");
93 pub.shouldExit(0);
94 });
95
96 withBarbackVersions("any", () {
97 integration('the spawned application can load a transformed resource', () {
98 d.dir(appPath, [
99 d.pubspec({
100 "name": "myapp",
101 "transformers": ["myapp/src/transformer"]
102 }),
103 d.dir("lib", [
104 d.file("resource.in", "hello!"),
105 d.dir("src", [
106 d.file("transformer.dart", TRANSFORMER)
107 ])
108 ]),
109 d.dir("bin", [
110 d.file("script.dart", """
111 main() async {
112 var resource = new Resource("package:myapp/resource.txt");
113
114 // TODO(nweiz): Enable this when sdk#23990 is fixed.
115 // print(resource.uri);
116
117 print(await resource.readAsString());
118 }
119 """)
120 ])
121 ]).create();
122
123 createLockFile('myapp', pkg: ['barback']);
124
125 var pub = pubRun(args: ["bin/script"]);
126
127 // TODO(nweiz): Enable this when sdk#23990 is fixed.
128 // pub.stdout.expect(p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")) );
129
130 pub.stdout.expect("hello!");
131 pub.shouldExit(0);
132 });
133 });
134
135 integration('a snapshotted application can load a resource', () {
136 servePackages((builder) {
137 builder.serve("foo", "1.0.0", contents: [
138 d.dir("lib", [
139 d.file("resource.txt", "hello!")
140 ]),
141 d.dir("bin", [
142 d.file("script.dart", """
143 main() async {
144 var resource = new Resource("package:foo/resource.txt");
145
146 // TODO(nweiz): Enable this when sdk#23990 is fixed.
147 // print(resource.uri);
148
149 print(await resource.readAsString());
150 }
151 """)
152 ])
153 ]);
154 });
155
156 d.dir(appPath, [
157 d.appPubspec({
158 "foo": "any"
159 })
160 ]).create();
161
162 pubGet(output: contains("Precompiled foo:script."));
163
164 var pub = pubRun(args: ["foo:script"]);
165
166 // TODO(nweiz): Enable this when sdk#23990 is fixed.
167 // pub.stdout.expect(p.toUri(p.join(sandboxDir, "foo/lib/resource.txt")));
168
169 pub.stdout.expect("hello!");
170 pub.shouldExit(0);
171 });
172 }
OLDNEW
« no previous file with comments | « test/global/run/resource_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698