Skip to content
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 build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.10.2-wip
## 2.10.3-wip

- In "serve" and "watch" modes, retry failed compiles instead of exiting.

Expand Down
2 changes: 1 addition & 1 deletion build_runner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_runner
version: 2.10.2-wip
version: 2.10.3-wip
description: A build system for Dart code generation and modular compilation.
repository: https://github.com/dart-lang/build/tree/master/build_runner
resolution: workspace
Expand Down
91 changes: 56 additions & 35 deletions build_runner/test/common/build_runner_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,62 +239,83 @@ class BuildRunnerProcess {
/// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
/// process reports a build failure.
///
/// if [expectFailure] is set, then both [pattern] and [failOn] must be
/// encountered for the test to pass.
/// If the process exits instead, the test fails immediately.
///
/// Otherwise, waits until [pattern] appears, then completes.
///
/// Throws if the process appears to be stuck or done: if it outputs nothing
/// for 30s.
Future<void> expect(Pattern pattern, {Pattern? failOn}) async =>
expectAndGetLine(pattern, failOn: failOn);

/// Expects [pattern] to appear in the process's stdout or stderr.
///
/// If [failOn] is encountered instead, the test fails immediately. It
/// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
/// process reports a build failure.
///
/// If the process exits instead, the test fails immediately.
///
/// Otherwise, waits until [pattern] appears, returns the matching line.
///
/// Throws if the process appears to be stuck or done: if it outputs nothing
/// for 30s.
Future<String> expect(
Pattern pattern, {
Pattern? failOn,
bool expectFailure = false,
}) async {
Future<String> expectAndGetLine(Pattern pattern, {Pattern? failOn}) async {
printOnFailure(
'--- $_testLine expects `$pattern`'
'${failOn == null ? '' : ', failOn: `$failOn`'}'
'${expectFailure ? ', expectFailure: true' : ''}',
'${failOn == null ? '' : ', failOn: `$failOn`'}',
);
failOn ??= BuildLog.failurePattern;

final expectsMessage =
expectFailure
? '`$pattern` with failure matching (`$failOn`)'
: '`$pattern`';

var failureSeen = false;
var patternSeen = false;
while (true) {
String? line;
try {
line = await _outputs.next.timeout(const Duration(seconds: 30));
} on TimeoutException catch (_) {
throw fail('While expecting $expectsMessage, timed out after 30s.');
throw fail('While expecting `$pattern`, timed out after 30s.');
} catch (_) {
throw fail('While expecting $expectsMessage, process exited.');
throw fail('While expecting `$pattern`, process exited.');
}
printOnFailure(line);
if (line.contains(pattern)) return line;
if (line.contains(failOn)) {
failureSeen = true;
}
if (line.contains(pattern)) {
patternSeen = true;
fail('While expecting `$pattern`, got `$failOn`.');
}
}
}

if (expectFailure) {
if (patternSeen && failureSeen) {
return line;
}
} else {
if (failureSeen) {
fail('While expecting $expectsMessage, got `$failOn`.');
}
if (patternSeen) {
return line;
}
/// Expects [pattern] to appear in the process's stdout or stderr.
///
/// If [failOn] is encountered instead, the test fails immediately. It
/// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
/// process reports a build failure.
///
/// If the process exits instead, the test fails immediately.
///
/// Otherwise, waits until [pattern] appears, returns all text seen.
///
/// Throws if the process appears to be stuck or done: if it outputs nothing
/// for 30s.
Future<String> expectAndGetBlock(Pattern pattern, {Pattern? failOn}) async {
printOnFailure(
'--- $_testLine expects `$pattern`'
'${failOn == null ? '' : ', failOn: `$failOn`'}',
);
failOn ??= BuildLog.failurePattern;
final lines = StringBuffer();
while (true) {
String? line;
try {
line = await _outputs.next.timeout(const Duration(seconds: 30));
lines.writeln(line);
} on TimeoutException catch (_) {
throw fail('While expecting `$pattern`, timed out after 30s.');
} catch (_) {
throw fail('While expecting `$pattern`, process exited.');
}
printOnFailure(line);
if (line.contains(pattern)) return lines.toString();
if (line.contains(failOn)) {
fail('While expecting `$pattern`, got `$failOn`.');
}
}
}
Expand Down Expand Up @@ -329,7 +350,7 @@ class BuildRunnerProcess {
// Expects the server to log that it is serving, records the port.
Future<void> expectServing() async {
final regexp = RegExp('Serving `web` on http://localhost:([0-9]+)');
final line = await expect(regexp);
final line = await expectAndGetLine(regexp);
final port = int.parse(regexp.firstMatch(line)!.group(1)!);
_port = port;
}
Expand Down
12 changes: 9 additions & 3 deletions build_runner/test/integration_tests/processes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ void main() async {
}
''');
var process = await tester.start('root_pkg', 'dart run root_pkg:parent');
var parentLine = await process.expect(RegExp(r'Parent is running\. \d+'));
var parentLine = await process.expectAndGetLine(
RegExp(r'Parent is running\. \d+'),
);
var parentPid = int.parse(parentLine.split(' ').last);
final childLine = await process.expect(RegExp(r'Child is waiting\. \d+'));
final childLine = await process.expectAndGetLine(
RegExp(r'Child is waiting\. \d+'),
);
var childPid = int.parse(childLine.split(' ').last);

expect(processIsRunning(parentPid), true);
Expand Down Expand Up @@ -128,7 +132,9 @@ void main() async {
}
''');
process = await tester.start('root_pkg', 'dart run root_pkg:parent');
parentLine = await process.expect(RegExp(r'Parent is running\. \d+'));
parentLine = await process.expectAndGetLine(
RegExp(r'Parent is running\. \d+'),
);
parentPid = int.parse(parentLine.split(' ').last);

while (tester.read('root_pkg/pid.txt') == null) {
Expand Down
7 changes: 4 additions & 3 deletions build_runner/test/integration_tests/web_compilers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,10 @@ String helloWorld = 'Hello Dash!';
class Foo<T>{}
String helloWorld = 'Hello Dash!';
''');
await watch.expect(
'Hot reload rejected due to unsupported changes',
expectFailure: true,
final errorText = await watch.expectAndGetBlock(BuildLog.failurePattern);
expect(
errorText,
contains('Hot reload rejected due to unsupported changes'),
);

// Revert the invalid edit, rebuild succeeds.
Expand Down
4 changes: 4 additions & 0 deletions build_test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.5.3-wip

- Use `build_runner` 2.10.3.

## 3.5.2-wip

- Use `build_runner` 2.10.2.
Expand Down
4 changes: 2 additions & 2 deletions build_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: build_test
description: Utilities for writing unit tests of Builders.
version: 3.5.2-wip
version: 3.5.3-wip
repository: https://github.com/dart-lang/build/tree/master/build_test
resolution: workspace

Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
build: ^4.0.0
build_config: ^1.0.0
build_runner: '2.10.2-wip'
build_runner: '2.10.3-wip'
built_collection: ^5.1.1
crypto: ^3.0.0
glob: ^2.0.0
Expand Down
Loading