2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'dart:async' ;
5
6
import 'dart:io' ;
6
7
7
8
import 'package:path/path.dart' as p;
@@ -45,6 +46,10 @@ A dependency on `build_runner` was not found.'''));
45
46
group ('should fail when `build_runner` is the wrong version' , () {
46
47
for (var version in ['0.7.13+1' , '0.9.0' ]) {
47
48
test (version, () async {
49
+ await d.file ('pubspec.yaml' , '''
50
+ name: sample
51
+ ''' ).create ();
52
+
48
53
await d.file ('pubspec.lock' , '''
49
54
# Copy-pasted from a valid run
50
55
packages:
@@ -57,6 +62,9 @@ packages:
57
62
version: "$version "
58
63
''' ).create ();
59
64
65
+ await d.file ('.packages' , '''
66
+ ''' ).create ();
67
+
60
68
var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
61
69
workingDirectory: d.sandbox);
62
70
@@ -71,7 +79,38 @@ packages:
71
79
}
72
80
});
73
81
74
- test ('should fail gracefully if there is no .packages file' , () async {
82
+ test ('no pubspec.yaml' , () async {
83
+ var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
84
+ workingDirectory: d.sandbox);
85
+
86
+ var output = await process.stdoutStream ().join ('\n ' );
87
+
88
+ expect (output, contains ('Could not run in the current directory.' ));
89
+ expect (output, contains ('Could not find a file named "pubspec.yaml"' ));
90
+ await process.shouldExit (78 );
91
+ });
92
+
93
+ test ('pubspec.yaml, no pubspec.lock' , () async {
94
+ await d.file ('pubspec.yaml' , '''
95
+ name: sample
96
+ ''' ).create ();
97
+
98
+ var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
99
+ workingDirectory: d.sandbox);
100
+
101
+ var output = await process.stdoutStream ().join ('\n ' );
102
+
103
+ expect (output, contains ('Could not run in the current directory.' ));
104
+ expect (output,
105
+ contains ('No pubspec.lock file found, please run "pub get" first.' ));
106
+ await process.shouldExit (78 );
107
+ });
108
+
109
+ test ('pubspec.yaml, pubspec.lock, no .packages' , () async {
110
+ await d.file ('pubspec.yaml' , '''
111
+ name: sample
112
+ ''' ).create ();
113
+
75
114
await d.file ('pubspec.lock' , '''
76
115
# Copy-pasted from a valid run
77
116
packages:
@@ -87,14 +126,19 @@ packages:
87
126
var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
88
127
workingDirectory: d.sandbox);
89
128
90
- await expectLater (
91
- process.stdout, emits ('Could not run in the current directory.' ));
92
- await expectLater (process.stdout,
93
- emits ('A `.packages` file does not exist in the target directory.' ));
129
+ var output = await process.stdoutStream ().join ('\n ' );
130
+
131
+ expect (output, contains ('Could not run in the current directory.' ));
132
+ expect (output,
133
+ contains ('No .packages file found, please run "pub get" first.' ));
94
134
await process.shouldExit (78 );
95
135
});
96
136
97
137
test ('should fail gracefully if there is an isolate error' , () async {
138
+ await d.file ('pubspec.yaml' , '''
139
+ name: sample
140
+ ''' ).create ();
141
+
98
142
await d.file ('pubspec.lock' , '''
99
143
# Copy-pasted from a valid run
100
144
packages:
@@ -112,11 +156,53 @@ packages:
112
156
var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
113
157
workingDirectory: d.sandbox);
114
158
115
- await expectLater (
116
- process.stdout, emits ('An unexpected exception has occurred.' ));
159
+ var output = await process.stdoutStream ().join ('\n ' );
160
+
161
+ expect (output, contains ('An unexpected exception has occurred.' ));
162
+
163
+ // The isolate will fail - broken .packages file
164
+ expect (output, contains ('Unable to spawn isolate' ));
117
165
await process.shouldExit (70 );
118
166
});
119
167
168
+ test ('should fail if there has been a dependency change' , () async {
169
+ await d.file ('pubspec.lock' , '''
170
+ # Copy-pasted from a valid run
171
+ packages:
172
+ build_runner:
173
+ dependency: "direct main"
174
+ description:
175
+ name: build_runner
176
+ url: "https://pub.dartlang.org"
177
+ source: hosted
178
+ version: "0.8.0"
179
+ ''' ).create ();
180
+
181
+ await d.file ('.packages' , '' ).create ();
182
+
183
+ // Ensure there is a noticeable delta in the creation times
184
+ await new Future .delayed (const Duration (milliseconds: 500 ));
185
+
186
+ await d.file ('pubspec.yaml' , '''
187
+ name: sample
188
+ dependencies:
189
+ args: ^1.0.0
190
+ ''' ).create ();
191
+
192
+ var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
193
+ workingDirectory: d.sandbox);
194
+
195
+ var output = await process.stdoutStream ().join ('\n ' );
196
+
197
+ expect (output, contains ('Could not run in the current directory.' ));
198
+ expect (
199
+ output,
200
+ contains (
201
+ 'The pubspec.yaml file has changed since the pubspec.lock file '
202
+ 'was generated, please run "pub get" again.' ));
203
+ await process.shouldExit (78 );
204
+ });
205
+
120
206
test ('should succeed with valid configuration' , () async {
121
207
var exampleDirectory = p.absolute (p.join (p.current, '..' , 'example' ));
122
208
var process = await TestProcess .start ('pub' , ['get' ],
0 commit comments