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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 2232863004: Create new error message for missing generated files (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after
3537 computeResult(target, RESOLVED_UNIT7, 3537 computeResult(target, RESOLVED_UNIT7,
3538 matcher: isPartiallyResolveUnitReferencesTask); 3538 matcher: isPartiallyResolveUnitReferencesTask);
3539 CompilationUnit unit = outputs[RESOLVED_UNIT7]; 3539 CompilationUnit unit = outputs[RESOLVED_UNIT7];
3540 NodeList<CompilationUnitMember> declarations = unit.declarations; 3540 NodeList<CompilationUnitMember> declarations = unit.declarations;
3541 3541
3542 void expectReference(BlockFunctionBody body, bool isResolved) { 3542 void expectReference(BlockFunctionBody body, bool isResolved) {
3543 ExpressionStatement statement = body.block.statements[0]; 3543 ExpressionStatement statement = body.block.statements[0];
3544 SimpleIdentifier reference = statement.expression; 3544 SimpleIdentifier reference = statement.expression;
3545 expect(reference.staticElement, isResolved ? isNotNull : isNull); 3545 expect(reference.staticElement, isResolved ? isNotNull : isNull);
3546 } 3546 }
3547
3547 // 3548 //
3548 // The reference to 'A' in 'f1' should not be resolved. 3549 // The reference to 'A' in 'f1' should not be resolved.
3549 // 3550 //
3550 FunctionDeclaration f1 = declarations[1]; 3551 FunctionDeclaration f1 = declarations[1];
3551 expectReference(f1.functionExpression.body, false); 3552 expectReference(f1.functionExpression.body, false);
3552 // 3553 //
3553 // The references to 'A' in 'f2' should be resolved. 3554 // The references to 'A' in 'f2' should be resolved.
3554 // 3555 //
3555 TopLevelVariableDeclaration f2 = declarations[2]; 3556 TopLevelVariableDeclaration f2 = declarations[2];
3556 FunctionExpression expression2 = f2.variables.variables[0].initializer; 3557 FunctionExpression expression2 = f2.variables.variables[0].initializer;
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
5675 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 5676 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
5676 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); 5677 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
5677 // validate 5678 // validate
5678 _fillErrorListener(VERIFY_ERRORS); 5679 _fillErrorListener(VERIFY_ERRORS);
5679 errorListener.assertErrorsWithCodes(<ErrorCode>[ 5680 errorListener.assertErrorsWithCodes(<ErrorCode>[
5680 CompileTimeErrorCode.URI_DOES_NOT_EXIST, 5681 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
5681 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE 5682 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
5682 ]); 5683 ]);
5683 } 5684 }
5684 5685
5685 test_perform_directiveError() { 5686 test_perform_directiveError_generated() {
5686 Source source = newSource( 5687 Source source = newSource(
5687 '/test.dart', 5688 '/test.dart',
5688 ''' 5689 '''
5690 import 'generated-file.g.dart';
5691 ''');
5692 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
5693 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
5694 // validate
5695 _fillErrorListener(VERIFY_ERRORS);
5696 errorListener.assertErrorsWithCodes(
5697 <ErrorCode>[CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED]);
5698 }
5699
5700 test_perform_directiveError_nonGenerated() {
5701 Source source = newSource(
5702 '/test.dart',
5703 '''
5689 import 'no-such-file.dart'; 5704 import 'no-such-file.dart';
5690 '''); 5705 ''');
5691 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 5706 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
5692 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); 5707 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask);
5693 // validate 5708 // validate
5694 _fillErrorListener(VERIFY_ERRORS); 5709 _fillErrorListener(VERIFY_ERRORS);
5695 errorListener.assertErrorsWithCodes( 5710 errorListener.assertErrorsWithCodes(
5696 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5711 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
5697 } 5712 }
5698 5713
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5778 } 5793 }
5779 5794
5780 List<dynamic> computeLibraryResults( 5795 List<dynamic> computeLibraryResults(
5781 List<Source> sources, ResultDescriptor result, 5796 List<Source> sources, ResultDescriptor result,
5782 {isInstanceOf matcher: null}) { 5797 {isInstanceOf matcher: null}) {
5783 dynamic compute(Source source) { 5798 dynamic compute(Source source) {
5784 computeResult(new LibrarySpecificUnit(source, source), result, 5799 computeResult(new LibrarySpecificUnit(source, source), result,
5785 matcher: matcher); 5800 matcher: matcher);
5786 return outputs[result]; 5801 return outputs[result];
5787 } 5802 }
5803
5788 return sources.map(compute).toList(); 5804 return sources.map(compute).toList();
5789 } 5805 }
5790 5806
5791 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( 5807 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap(
5792 List<Source> sources, ResultDescriptor result, 5808 List<Source> sources, ResultDescriptor result,
5793 {isInstanceOf matcher: null}) { 5809 {isInstanceOf matcher: null}) {
5794 Map<ResultDescriptor, dynamic> compute(Source source) { 5810 Map<ResultDescriptor, dynamic> compute(Source source) {
5795 computeResult(source, result, matcher: matcher); 5811 computeResult(source, result, matcher: matcher);
5796 return outputs; 5812 return outputs;
5797 } 5813 }
5814
5798 return sources.map(compute).toList(); 5815 return sources.map(compute).toList();
5799 } 5816 }
5800 5817
5801 /** 5818 /**
5802 * Create a script object with a single fragment containing the given 5819 * Create a script object with a single fragment containing the given
5803 * [scriptContent]. 5820 * [scriptContent].
5804 */ 5821 */
5805 DartScript createScript(String scriptContent) { 5822 DartScript createScript(String scriptContent) {
5806 String htmlContent = ''' 5823 String htmlContent = '''
5807 <!DOCTYPE html> 5824 <!DOCTYPE html>
(...skipping 27 matching lines...) Expand all
5835 /** 5852 /**
5836 * Fill [errorListener] with [result] errors in the current [task]. 5853 * Fill [errorListener] with [result] errors in the current [task].
5837 */ 5854 */
5838 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 5855 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
5839 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; 5856 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
5840 expect(errors, isNotNull, reason: result.name); 5857 expect(errors, isNotNull, reason: result.name);
5841 errorListener = new GatheringErrorListener(); 5858 errorListener = new GatheringErrorListener();
5842 errorListener.addAll(errors); 5859 errorListener.addAll(errors);
5843 } 5860 }
5844 } 5861 }
OLDNEW
« pkg/analyzer/lib/src/task/dart.dart ('K') | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698