22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5+ import 'dart:async' ;
56import 'dart:io' ;
67
78import 'package:path/path.dart' as p;
@@ -45,6 +46,10 @@ A dependency on `build_runner` was not found.'''));
4546 group ('should fail when `build_runner` is the wrong version' , () {
4647 for (var version in ['0.7.13+1' , '0.9.0' ]) {
4748 test (version, () async {
49+ await d.file ('pubspec.yaml' , '''
50+ name: sample
51+ ''' ).create ();
52+
4853 await d.file ('pubspec.lock' , '''
4954# Copy-pasted from a valid run
5055packages:
@@ -57,6 +62,9 @@ packages:
5762 version: "$version "
5863''' ).create ();
5964
65+ await d.file ('.packages' , '''
66+ ''' ).create ();
67+
6068 var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
6169 workingDirectory: d.sandbox);
6270
@@ -71,7 +79,38 @@ packages:
7179 }
7280 });
7381
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+
75114 await d.file ('pubspec.lock' , '''
76115# Copy-pasted from a valid run
77116packages:
@@ -87,14 +126,19 @@ packages:
87126 var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
88127 workingDirectory: d.sandbox);
89128
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.' ));
94134 await process.shouldExit (78 );
95135 });
96136
97137 test ('should fail gracefully if there is an isolate error' , () async {
138+ await d.file ('pubspec.yaml' , '''
139+ name: sample
140+ ''' ).create ();
141+
98142 await d.file ('pubspec.lock' , '''
99143# Copy-pasted from a valid run
100144packages:
@@ -112,11 +156,53 @@ packages:
112156 var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
113157 workingDirectory: d.sandbox);
114158
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' ));
117165 await process.shouldExit (70 );
118166 });
119167
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+
120206 test ('should succeed with valid configuration' , () async {
121207 var exampleDirectory = p.absolute (p.join (p.current, '..' , 'example' ));
122208 var process = await TestProcess .start ('pub' , ['get' ],
0 commit comments