-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathembedder_test.dart
66 lines (57 loc) · 1.64 KB
/
embedder_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:analyzer_cli/src/driver.dart' show Driver, errorSink, outSink;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'utils.dart';
void main() {
group('_embedder.yaml', () {
late StringSink savedOutSink, savedErrorSink;
late int savedExitCode;
setUp(() {
savedOutSink = outSink;
savedErrorSink = errorSink;
savedExitCode = exitCode;
outSink = StringBuffer();
errorSink = StringBuffer();
});
tearDown(() {
outSink = savedOutSink;
errorSink = savedErrorSink;
exitCode = savedExitCode;
});
test(
'resolution',
wrap(() async {
var testDir = path.join(testDirectory, 'data', 'embedder_client');
await Driver().start([
'--packages',
path.join(testDir, '_packages'),
path.join(testDir, 'embedder_yaml_user.dart'),
]);
expect(exitCode, 0);
expect(outSink.toString(), contains('No issues found'));
}),
);
});
}
/// Wrap a function call to dump stdout and stderr in case of an exception.
dynamic Function() wrap(dynamic Function() f) {
return () async {
try {
await f();
} catch (e) {
if (outSink.toString().isNotEmpty) {
print('stdout:');
print(outSink);
}
if (errorSink.toString().isNotEmpty) {
print('stderr:');
print(errorSink);
}
rethrow;
}
};
}