Skip to content
Snippets Groups Projects
Commit a1a24706 authored by Natalie Weizenbaum's avatar Natalie Weizenbaum
Browse files

Refactor version_solver_test.

This brings these tests in line with others, making them integration
tests that invoke a pub process rather than testing the version solver
APIs directly. This will make it easier to add Flutter support in the
future (see #1431 and #1432).

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//2172523002 .
parent 3a972799
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ final String rootDirectory = (() {
///
/// This can be set so that the version solver tests can artificially select
/// different SDK versions.
Version version = _getVersion();
final version = _getVersion();
/// Determine the SDK's version number.
Version _getVersion() {
......
......@@ -189,6 +189,7 @@ class BacktrackingSolver {
// Gather some solving metrics.
var buffer = new StringBuffer();
buffer.writeln('${runtimeType} took ${stopwatch.elapsed} seconds.');
buffer.writeln('- Tried $_attemptedSolutions solutions');
buffer.writeln(cache.describeResults());
log.solver(buffer);
}
......
......@@ -74,6 +74,9 @@ class PackageServer {
/// A future that will complete to the port used for the server.
Future<int> get port => _inner.port;
/// A future that will complete to the URL for the server.
Future<String> get url async => 'http://localhost:${await port}';
/// Creates an HTTP server that replicates the structure of pub.dartlang.org.
///
/// Calls [callback] with a [PackageServerBuilder] that's used to specify
......
......@@ -219,9 +219,10 @@ void scheduleSymlink(String target, String symlink) {
/// Schedules a call to the Pub command-line utility.
///
/// Runs Pub with [args] and validates that its results match [output] (or
/// [outputJson]), [error], and [exitCode].
/// [outputJson]), [error], [silent] (for logs that are silent by default), and
/// [exitCode].
///
/// [output] and [error] can be [String]s, [RegExp]s, or [Matcher]s.
/// [output], [error], and [silent] can be [String]s, [RegExp]s, or [Matcher]s.
///
/// If [outputJson] is given, validates that pub outputs stringified JSON
/// matching that object, which can be a literal JSON object or any other
......@@ -229,7 +230,7 @@ void scheduleSymlink(String target, String symlink) {
///
/// If [environment] is given, any keys in it will override the environment
/// variables passed to the spawned process.
void schedulePub({List args, output, error, outputJson,
void schedulePub({List args, output, error, outputJson, silent,
int exitCode: exit_codes.SUCCESS, Map<String, String> environment}) {
// Cannot pass both output and outputJson.
assert(output == null || outputJson == null);
......@@ -237,30 +238,24 @@ void schedulePub({List args, output, error, outputJson,
var pub = startPub(args: args, environment: environment);
pub.shouldExit(exitCode);
var failures = [];
var stderr;
expect(Future.wait([
pub.stdoutStream().toList(),
pub.stderrStream().toList()
]).then((results) {
var stdout = results[0].join("\n");
stderr = results[1].join("\n");
expect(() async {
var actualOutput = (await pub.stdoutStream().toList()).join("\n");
var actualError = (await pub.stderrStream().toList()).join("\n");
var actualSilent = (await pub.silentStream().toList()).join("\n");
var failures = [];
if (outputJson == null) {
_validateOutput(failures, 'stdout', output, stdout);
return null;
_validateOutput(failures, 'stdout', output, actualOutput);
} else {
_validateOutputJson(
failures, 'stdout', await awaitObject(outputJson), actualOutput);
}
// Allow the expected JSON to contain futures.
return awaitObject(outputJson).then((resolved) {
_validateOutputJson(failures, 'stdout', resolved, stdout);
});
}).then((_) {
_validateOutput(failures, 'stderr', error, stderr);
_validateOutput(failures, 'stderr', error, actualError);
_validateOutput(failures, 'silent', silent, actualSilent);
if (!failures.isEmpty) throw new TestFailure(failures.join('\n'));
}), completes);
}(), completes);
}
/// Like [startPub], but runs `pub lish` in particular with [server] used both
......@@ -373,6 +368,7 @@ class PubProcess extends ScheduledProcess {
Stream<Pair<log.Level, String>> _log;
Stream<String> _stdout;
Stream<String> _stderr;
Stream<String> _silent;
PubProcess.start(executable, arguments,
{workingDirectory, environment, String description,
......@@ -446,6 +442,22 @@ class PubProcess extends ScheduledProcess {
_stderr = pair.first;
return pair.last;
}
/// A stream of log messages that are silent by default.
Stream<String> silentStream() {
if (_silent == null) {
_silent = _logStream().expand((entry) {
if (entry.first == log.Level.MESSAGE) return [];
if (entry.first == log.Level.ERROR) return [];
if (entry.first == log.Level.WARNING) return [];
return [entry.last];
});
}
var pair = tee(_silent);
_silent = pair.first;
return pair.last;
}
}
/// Fails the current test if Git is not installed.
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment