Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: pkg/analyzer_cli/test/analysis_options_test.dart

Issue 2710313002: rework analyzer_cli to use ContextBuilder getAnalysisOptions (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import 'dart:async';
2 import 'dart:io';
3
4 import 'package:analyzer_cli/src/driver.dart' show Driver, outSink, errorSink;
5 import 'package:analyzer_cli/src/options.dart' show ExitHandler, exitHandler;
6 import 'package:path/path.dart' as path;
7 import 'package:test/test.dart';
8 import 'package:test_reflective_loader/test_reflective_loader.dart';
9
10 import 'utils.dart' show testDirectory, withTempDir;
11
12 main() {
13 defineReflectiveTests(OptionsTest);
14 }
15
16
17 @reflectiveTest
18 class OptionsTest {
19 _Runner runner;
20
21 void setUp() {
22 runner = new _Runner.setUp();
23 }
24
25 void tearDown() {
26 runner.tearDown();
27 runner = null;
28 }
29
30 test_options() async {
31 Future<Null> copy(FileSystemEntity src, String dstPath) async {
32 if (src is Directory) {
33 await (new Directory(dstPath)).create(recursive: true);
34 for (FileSystemEntity entity in src.listSync()) {
35 await copy(entity, path.join(dstPath, path.basename(entity.path)));
36 }
37 } else if (src is File) {
38 await src.copy(dstPath);
39 }
40 }
41
42 // Copy to temp dir so that existing analysis options
43 // in the test directory hierarchy do not interfere
44 var projDir = path.join(testDirectory, 'data', 'flutter_analysis_options');
45 await withTempDir((String tempDirPath) async {
46 await copy(new Directory(projDir), tempDirPath);
47 var expectedPath = path.join(tempDirPath, 'somepkgs', 'flutter', 'lib', 'a nalysis_options_user.yaml');
48 expect(FileSystemEntity.isFileSync(expectedPath), isTrue);
49 await runner.run2([
50 "--packages",
51 path.join(tempDirPath, 'packagelist'),
52 path.join(tempDirPath, 'lib', 'main.dart')
53 ]);
54 expect(runner.stdout, contains('The parameter \'child\' is required'));
55 // Should be a warning as specified in analysis_options_user.yaml
56 // not a hint
57 expect(runner.stdout, contains('1 warning found'));
58 });
59 }
60 }
61
62 class _Runner {
63 final _stdout = new StringBuffer();
64 final _stderr = new StringBuffer();
65
66 final StringSink _savedOutSink;
67 final StringSink _savedErrorSink;
68 final int _savedExitCode;
69 final ExitHandler _savedExitHandler;
70
71 _Runner.setUp()
72 : _savedOutSink = outSink,
73 _savedErrorSink = errorSink,
74 _savedExitHandler = exitHandler,
75 _savedExitCode = exitCode {
76 outSink = _stdout;
77 errorSink = _stderr;
78 exitHandler = (_) {};
79 }
80
81 String get stderr => _stderr.toString();
82
83 String get stdout => _stdout.toString();
84
85 Future<Null> run2(List<String> args) async {
86 await new Driver().start(args);
87 if (stderr.isNotEmpty) {
88 fail("Unexpected output to stderr:\n$stderr");
89 }
90 }
91
92 void tearDown() {
93 outSink = _savedOutSink;
94 errorSink = _savedErrorSink;
95 exitCode = _savedExitCode;
96 exitHandler = _savedExitHandler;
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698