File tree Expand file tree Collapse file tree 3 files changed +10
-18
lines changed Expand file tree Collapse file tree 3 files changed +10
-18
lines changed Original file line number Diff line number Diff line change 1
1
## 3.3.0-wip
2
2
3
+ - Bug fix: don't crash when a builder logs during a ` testBuilder ` or
4
+ ` resolveSource ` call outside a test.
3
5
- Remove unused deps: ` async ` , ` convert ` .
4
6
- Remove unused dev_deps: ` collection ` .
5
7
Original file line number Diff line number Diff line change 3
3
// BSD-style license that can be found in the LICENSE file.
4
4
import 'dart:async' ;
5
5
import 'dart:convert' ;
6
+ import 'dart:io' ;
6
7
7
8
import 'package:build/build.dart' ;
8
9
import 'package:build/experiments.dart' ;
@@ -233,7 +234,7 @@ Future<TestBuilderResult> testBuilders(
233
234
TestReaderWriter ? readerWriter,
234
235
bool enableLowResourceMode = false ,
235
236
}) async {
236
- onLog ?? = _printOnFailureOrPrint ;
237
+ onLog ?? = _printOnFailureOrWrite ;
237
238
238
239
var inputIds = {
239
240
for (var descriptor in sourceAssets.keys) makeAssetId (descriptor),
@@ -382,7 +383,7 @@ class TestBuilderResult {
382
383
TestBuilderResult ({required this .buildResult, required this .readerWriter});
383
384
}
384
385
385
- void _printOnFailureOrPrint (LogRecord record) {
386
+ void _printOnFailureOrWrite (LogRecord record) {
386
387
final message =
387
388
'$record '
388
389
'${record .error == null ? '' : ' ${record .error }' }'
@@ -391,7 +392,8 @@ void _printOnFailureOrPrint(LogRecord record) {
391
392
// This throws if a test is not currently running.
392
393
printOnFailure (message);
393
394
} catch (_) {
394
- // Print instead.
395
- print (message);
395
+ // Write instead. Don't `print` because that would hit the Zone print
396
+ // handler if logging from a builder.
397
+ stdout.writeln (message);
396
398
}
397
399
}
Original file line number Diff line number Diff line change @@ -13,20 +13,8 @@ import 'package:test/test.dart';
13
13
14
14
Future <void > main () async {
15
15
// Default logging uses `printOnFailure` which crashes outside tests; check
16
- // that it falls back to `print` outside tests.
17
- final printed = < String > [];
18
- await runZonedGuarded (
19
- () async {
20
- await testBuilder (TestBuilder (), {'a|lib/a.dart' : '' }, rootPackage: 'a' );
21
- },
22
- (_, _) {},
23
- zoneSpecification: ZoneSpecification (
24
- print: (_, _, _, string) {
25
- printed.add (string);
26
- },
27
- ),
28
- );
29
- if (printed.isEmpty) throw StateError ('Expected some prints.' );
16
+ // that it falls back to something else outside tests.
17
+ await testBuilder (TestBuilder (), {'a|lib/a.dart' : '' }, rootPackage: 'a' );
30
18
31
19
test ('can glob files in the root package' , () async {
32
20
var assets = {
You can’t perform that action at this time.
0 commit comments