Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure pub/dart invoked by tests are the same as the top-level SDK #24

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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