@@ -12,9 +12,28 @@ import 'package:test_process/test_process.dart';
12
12
13
13
final _webdevBin = p.absolute ('bin/webdev.dart' );
14
14
15
+ /// The path to the root directory of the SDK.
16
+ final String _sdkDir = (() {
17
+ // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is
18
+ // "/path/to/sdk".
19
+ var aboveExecutable = p.dirname (p.dirname (Platform .resolvedExecutable));
20
+ assert (FileSystemEntity .isFileSync (p.join (aboveExecutable, 'version' )));
21
+ return aboveExecutable;
22
+ })();
23
+
24
+ final String _dartPath = p.join (_sdkDir, 'bin' , 'dart' );
25
+ final String _pubPath = p.join (_sdkDir, 'bin' , 'pub' );
26
+
27
+ Future <TestProcess > _runWebDev (List <String > args, {String workingDirectory}) {
28
+ var fullArgs = [_webdevBin]..addAll (args);
29
+
30
+ return TestProcess .start (_dartPath, fullArgs,
31
+ workingDirectory: workingDirectory);
32
+ }
33
+
15
34
void main () {
16
35
test ('README contains help output' , () async {
17
- var process = await TestProcess . start ( 'dart' , [_webdevBin ]);
36
+ var process = await _runWebDev ([ ]);
18
37
var output = (await process.stdoutStream ().join ('\n ' )).trim ();
19
38
await process.shouldExit (0 );
20
39
@@ -24,7 +43,7 @@ void main() {
24
43
});
25
44
26
45
test ('non-existant commands create errors' , () async {
27
- var process = await TestProcess . start ( 'dart' , [_webdevBin, 'monkey' ]);
46
+ var process = await _runWebDev ([ 'monkey' ]);
28
47
29
48
await expectLater (
30
49
process.stdout, emits ('Could not find a command named "monkey".' ));
@@ -35,7 +54,7 @@ void main() {
35
54
test ('should fail in a package without a build_runner dependency' , () async {
36
55
// Running on the `webdev` package directory – which has no dependency on
37
56
// build runner.
38
- var process = await TestProcess . start ( 'dart' , [_webdevBin, 'build' ]);
57
+ var process = await _runWebDev ([ 'build' ]);
39
58
var output = (await process.stdoutStream ().join ('\n ' )).trim ();
40
59
41
60
expect (output, contains (r'''Could not run in the current directory.
@@ -65,8 +84,7 @@ packages:
65
84
await d.file ('.packages' , '''
66
85
''' ).create ();
67
86
68
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
69
- workingDirectory: d.sandbox);
87
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
70
88
71
89
await expectLater (
72
90
process.stdout, emits ('Could not run in the current directory.' ));
@@ -80,8 +98,7 @@ packages:
80
98
});
81
99
82
100
test ('no pubspec.yaml' , () async {
83
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
84
- workingDirectory: d.sandbox);
101
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
85
102
86
103
var output = await process.stdoutStream ().join ('\n ' );
87
104
@@ -95,8 +112,7 @@ packages:
95
112
name: sample
96
113
''' ).create ();
97
114
98
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
99
- workingDirectory: d.sandbox);
115
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
100
116
101
117
var output = await process.stdoutStream ().join ('\n ' );
102
118
@@ -123,8 +139,7 @@ packages:
123
139
version: "0.8.0"
124
140
''' ).create ();
125
141
126
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
127
- workingDirectory: d.sandbox);
142
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
128
143
129
144
var output = await process.stdoutStream ().join ('\n ' );
130
145
@@ -153,8 +168,7 @@ packages:
153
168
154
169
await d.file ('.packages' , '' ).create ();
155
170
156
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
157
- workingDirectory: d.sandbox);
171
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
158
172
159
173
var output = await process.stdoutStream ().join ('\n ' );
160
174
@@ -189,8 +203,7 @@ dependencies:
189
203
args: ^1.0.0
190
204
''' ).create ();
191
205
192
- var process = await TestProcess .start ('dart' , [_webdevBin, 'build' ],
193
- workingDirectory: d.sandbox);
206
+ var process = await _runWebDev (['build' ], workingDirectory: d.sandbox);
194
207
195
208
var output = await process.stdoutStream ().join ('\n ' );
196
209
@@ -205,16 +218,15 @@ dependencies:
205
218
206
219
test ('should succeed with valid configuration' , () async {
207
220
var exampleDirectory = p.absolute (p.join (p.current, '..' , 'example' ));
208
- var process = await TestProcess .start ('pub' , ['get' ],
221
+ var process = await TestProcess .start (_pubPath , ['get' ],
209
222
workingDirectory: exampleDirectory, environment: _getPubEnvironment ());
210
223
211
224
await process.shouldExit (0 );
212
225
213
226
await d.file ('.packages' , isNotEmpty).validate (exampleDirectory);
214
227
await d.file ('pubspec.lock' , isNotEmpty).validate (exampleDirectory);
215
228
216
- process = await TestProcess .start (
217
- 'dart' , [_webdevBin, 'build' , '-o' , d.sandbox],
229
+ process = await _runWebDev (['build' , '-o' , d.sandbox],
218
230
workingDirectory: exampleDirectory);
219
231
220
232
var output = await process.stdoutStream ().join ('\n ' );
0 commit comments