Skip to content

Commit

Permalink
Ensure pub/dart invoked by tests are the same as the top-level SDK (#24)
Browse files Browse the repository at this point in the history
Closes #23
  • Loading branch information
kevmoo authored Mar 28, 2018
1 parent 9c269cd commit 1f460d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdev
version: 0.1.2
version: 0.1.3-dev
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
description: >-
Expand Down
48 changes: 30 additions & 18 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,28 @@ import 'package:test_process/test_process.dart';

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

/// The path to the root directory of the SDK.
final String _sdkDir = (() {
// The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is
// "/path/to/sdk".
var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable));
assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version')));
return aboveExecutable;
})();

final String _dartPath = p.join(_sdkDir, 'bin', 'dart');
final String _pubPath = p.join(_sdkDir, 'bin', 'pub');

Future<TestProcess> _runWebDev(List<String> args, {String workingDirectory}) {
var fullArgs = [_webdevBin]..addAll(args);

return TestProcess.start(_dartPath, fullArgs,
workingDirectory: workingDirectory);
}

void main() {
test('README contains help output', () async {
var process = await TestProcess.start('dart', [_webdevBin]);
var process = await _runWebDev([]);
var output = (await process.stdoutStream().join('\n')).trim();
await process.shouldExit(0);

Expand All @@ -24,7 +43,7 @@ void main() {
});

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

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

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

var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

test('no pubspec.yaml', () async {
var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

Expand All @@ -95,8 +112,7 @@ packages:
name: sample
''').create();

var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

Expand All @@ -123,8 +139,7 @@ packages:
version: "0.8.0"
''').create();

var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

Expand Down Expand Up @@ -153,8 +168,7 @@ packages:

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

var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

Expand Down Expand Up @@ -189,8 +203,7 @@ dependencies:
args: ^1.0.0
''').create();

var process = await TestProcess.start('dart', [_webdevBin, 'build'],
workingDirectory: d.sandbox);
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

Expand All @@ -205,16 +218,15 @@ dependencies:

test('should succeed with valid configuration', () async {
var exampleDirectory = p.absolute(p.join(p.current, '..', 'example'));
var process = await TestProcess.start('pub', ['get'],
var process = await TestProcess.start(_pubPath, ['get'],
workingDirectory: exampleDirectory, environment: _getPubEnvironment());

await process.shouldExit(0);

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

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

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

0 comments on commit 1f460d9

Please sign in to comment.