| Index: pkg/analyzer/test/src/task/options_work_manager_test.dart
|
| diff --git a/pkg/analyzer/test/src/task/html_work_manager_test.dart b/pkg/analyzer/test/src/task/options_work_manager_test.dart
|
| similarity index 55%
|
| copy from pkg/analyzer/test/src/task/html_work_manager_test.dart
|
| copy to pkg/analyzer/test/src/task/options_work_manager_test.dart
|
| index 0785f97c324973d54452be67ee01cfe9e14f4119..424a7291dfc6049396c710a655cf513db78fc9a6 100644
|
| --- a/pkg/analyzer/test/src/task/html_work_manager_test.dart
|
| +++ b/pkg/analyzer/test/src/task/options_work_manager_test.dart
|
| @@ -2,7 +2,7 @@
|
| // 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.
|
|
|
| -library test.src.task.html_work_manager_test;
|
| +library test.src.task.options_work_manager_test;
|
|
|
| import 'package:analyzer/src/context/cache.dart';
|
| import 'package:analyzer/src/generated/engine.dart'
|
| @@ -14,14 +14,13 @@ import 'package:analyzer/src/generated/engine.dart'
|
| ChangeNoticeImpl,
|
| InternalAnalysisContext;
|
| import 'package:analyzer/src/generated/error.dart'
|
| - show AnalysisError, HtmlErrorCode;
|
| -import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
|
| + show AnalysisError, AnalysisOptionsErrorCode;
|
| +import 'package:analyzer/src/generated/java_engine.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| -import 'package:analyzer/src/task/html.dart';
|
| -import 'package:analyzer/src/task/html_work_manager.dart';
|
| +import 'package:analyzer/src/task/options.dart';
|
| +import 'package:analyzer/src/task/options_work_manager.dart';
|
| import 'package:analyzer/task/dart.dart';
|
| import 'package:analyzer/task/general.dart';
|
| -import 'package:analyzer/task/html.dart';
|
| import 'package:analyzer/task/model.dart';
|
| import 'package:typed_mock/typed_mock.dart';
|
| import 'package:unittest/unittest.dart';
|
| @@ -32,21 +31,23 @@ import '../../utils.dart';
|
|
|
| main() {
|
| initializeTestEnvironment();
|
| - runReflectiveTests(HtmlWorkManagerTest);
|
| + runReflectiveTests(OptionsWorkManagerTest);
|
| }
|
|
|
| @reflectiveTest
|
| -class HtmlWorkManagerTest {
|
| +class OptionsWorkManagerTest {
|
| + static final optionsFile = AnalysisEngine.ANALYSIS_OPTIONS_FILE;
|
| InternalAnalysisContext context = new _InternalAnalysisContextMock();
|
| AnalysisCache cache;
|
| - HtmlWorkManager manager;
|
| +
|
| + OptionsWorkManager manager;
|
|
|
| CaughtException caughtException = new CaughtException(null, null);
|
|
|
| - Source source1 = new TestSource('1.html');
|
| - Source source2 = new TestSource('2.html');
|
| - Source source3 = new TestSource('3.html');
|
| - Source source4 = new TestSource('4.html');
|
| + Source source1 = new TestSource('test1/$optionsFile');
|
| + Source source2 = new TestSource('test2/$optionsFile');
|
| + Source source3 = new TestSource('test3/$optionsFile');
|
| + Source source4 = new TestSource('test4/$optionsFile');
|
| CacheEntry entry1;
|
| CacheEntry entry2;
|
| CacheEntry entry3;
|
| @@ -58,7 +59,7 @@ class HtmlWorkManagerTest {
|
|
|
| void setUp() {
|
| cache = context.analysisCache;
|
| - manager = new HtmlWorkManager(context);
|
| + manager = new OptionsWorkManager(context);
|
| entry1 = context.getCacheEntry(source1);
|
| entry2 = context.getCacheEntry(source2);
|
| entry3 = context.getCacheEntry(source3);
|
| @@ -112,110 +113,97 @@ class HtmlWorkManagerTest {
|
| void test_applyPriorityTargets() {
|
| when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true);
|
| when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true);
|
| - manager.priorityResultQueue.add(new TargetedResult(source1, HTML_ERRORS));
|
| - manager.priorityResultQueue.add(new TargetedResult(source2, HTML_ERRORS));
|
| + manager.priorityResultQueue
|
| + .add(new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS));
|
| + manager.priorityResultQueue
|
| + .add(new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS));
|
| // -source1 +source3
|
| manager.applyPriorityTargets([source2, source3]);
|
| expect(
|
| manager.priorityResultQueue,
|
| unorderedEquals([
|
| - new TargetedResult(source2, HTML_ERRORS),
|
| - new TargetedResult(source3, HTML_ERRORS)
|
| + new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS),
|
| + new TargetedResult(source3, ANALYSIS_OPTIONS_ERRORS)
|
| ]));
|
| // get next request
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source2);
|
| - expect(request.result, HTML_ERRORS);
|
| - }
|
| -
|
| - void test_getErrors_fullList() {
|
| - AnalysisError error1 =
|
| - new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| - AnalysisError error2 =
|
| - new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| - entry1.setValue(HTML_DOCUMENT_ERRORS, <AnalysisError>[error1], []);
|
| -
|
| - DartScript script = new DartScript(source1, []);
|
| - entry1.setValue(DART_SCRIPTS, [script], []);
|
| - CacheEntry scriptEntry = context.getCacheEntry(script);
|
| - scriptEntry.setValue(DART_ERRORS, [error2], []);
|
| -
|
| - List<AnalysisError> errors = manager.getErrors(source1);
|
| - expect(errors, unorderedEquals([error1, error2]));
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| }
|
|
|
| - void test_getErrors_partialList() {
|
| - AnalysisError error1 =
|
| - new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| - AnalysisError error2 =
|
| - new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| - entry1.setValue(HTML_DOCUMENT_ERRORS, <AnalysisError>[error1, error2], []);
|
| + void test_getErrors() {
|
| + AnalysisError error1 = new AnalysisError(
|
| + source1, 1, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
|
| + AnalysisError error2 = new AnalysisError(
|
| + source1, 2, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
|
| + entry1.setValue(
|
| + ANALYSIS_OPTIONS_ERRORS, <AnalysisError>[error1, error2], []);
|
|
|
| List<AnalysisError> errors = manager.getErrors(source1);
|
| expect(errors, unorderedEquals([error1, error2]));
|
| }
|
|
|
| void test_getNextResult_hasNormal_firstIsError() {
|
| - entry1.setErrorState(caughtException, [HTML_ERRORS]);
|
| + entry1.setErrorState(caughtException, [ANALYSIS_OPTIONS_ERRORS]);
|
| manager.sourceQueue.addAll([source1, source2]);
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source2);
|
| - expect(request.result, HTML_ERRORS);
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| // source1 is out, source2 is waiting
|
| expect_sourceQueue([source2]);
|
| }
|
|
|
| void test_getNextResult_hasNormal_firstIsInvalid() {
|
| - entry1.setState(HTML_ERRORS, CacheState.INVALID);
|
| + entry1.setState(ANALYSIS_OPTIONS_ERRORS, CacheState.INVALID);
|
| manager.sourceQueue.addAll([source1, source2]);
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source1);
|
| - expect(request.result, HTML_ERRORS);
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| // no changes until computed
|
| expect_sourceQueue([source1, source2]);
|
| }
|
|
|
| void test_getNextResult_hasNormal_firstIsValid() {
|
| - entry1.setValue(HTML_ERRORS, [], []);
|
| + entry1.setValue(ANALYSIS_OPTIONS_ERRORS, [], []);
|
| manager.sourceQueue.addAll([source1, source2]);
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source2);
|
| - expect(request.result, HTML_ERRORS);
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| // source1 is out, source2 is waiting
|
| expect_sourceQueue([source2]);
|
| }
|
|
|
| void test_getNextResult_hasNormalAndPriority() {
|
| - entry1.setState(HTML_ERRORS, CacheState.INVALID);
|
| + entry1.setState(ANALYSIS_OPTIONS_ERRORS, CacheState.INVALID);
|
| manager.sourceQueue.addAll([source1, source2]);
|
| - manager.addPriorityResult(source3, HTML_ERRORS);
|
| + manager.addPriorityResult(source3, ANALYSIS_OPTIONS_ERRORS);
|
|
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source3);
|
| - expect(request.result, HTML_ERRORS);
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| // no changes until computed
|
| expect_sourceQueue([source1, source2]);
|
| }
|
|
|
| void test_getNextResult_hasPriority() {
|
| - manager.addPriorityResult(source1, HTML_ERRORS);
|
| - manager.addPriorityResult(source2, HTML_ERRORS);
|
| + manager.addPriorityResult(source1, ANALYSIS_OPTIONS_ERRORS);
|
| + manager.addPriorityResult(source2, ANALYSIS_OPTIONS_ERRORS);
|
| expect(
|
| manager.priorityResultQueue,
|
| unorderedEquals([
|
| - new TargetedResult(source1, HTML_ERRORS),
|
| - new TargetedResult(source2, HTML_ERRORS)
|
| + new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS),
|
| + new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS)
|
| ]));
|
|
|
| TargetedResult request = manager.getNextResult();
|
| expect(request.target, source1);
|
| - expect(request.result, HTML_ERRORS);
|
| + expect(request.result, ANALYSIS_OPTIONS_ERRORS);
|
| // no changes until computed
|
| expect(
|
| manager.priorityResultQueue,
|
| unorderedEquals([
|
| - new TargetedResult(source1, HTML_ERRORS),
|
| - new TargetedResult(source2, HTML_ERRORS)
|
| + new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS),
|
| + new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS)
|
| ]));
|
| }
|
|
|
| @@ -238,64 +226,17 @@ class HtmlWorkManagerTest {
|
| expect(manager.getNextResultPriority(), WorkOrderPriority.NONE);
|
| }
|
|
|
| - void test_onAnalysisOptionsChanged() {
|
| - when(context.exists(anyObject)).thenReturn(true);
|
| - // set cache values
|
| - entry1.setValue(DART_SCRIPTS, [], []);
|
| - entry1.setValue(HTML_DOCUMENT, null, []);
|
| - entry1.setValue(HTML_DOCUMENT_ERRORS, [], []);
|
| - entry1.setValue(HTML_ERRORS, [], []);
|
| - entry1.setValue(REFERENCED_LIBRARIES, [], []);
|
| - // notify
|
| - manager.onAnalysisOptionsChanged();
|
| - // Only resolution-based values are invalidated.
|
| - expect(entry1.getState(DART_SCRIPTS), CacheState.VALID);
|
| - expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID);
|
| - expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID);
|
| - expect(entry1.getState(HTML_ERRORS), CacheState.INVALID);
|
| - expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.VALID);
|
| - }
|
| -
|
| - void test_onResultInvalidated_scheduleInvalidatedLibraries() {
|
| - // set HTML_ERRORS for source1 and source3
|
| - entry1.setValue(HTML_ERRORS, [], []);
|
| - entry3.setValue(HTML_ERRORS, [], []);
|
| - // invalidate HTML_ERRORS for source1, schedule it
|
| - entry1.setState(HTML_ERRORS, CacheState.INVALID);
|
| - expect_sourceQueue([source1]);
|
| - // invalidate HTML_ERRORS for source3, schedule it
|
| - entry3.setState(HTML_ERRORS, CacheState.INVALID);
|
| - expect_sourceQueue([source1, source3]);
|
| - }
|
| -
|
| - void test_onSourceFactoryChanged() {
|
| - when(context.exists(anyObject)).thenReturn(true);
|
| - // set cache values
|
| - entry1.setValue(DART_SCRIPTS, [], []);
|
| - entry1.setValue(HTML_DOCUMENT, null, []);
|
| - entry1.setValue(HTML_DOCUMENT_ERRORS, [], []);
|
| - entry1.setValue(HTML_ERRORS, [], []);
|
| - entry1.setValue(REFERENCED_LIBRARIES, [], []);
|
| - // notify
|
| - manager.onSourceFactoryChanged();
|
| - // Only resolution-based values are invalidated.
|
| - expect(entry1.getState(DART_SCRIPTS), CacheState.VALID);
|
| - expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID);
|
| - expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID);
|
| - expect(entry1.getState(HTML_ERRORS), CacheState.INVALID);
|
| - expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.INVALID);
|
| - }
|
| -
|
| void test_resultsComputed_errors() {
|
| - AnalysisError error1 =
|
| - new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| - AnalysisError error2 =
|
| - new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']);
|
| + AnalysisError error1 = new AnalysisError(
|
| + source1, 1, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
|
| + AnalysisError error2 = new AnalysisError(
|
| + source1, 2, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
|
| LineInfo lineInfo = new LineInfo([0]);
|
| entry1.setValue(LINE_INFO, lineInfo, []);
|
| - entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []);
|
| + entry1.setValue(
|
| + ANALYSIS_OPTIONS_ERRORS, <AnalysisError>[error1, error2], []);
|
| // RESOLVED_UNIT is ready, set errors
|
| - manager.resultsComputed(source1, {HTML_ERRORS: null});
|
| + manager.resultsComputed(source1, {ANALYSIS_OPTIONS_ERRORS: null});
|
| // all of the errors are included
|
| ChangeNoticeImpl notice = context.getNotice(source1);
|
| expect(notice.errors, unorderedEquals([error1, error2]));
|
| @@ -330,22 +271,17 @@ class _InternalAnalysisContextMock extends TypedMock
|
|
|
| @override
|
| AnalysisErrorInfo getErrors(Source source) {
|
| - String name = source.shortName;
|
| List<AnalysisError> errors = AnalysisError.NO_ERRORS;
|
| - if (AnalysisEngine.isDartFileName(name) || source is DartScript) {
|
| - errors = getCacheEntry(source).getValue(DART_ERRORS);
|
| - } else if (AnalysisEngine.isHtmlFileName(name)) {
|
| - errors = getCacheEntry(source).getValue(HTML_ERRORS);
|
| + if (AnalysisEngine.isAnalysisOptionsFileName(source.shortName)) {
|
| + errors = getCacheEntry(source).getValue(ANALYSIS_OPTIONS_ERRORS);
|
| }
|
| return new AnalysisErrorInfoImpl(
|
| errors, getCacheEntry(source).getValue(LINE_INFO));
|
| }
|
|
|
| @override
|
| - ChangeNoticeImpl getNotice(Source source) {
|
| - return _pendingNotices.putIfAbsent(
|
| - source, () => new ChangeNoticeImpl(source));
|
| - }
|
| + ChangeNoticeImpl getNotice(Source source) =>
|
| + _pendingNotices.putIfAbsent(source, () => new ChangeNoticeImpl(source));
|
|
|
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
| }
|
|
|