OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 7 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
8 import 'package:analyzer/src/generated/sdk.dart'; | 8 import 'package:analyzer/src/generated/sdk.dart'; |
9 import 'package:analyzer_cli/src/driver.dart' show Driver, errorSink, outSink; | 9 import 'package:analyzer_cli/src/driver.dart' show Driver, errorSink, outSink; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
12 | 12 |
13 import 'utils.dart'; | 13 import 'utils.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 group('_embedder.yaml', () { | 16 group('_embedder.yaml', () { |
17 StringSink savedOutSink, savedErrorSink; | 17 StringSink savedOutSink, savedErrorSink; |
18 int savedExitCode; | 18 int savedExitCode; |
19 | 19 |
20 setUp(() { | 20 setUp(() { |
21 savedOutSink = outSink; | 21 savedOutSink = outSink; |
22 savedErrorSink = errorSink; | 22 savedErrorSink = errorSink; |
23 savedExitCode = exitCode; | 23 savedExitCode = exitCode; |
24 outSink = new StringBuffer(); | 24 outSink = new StringBuffer(); |
25 errorSink = new StringBuffer(); | 25 errorSink = new StringBuffer(); |
26 }); | 26 }); |
| 27 |
27 tearDown(() { | 28 tearDown(() { |
28 outSink = savedOutSink; | 29 outSink = savedOutSink; |
29 errorSink = savedErrorSink; | 30 errorSink = savedErrorSink; |
30 exitCode = savedExitCode; | 31 exitCode = savedExitCode; |
31 }); | 32 }); |
32 | 33 |
33 test('resolution', wrap(() { | 34 test('resolution', wrap(() async { |
34 var testDir = path.join(testDirectory, 'data', 'embedder_client'); | 35 var testDir = path.join(testDirectory, 'data', 'embedder_client'); |
35 new Driver().start([ | 36 await new Driver().start([ |
36 '--packages', | 37 '--packages', |
37 path.join(testDir, '_packages'), | 38 path.join(testDir, '_packages'), |
38 path.join(testDir, 'embedder_yaml_user.dart') | 39 path.join(testDir, 'embedder_yaml_user.dart') |
39 ]); | 40 ]); |
40 | 41 |
41 expect(exitCode, 0); | 42 expect(exitCode, 0); |
42 expect(outSink.toString(), contains('No issues found')); | 43 expect(outSink.toString(), contains('No issues found')); |
43 })); | 44 })); |
44 | 45 |
45 test('sdk setup', wrap(() { | 46 test('sdk setup', wrap(() async { |
46 var testDir = path.join(testDirectory, 'data', 'embedder_client'); | 47 var testDir = path.join(testDirectory, 'data', 'embedder_client'); |
47 Driver driver = new Driver(); | 48 Driver driver = new Driver(); |
48 driver.start([ | 49 await driver.start([ |
49 '--packages', | 50 '--packages', |
50 path.join(testDir, '_packages'), | 51 path.join(testDir, '_packages'), |
51 path.join(testDir, 'embedder_yaml_user.dart') | 52 path.join(testDir, 'embedder_yaml_user.dart') |
52 ]); | 53 ]); |
53 | 54 |
54 DartSdk sdk = driver.sdk; | 55 DartSdk sdk = driver.sdk; |
55 expect(sdk, new isInstanceOf<FolderBasedDartSdk>()); | 56 expect(sdk, new isInstanceOf<FolderBasedDartSdk>()); |
56 expect((sdk as FolderBasedDartSdk).useSummary, isFalse); | 57 expect((sdk as FolderBasedDartSdk).useSummary, isFalse); |
57 })); | 58 })); |
58 }); | 59 }); |
59 } | 60 } |
60 | 61 |
61 /// Wrap a function call to dump stdout and stderr in case of an exception. | 62 /// Wrap a function call to dump stdout and stderr in case of an exception. |
62 Function wrap(Function f) { | 63 Function wrap(Function f) { |
63 return () { | 64 return () async { |
64 try { | 65 try { |
65 f(); | 66 await f(); |
66 } catch (e) { | 67 } catch (e) { |
67 if (outSink.toString().isNotEmpty) { | 68 if (outSink.toString().isNotEmpty) { |
68 print('stdout:'); | 69 print('stdout:'); |
69 print(outSink); | 70 print(outSink); |
70 } | 71 } |
71 if (errorSink.toString().isNotEmpty) { | 72 if (errorSink.toString().isNotEmpty) { |
72 print('stderr:'); | 73 print('stderr:'); |
73 print(errorSink); | 74 print(errorSink); |
74 } | 75 } |
75 throw e; | 76 throw e; |
76 } | 77 } |
77 }; | 78 }; |
78 } | 79 } |
OLD | NEW |