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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1361003002: Reset Source modification stamp to -1 if it does not exist. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library test.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 reason: "libA resolved 2"); 1765 reason: "libA resolved 2");
1766 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), 1766 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)),
1767 isTrue, 1767 isTrue,
1768 reason: "libA has an error"); 1768 reason: "libA has an error");
1769 } 1769 }
1770 1770
1771 void test_performAnalysisTask_IOException() { 1771 void test_performAnalysisTask_IOException() {
1772 TestSource source = _addSourceWithException2("/test.dart", "library test;"); 1772 TestSource source = _addSourceWithException2("/test.dart", "library test;");
1773 source.generateExceptionOnRead = false; 1773 source.generateExceptionOnRead = false;
1774 _analyzeAll_assertFinished(); 1774 _analyzeAll_assertFinished();
1775 expect(source.readCount, 1); 1775 expect(source.readCount, 2);
Brian Wilkerson 2015/09/23 13:53:38 I don't understand why this change would cause the
scheglov 2015/09/23 15:11:27 The scenario is following. 1. We add test.dart as
1776 _changeSource(source, ""); 1776 _changeSource(source, "");
1777 source.generateExceptionOnRead = true; 1777 source.generateExceptionOnRead = true;
1778 _analyzeAll_assertFinished(); 1778 _analyzeAll_assertFinished();
1779 if (AnalysisEngine.instance.limitInvalidationInTaskModel) { 1779 if (AnalysisEngine.instance.limitInvalidationInTaskModel) {
1780 expect(source.readCount, 7);
1781 } else {
1780 expect(source.readCount, 5); 1782 expect(source.readCount, 5);
1781 } else {
1782 expect(source.readCount, 3);
1783 } 1783 }
1784 } 1784 }
1785 1785
1786 void test_performAnalysisTask_missingPart() { 1786 void test_performAnalysisTask_missingPart() {
1787 Source source = 1787 Source source =
1788 addSource("/test.dart", "library lib; part 'no-such-file.dart';"); 1788 addSource("/test.dart", "library lib; part 'no-such-file.dart';");
1789 _analyzeAll_assertFinished(); 1789 _analyzeAll_assertFinished();
1790 expect(context.getLibraryElement(source), isNotNull, 1790 expect(context.getLibraryElement(source), isNotNull,
1791 reason: "performAnalysisTask failed to compute an element model"); 1791 reason: "performAnalysisTask failed to compute an element model");
1792 } 1792 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 context.resolveCompilationUnit2(sourceA, sourceA); 1862 context.resolveCompilationUnit2(sourceA, sourceA);
1863 expect(compilationUnit, isNotNull); 1863 expect(compilationUnit, isNotNull);
1864 LibraryElement library = compilationUnit.element.library; 1864 LibraryElement library = compilationUnit.element.library;
1865 List<LibraryElement> importedLibraries = library.importedLibraries; 1865 List<LibraryElement> importedLibraries = library.importedLibraries;
1866 assertNamedElements(importedLibraries, ["dart.core", "libB"]); 1866 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
1867 List<LibraryElement> visibleLibraries = library.visibleLibraries; 1867 List<LibraryElement> visibleLibraries = library.visibleLibraries;
1868 assertNamedElements(visibleLibraries, 1868 assertNamedElements(visibleLibraries,
1869 ["dart.core", "dart.async", "dart.math", "libA", "libB"]); 1869 ["dart.core", "dart.async", "dart.math", "libA", "libB"]);
1870 } 1870 }
1871 1871
1872 void test_resolveCompilationUnit_library() {
1873 Source source = addSource("/lib.dart", "library lib;");
1874 LibraryElement library = context.computeLibraryElement(source);
1875 CompilationUnit compilationUnit =
1876 context.resolveCompilationUnit(source, library);
1877 expect(compilationUnit, isNotNull);
1878 expect(compilationUnit.element, isNotNull);
1879 }
1880
1872 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { 1881 // void test_resolveCompilationUnit_sourceChangeDuringResolution() {
1873 // _context = new _AnalysisContext_sourceChangeDuringResolution(); 1882 // _context = new _AnalysisContext_sourceChangeDuringResolution();
1874 // AnalysisContextFactory.initContextWithCore(_context); 1883 // AnalysisContextFactory.initContextWithCore(_context);
1875 // _sourceFactory = _context.sourceFactory; 1884 // _sourceFactory = _context.sourceFactory;
1876 // Source source = _addSource("/lib.dart", "library lib;"); 1885 // Source source = _addSource("/lib.dart", "library lib;");
1877 // CompilationUnit compilationUnit = 1886 // CompilationUnit compilationUnit =
1878 // _context.resolveCompilationUnit2(source, source); 1887 // _context.resolveCompilationUnit2(source, source);
1879 // expect(compilationUnit, isNotNull); 1888 // expect(compilationUnit, isNotNull);
1880 // expect(_context.getLineInfo(source), isNotNull); 1889 // expect(_context.getLineInfo(source), isNotNull);
1881 // } 1890 // }
1882 1891
1883 void test_resolveCompilationUnit_library() {
1884 Source source = addSource("/lib.dart", "library lib;");
1885 LibraryElement library = context.computeLibraryElement(source);
1886 CompilationUnit compilationUnit =
1887 context.resolveCompilationUnit(source, library);
1888 expect(compilationUnit, isNotNull);
1889 expect(compilationUnit.element, isNotNull);
1890 }
1891
1892 void test_resolveCompilationUnit_source() { 1892 void test_resolveCompilationUnit_source() {
1893 Source source = addSource("/lib.dart", "library lib;"); 1893 Source source = addSource("/lib.dart", "library lib;");
1894 CompilationUnit compilationUnit = 1894 CompilationUnit compilationUnit =
1895 context.resolveCompilationUnit2(source, source); 1895 context.resolveCompilationUnit2(source, source);
1896 expect(compilationUnit, isNotNull); 1896 expect(compilationUnit, isNotNull);
1897 } 1897 }
1898 1898
1899 void test_setAnalysisOptions() { 1899 void test_setAnalysisOptions() {
1900 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1900 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1901 options.cacheSize = 42; 1901 options.cacheSize = 42;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 AnalysisDelta delta = new AnalysisDelta(); 2066 AnalysisDelta delta = new AnalysisDelta();
2067 delta.setAnalysisLevel(source, AnalysisLevel.ALL); 2067 delta.setAnalysisLevel(source, AnalysisLevel.ALL);
2068 context.applyAnalysisDelta(delta); 2068 context.applyAnalysisDelta(delta);
2069 expect(context.sourcesNeedingProcessing, contains(source)); 2069 expect(context.sourcesNeedingProcessing, contains(source));
2070 delta = new AnalysisDelta(); 2070 delta = new AnalysisDelta();
2071 delta.setAnalysisLevel(source, AnalysisLevel.NONE); 2071 delta.setAnalysisLevel(source, AnalysisLevel.NONE);
2072 context.applyAnalysisDelta(delta); 2072 context.applyAnalysisDelta(delta);
2073 expect(context.sourcesNeedingProcessing.contains(source), isFalse); 2073 expect(context.sourcesNeedingProcessing.contains(source), isFalse);
2074 } 2074 }
2075 2075
2076 void test_validateCacheConsistency_deletedSource() {
2077 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
2078 var fileA = resourceProvider.newFile('/a.dart', "");
2079 var fileB = resourceProvider.newFile('/b.dart', "import 'a.dart';");
2080 Source sourceA = fileA.createSource();
2081 Source sourceB = fileB.createSource();
2082 context.applyChanges(
2083 new ChangeSet()..addedSource(sourceA)..addedSource(sourceB));
2084 // analyze everything
2085 _analyzeAll_assertFinished();
2086 // delete a.dart
2087 resourceProvider.deleteFile('/a.dart');
2088 // analysis should eventually stop
2089 _analyzeAll_assertFinished();
2090 }
2091
2076 void xtest_performAnalysisTask_stress() { 2092 void xtest_performAnalysisTask_stress() {
2077 int maxCacheSize = 4; 2093 int maxCacheSize = 4;
2078 AnalysisOptionsImpl options = 2094 AnalysisOptionsImpl options =
2079 new AnalysisOptionsImpl.from(context.analysisOptions); 2095 new AnalysisOptionsImpl.from(context.analysisOptions);
2080 options.cacheSize = maxCacheSize; 2096 options.cacheSize = maxCacheSize;
2081 context.analysisOptions = options; 2097 context.analysisOptions = options;
2082 int sourceCount = maxCacheSize + 2; 2098 int sourceCount = maxCacheSize + 2;
2083 List<Source> sources = <Source>[]; 2099 List<Source> sources = <Source>[];
2084 ChangeSet changeSet = new ChangeSet(); 2100 ChangeSet changeSet = new ChangeSet();
2085 for (int i = 0; i < sourceCount; i++) { 2101 for (int i = 0; i < sourceCount; i++) {
(...skipping 30 matching lines...) Expand all
2116 return source; 2132 return source;
2117 } 2133 }
2118 2134
2119 /** 2135 /**
2120 * Perform analysis tasks up to 512 times and assert that it was enough. 2136 * Perform analysis tasks up to 512 times and assert that it was enough.
2121 */ 2137 */
2122 void _analyzeAll_assertFinished([int maxIterations = 512]) { 2138 void _analyzeAll_assertFinished([int maxIterations = 512]) {
2123 for (int i = 0; i < maxIterations; i++) { 2139 for (int i = 0; i < maxIterations; i++) {
2124 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices; 2140 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices;
2125 if (notice == null) { 2141 if (notice == null) {
2126 return; 2142 bool inconsistent = context.validateCacheConsistency();
2143 if (!inconsistent) {
2144 return;
2145 }
2127 } 2146 }
2128 } 2147 }
2129 fail("performAnalysisTask failed to terminate after analyzing all sources"); 2148 fail("performAnalysisTask failed to terminate after analyzing all sources");
2130 } 2149 }
2131 2150
2132 void _changeSource(TestSource source, String contents) { 2151 void _changeSource(TestSource source, String contents) {
2133 source.setContents(contents); 2152 source.setContents(contents);
2134 ChangeSet changeSet = new ChangeSet(); 2153 ChangeSet changeSet = new ChangeSet();
2135 changeSet.changedSource(source); 2154 changeSet.changedSource(source);
2136 context.applyChanges(changeSet); 2155 context.applyChanges(changeSet);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 } 2522 }
2504 } 2523 }
2505 2524
2506 class _AnalysisContextImplTest_test_applyChanges_removeContainer 2525 class _AnalysisContextImplTest_test_applyChanges_removeContainer
2507 implements SourceContainer { 2526 implements SourceContainer {
2508 Source libB; 2527 Source libB;
2509 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); 2528 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB);
2510 @override 2529 @override
2511 bool contains(Source source) => source == libB; 2530 bool contains(Source source) => source == libB;
2512 } 2531 }
OLDNEW
« pkg/analyzer/lib/src/context/context.dart ('K') | « pkg/analyzer/lib/src/context/context.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698