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

Unified Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 1923973004: Pubspec-specified analysis configuration (#26359). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: typeo Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/context_manager_test.dart
diff --git a/pkg/analysis_server/test/context_manager_test.dart b/pkg/analysis_server/test/context_manager_test.dart
index d20e5994d4469750e4ba4109b64bb13f2f458af7..9f00603059afb09677b19d2e16d82423014378de 100644
--- a/pkg/analysis_server/test/context_manager_test.dart
+++ b/pkg/analysis_server/test/context_manager_test.dart
@@ -78,6 +78,11 @@ class AbstractContextManagerTest {
String projPath = '/my/proj';
+ AnalysisError missing_required_param = new AnalysisError(
+ new TestSource(), 0, 1, HintCode.MISSING_REQUIRED_PARAM, [
+ ['x']
+ ]);
+
AnalysisError missing_return =
new AnalysisError(new TestSource(), 0, 1, HintCode.MISSING_RETURN, [
['x']
@@ -284,6 +289,98 @@ linter:
// No error means success.
}
+ test_configed_options() async {
+ // Create files.
+ String libPath = newFolder([projPath, LIB_NAME]);
+ newFile([projPath, 'test', 'test.dart']);
+ newFile(
+ [projPath, 'pubspec.yaml'],
+ r'''
+dependencies:
+ test_pack: any
+analyzer:
+ configuration: test_pack/config
+''');
+
+ // Setup .packages file
+ newFile(
+ [projPath, '.packages'],
+ r'''
+test_pack:lib/''');
+
+ // Setup config.yaml.
+ newFile(
+ [libPath, 'config', 'config.yaml'],
+ r'''
+analyzer:
+ strong-mode: true
+ language:
+ enableSuperMixins: true
+ errors:
+ missing_return: false
+linter:
+ rules:
+ - avoid_as
+''');
+
+ // Setup .analysis_options
+ newFile(
+ [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE],
+ r'''
+analyzer:
+ exclude:
+ - 'test/**'
+ language:
+ enableGenericMethods: true
+ enableAsync: false
+ errors:
+ unused_local_variable: false
+linter:
+ rules:
+ - camel_case_types
+''');
+
+ // Setup context.
+ manager.setRoots(<String>[projPath], <String>[], <String, String>{});
+ await pumpEventQueue();
+
+ // Confirm that one context was created.
+ var contexts =
+ manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
+ expect(contexts, isNotNull);
+ expect(contexts, hasLength(1));
+
+ var context = contexts.first;
+
+ // Verify options.
+ // * from `config.yaml`:
+ expect(context.analysisOptions.strongMode, isTrue);
+ expect(context.analysisOptions.enableSuperMixins, isTrue);
+ expect(context.analysisOptions.enableAsync, isFalse);
+ // * from `.analysis_options`:
+ expect(context.analysisOptions.enableGenericMethods, isTrue);
+
+ // * verify tests are excluded
+ expect(callbacks.currentContextFilePaths[projPath].keys,
+ unorderedEquals(['/my/proj/.analysis_options']));
+
+ // Verify filter setup.
+ expect(errorProcessors, hasLength(2));
+
+ // * (config.)
+ expect(getProcessor(missing_return).severity, isNull);
+
+ // * (options.)
+ expect(getProcessor(unused_local_variable).severity, isNull);
+
+ // Verify lints.
+ var lintNames = lints.map((lint) => lint.name);
+ expect(
+ lintNames,
+ unorderedEquals(
+ ['avoid_as' /* config */, 'camel_case_types' /* options */]));
+ }
+
void test_contextsInAnalysisRoot_nestedContext() {
String subProjPath = posix.join(projPath, 'subproj');
Folder subProjFolder = resourceProvider.newFolder(subProjPath);
@@ -362,6 +459,130 @@ test_pack:lib/''');
expect(contexts.first.sourceFactory.forUri('dart:typed_data'), isNotNull);
}
+ test_embedder_and_configed_options() async {
+ // Create files.
+ String libPath = newFolder([projPath, LIB_NAME]);
+ String sdkExtPath = newFolder([projPath, 'sdk_ext']);
+ newFile([projPath, 'test', 'test.dart']);
+ newFile([sdkExtPath, 'entry.dart']);
+
+ // Setup pubspec with configuration.
+ newFile(
+ [projPath, 'pubspec.yaml'],
+ r'''
+dependencies:
+ test_pack: any
+analyzer:
+ configuration: test_pack/config
+''');
+
+ // Setup _embedder.yaml.
+ newFile(
+ [libPath, '_embedder.yaml'],
+ r'''
+embedded_libs:
+ "dart:foobar": "../sdk_ext/entry.dart"
+analyzer:
+ strong-mode: true
+ language:
+ enableSuperMixins: true
+ errors:
+ missing_return: false
+linter:
+ rules:
+ - avoid_as
+''');
+
+ // Setup .packages file
+ newFile(
+ [projPath, '.packages'],
+ r'''
+test_pack:lib/''');
+
+ // Setup .analysis_options
+ newFile(
+ [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE],
+ r'''
+analyzer:
+ exclude:
+ - 'test/**'
+ language:
+ enableGenericMethods: true
+ enableAsync: false
+ errors:
+ unused_local_variable: false
+linter:
+ rules:
+ - camel_case_types
+''');
+
+ // Setup config.yaml.
+ newFile(
+ [libPath, 'config', 'config.yaml'],
+ r'''
+analyzer:
+ errors:
+ missing_required_param: error
+linter:
+ rules:
+ - always_specify_types
+''');
+
+ // Setup context.
+ manager.setRoots(<String>[projPath], <String>[], <String, String>{});
+ await pumpEventQueue();
+
+ // Confirm that one context was created.
+ var contexts =
+ manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
+ expect(contexts, isNotNull);
+ expect(contexts, hasLength(1));
+ var context = contexts[0];
+
+ // Verify options.
+ // * from `_embedder.yaml`:
+ expect(context.analysisOptions.strongMode, isTrue);
+ expect(context.analysisOptions.enableSuperMixins, isTrue);
+ expect(context.analysisOptions.enableAsync, isFalse);
+ // * from `.analysis_options`:
+ expect(context.analysisOptions.enableGenericMethods, isTrue);
+
+ // * verify tests are excluded
+ expect(
+ callbacks.currentContextFilePaths[projPath].keys,
+ unorderedEquals(
+ ['/my/proj/sdk_ext/entry.dart', '/my/proj/.analysis_options']));
+
+ // Verify filter setup.
+ expect(errorProcessors, hasLength(3));
+
+ // * (embedder.)
+ expect(getProcessor(missing_return).severity, isNull);
+
+ // * (config.)
+ expect(getProcessor(missing_required_param).severity, ErrorSeverity.ERROR);
+
+ // * (options.)
+ expect(getProcessor(unused_local_variable).severity, isNull);
+
+ // Verify lints.
+ var lintNames = lints.map((lint) => lint.name);
+
+ expect(
+ lintNames,
+ unorderedEquals([
+ 'avoid_as' /* embedder */,
+ 'always_specify_types' /* config*/,
+ 'camel_case_types' /* options */
+ ]));
+
+ // Sanity check embedder libs.
+ var source = context.sourceFactory.forUri('dart:foobar');
+ expect(source, isNotNull);
+ expect(source.fullName,
+ '/my/proj/sdk_ext/entry.dart'.replaceAll('/', JavaFile.separator));
+ }
+
test_embedder_options() async {
// Create files.
String libPath = newFolder([projPath, LIB_NAME]);

Powered by Google App Engine
This is Rietveld 408576698