Skip to content

Commit 1f460d9

Browse files
authored
Ensure pub/dart invoked by tests are the same as the top-level SDK (#24)
Closes #23
1 parent 9c269cd commit 1f460d9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

webdev/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: webdev
2-
version: 0.1.2
2+
version: 0.1.3-dev
33
author: Dart Team <misc@dartlang.org>
44
homepage: https://github.com/dart-lang/webdev
55
description: >-

webdev/test/integration_test.dart

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,28 @@ import 'package:test_process/test_process.dart';
1212

1313
final _webdevBin = p.absolute('bin/webdev.dart');
1414

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+
1534
void main() {
1635
test('README contains help output', () async {
17-
var process = await TestProcess.start('dart', [_webdevBin]);
36+
var process = await _runWebDev([]);
1837
var output = (await process.stdoutStream().join('\n')).trim();
1938
await process.shouldExit(0);
2039

@@ -24,7 +43,7 @@ void main() {
2443
});
2544

2645
test('non-existant commands create errors', () async {
27-
var process = await TestProcess.start('dart', [_webdevBin, 'monkey']);
46+
var process = await _runWebDev(['monkey']);
2847

2948
await expectLater(
3049
process.stdout, emits('Could not find a command named "monkey".'));
@@ -35,7 +54,7 @@ void main() {
3554
test('should fail in a package without a build_runner dependency', () async {
3655
// Running on the `webdev` package directory – which has no dependency on
3756
// build runner.
38-
var process = await TestProcess.start('dart', [_webdevBin, 'build']);
57+
var process = await _runWebDev(['build']);
3958
var output = (await process.stdoutStream().join('\n')).trim();
4059

4160
expect(output, contains(r'''Could not run in the current directory.
@@ -65,8 +84,7 @@ packages:
6584
await d.file('.packages', '''
6685
''').create();
6786

68-
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
69-
workingDirectory: d.sandbox);
87+
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
7088

7189
await expectLater(
7290
process.stdout, emits('Could not run in the current directory.'));
@@ -80,8 +98,7 @@ packages:
8098
});
8199

82100
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);
85102

86103
var output = await process.stdoutStream().join('\n');
87104

@@ -95,8 +112,7 @@ packages:
95112
name: sample
96113
''').create();
97114

98-
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
99-
workingDirectory: d.sandbox);
115+
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
100116

101117
var output = await process.stdoutStream().join('\n');
102118

@@ -123,8 +139,7 @@ packages:
123139
version: "0.8.0"
124140
''').create();
125141

126-
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
127-
workingDirectory: d.sandbox);
142+
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
128143

129144
var output = await process.stdoutStream().join('\n');
130145

@@ -153,8 +168,7 @@ packages:
153168

154169
await d.file('.packages', '').create();
155170

156-
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
157-
workingDirectory: d.sandbox);
171+
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
158172

159173
var output = await process.stdoutStream().join('\n');
160174

@@ -189,8 +203,7 @@ dependencies:
189203
args: ^1.0.0
190204
''').create();
191205

192-
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
193-
workingDirectory: d.sandbox);
206+
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
194207

195208
var output = await process.stdoutStream().join('\n');
196209

@@ -205,16 +218,15 @@ dependencies:
205218

206219
test('should succeed with valid configuration', () async {
207220
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'],
209222
workingDirectory: exampleDirectory, environment: _getPubEnvironment());
210223

211224
await process.shouldExit(0);
212225

213226
await d.file('.packages', isNotEmpty).validate(exampleDirectory);
214227
await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory);
215228

216-
process = await TestProcess.start(
217-
'dart', [_webdevBin, 'build', '-o', d.sandbox],
229+
process = await _runWebDev(['build', '-o', d.sandbox],
218230
workingDirectory: exampleDirectory);
219231

220232
var output = await process.stdoutStream().join('\n');

0 commit comments

Comments
 (0)