| OLD | NEW |
| 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/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 import 'abstract_context.dart'; | 47 import 'abstract_context.dart'; |
| 48 | 48 |
| 49 main() { | 49 main() { |
| 50 groupSep = ' | '; | 50 groupSep = ' | '; |
| 51 runReflectiveTests(AnalysisContextImplTest); | 51 runReflectiveTests(AnalysisContextImplTest); |
| 52 runReflectiveTests(LimitedInvalidateTest); | 52 runReflectiveTests(LimitedInvalidateTest); |
| 53 } | 53 } |
| 54 | 54 |
| 55 @reflectiveTest | 55 @reflectiveTest |
| 56 class AnalysisContextImplTest extends AbstractContextTest { | 56 class AnalysisContextImplTest extends AbstractContextTest { |
| 57 void fail_applyChanges_empty() { | 57 void test_applyChanges_empty() { |
| 58 context.applyChanges(new ChangeSet()); | 58 context.applyChanges(new ChangeSet()); |
| 59 expect(context.performAnalysisTask().changeNotices, isNull); | 59 expect(context.performAnalysisTask().changeNotices, isNull); |
| 60 // This test appears to be flaky. If it is named "test_" it fails, if it's | |
| 61 // named "fail_" it doesn't fail. I'm guessing that it's dependent on | |
| 62 // whether some other test is run. | |
| 63 fail('Should have failed'); | |
| 64 } | |
| 65 | |
| 66 void fail_extractContext() { | |
| 67 fail("Implement this"); | |
| 68 } | |
| 69 | |
| 70 void fail_mergeContext() { | |
| 71 fail("Implement this"); | |
| 72 } | 60 } |
| 73 | 61 |
| 74 void fail_parseHtmlUnit_resolveDirectives() { | 62 void fail_parseHtmlUnit_resolveDirectives() { |
| 75 Source libSource = addSource("/lib.dart", r''' | 63 Source libSource = addSource("/lib.dart", r''' |
| 76 library lib; | 64 library lib; |
| 77 class ClassA {}'''); | 65 class ClassA {}'''); |
| 78 Source source = addSource("/lib.html", r''' | 66 Source source = addSource("/lib.html", r''' |
| 79 <!DOCTYPE html> | 67 <!DOCTYPE html> |
| 80 <html> | 68 <html> |
| 81 <head> | 69 <head> |
| 82 <script type='application/dart'> | 70 <script type='application/dart'> |
| 83 import 'lib.dart'; | 71 import 'lib.dart'; |
| 84 ClassA v = null; | 72 ClassA v = null; |
| 85 </script> | 73 </script> |
| 86 </head> | 74 </head> |
| 87 <body> | 75 <body> |
| 88 </body> | 76 </body> |
| 89 </html>'''); | 77 </html>'''); |
| 90 // TODO(brianwilkerson) Rewrite this. We need a way to get the AST for the | 78 // TODO(brianwilkerson) Rewrite this. We need a way to get the AST for the |
| 91 // script. | 79 // script. |
| 80 // Document document = context.parseHtmlDocument(source); |
| 81 // expect(document, isNotNull); |
| 82 // List<DartScript> scripts = context.computeResult(source, DART_SCRIPTS); |
| 83 // expect(scripts, hasLength(1)); |
| 84 // CompilationUnit unit = context.computeResult(scripts[0], PARSED_AST); |
| 85 // ImportDirective importNode = unit.directives[0] as ImportDirective; |
| 86 // expect(importNode.uriContent, isNotNull); |
| 87 // expect(importNode.source, libSource); |
| 88 |
| 92 ht.HtmlUnit unit = context.parseHtmlUnit(source); | 89 ht.HtmlUnit unit = context.parseHtmlUnit(source); |
| 93 expect(unit, isNotNull); | 90 expect(unit, isNotNull); |
| 94 // import directive should be resolved | 91 // import directive should be resolved |
| 95 ht.XmlTagNode htmlNode = unit.tagNodes[0]; | 92 ht.XmlTagNode htmlNode = unit.tagNodes[0]; |
| 96 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; | 93 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; |
| 97 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; | 94 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; |
| 98 CompilationUnit script = scriptNode.script; | 95 CompilationUnit script = scriptNode.script; |
| 99 ImportDirective importNode = script.directives[0] as ImportDirective; | 96 ImportDirective importNode = script.directives[0] as ImportDirective; |
| 100 expect(importNode.uriContent, isNotNull); | 97 expect(importNode.uriContent, isNotNull); |
| 101 expect(importNode.source, libSource); | 98 expect(importNode.source, libSource); |
| 102 } | 99 } |
| 103 | 100 |
| 104 void fail_performAnalysisTask_getContentException_dart() { | 101 void test_performAnalysisTask_getContentException_dart() { |
| 105 Source source = _addSourceWithException('test.dart'); | 102 Source source = _addSourceWithException('test.dart'); |
| 106 // prepare errors | 103 // prepare errors |
| 107 _analyzeAll_assertFinished(); | 104 _analyzeAll_assertFinished(); |
| 108 List<AnalysisError> errors = context.getErrors(source).errors; | 105 List<AnalysisError> errors = context.getErrors(source).errors; |
| 109 // validate errors | 106 // validate errors |
| 110 expect(errors, hasLength(1)); | 107 expect(errors, hasLength(1)); |
| 111 AnalysisError error = errors[0]; | 108 AnalysisError error = errors[0]; |
| 112 expect(error.source, same(source)); | 109 expect(error.source, same(source)); |
| 113 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); | 110 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); |
| 114 } | 111 } |
| 115 | 112 |
| 116 void fail_performAnalysisTask_getContentException_html() { | 113 void test_performAnalysisTask_getContentException_html() { |
| 117 Source source = _addSourceWithException('test.html'); | 114 Source source = _addSourceWithException('test.html'); |
| 118 // prepare errors | 115 // prepare errors |
| 119 _analyzeAll_assertFinished(); | 116 _analyzeAll_assertFinished(); |
| 120 List<AnalysisError> errors = context.getErrors(source).errors; | 117 List<AnalysisError> errors = context.getErrors(source).errors; |
| 121 // validate errors | 118 // validate errors |
| 122 expect(errors, hasLength(1)); | 119 expect(errors, hasLength(1)); |
| 123 AnalysisError error = errors[0]; | 120 AnalysisError error = errors[0]; |
| 124 expect(error.source, same(source)); | 121 expect(error.source, same(source)); |
| 125 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); | 122 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); |
| 126 } | 123 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 isTrue, reason: "htmlSource doesn't have errors"); | 139 isTrue, reason: "htmlSource doesn't have errors"); |
| 143 // remove libB.dart content and analyze | 140 // remove libB.dart content and analyze |
| 144 context.setContents(libBSource, null); | 141 context.setContents(libBSource, null); |
| 145 _analyzeAll_assertFinished(); | 142 _analyzeAll_assertFinished(); |
| 146 context.computeErrors(htmlSource); | 143 context.computeErrors(htmlSource); |
| 147 AnalysisErrorInfo errors = context.getErrors(htmlSource); | 144 AnalysisErrorInfo errors = context.getErrors(htmlSource); |
| 148 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, | 145 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, |
| 149 reason: "htmlSource has an error"); | 146 reason: "htmlSource has an error"); |
| 150 } | 147 } |
| 151 | 148 |
| 152 void fail_performAnalysisTask_IOException() { | 149 void test_performAnalysisTask_IOException() { |
| 153 TestSource source = _addSourceWithException2("/test.dart", "library test;"); | 150 TestSource source = _addSourceWithException2("/test.dart", "library test;"); |
| 154 int oldTimestamp = context.getModificationStamp(source); | |
| 155 source.generateExceptionOnRead = false; | 151 source.generateExceptionOnRead = false; |
| 156 _analyzeAll_assertFinished(); | 152 _analyzeAll_assertFinished(); |
| 157 expect(source.readCount, 1); | 153 expect(source.readCount, 1); |
| 154 _changeSource(source, ""); |
| 158 source.generateExceptionOnRead = true; | 155 source.generateExceptionOnRead = true; |
| 159 do { | |
| 160 _changeSource(source, ""); | |
| 161 // Ensure that the timestamp differs, | |
| 162 // so that analysis engine notices the change | |
| 163 } while (oldTimestamp == context.getModificationStamp(source)); | |
| 164 _analyzeAll_assertFinished(); | 156 _analyzeAll_assertFinished(); |
| 165 expect(source.readCount, 2); | 157 expect(source.readCount, 3); |
| 166 } | 158 } |
| 167 | 159 |
| 168 void fail_recordLibraryElements() { | 160 void fail_recordLibraryElements() { |
| 169 fail("Implement this"); | 161 fail("Implement this"); |
| 170 } | 162 } |
| 171 | 163 |
| 172 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() { | 164 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() { |
| 173 AnalysisOptionsImpl options = | 165 AnalysisOptionsImpl options = |
| 174 new AnalysisOptionsImpl.from(context.analysisOptions); | 166 new AnalysisOptionsImpl.from(context.analysisOptions); |
| 175 List<Source> sources = new List<Source>(); | 167 List<Source> sources = new List<Source>(); |
| (...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2213 } | 2205 } |
| 2214 } | 2206 } |
| 2215 | 2207 |
| 2216 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2208 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 2217 implements SourceContainer { | 2209 implements SourceContainer { |
| 2218 Source libB; | 2210 Source libB; |
| 2219 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2211 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 2220 @override | 2212 @override |
| 2221 bool contains(Source source) => source == libB; | 2213 bool contains(Source source) => source == libB; |
| 2222 } | 2214 } |
| OLD | NEW |