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 engine.test_support; | 5 library engine.test_support; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; | 9 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
13 import 'package:analyzer/src/generated/java_core.dart'; | 13 import 'package:analyzer/src/generated/java_core.dart'; |
14 import 'package:analyzer/src/generated/java_engine.dart'; | 14 import 'package:analyzer/src/generated/java_engine.dart'; |
15 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:plugin/manager.dart'; |
| 17 import 'package:plugin/plugin.dart'; |
16 import 'package:unittest/unittest.dart'; | 18 import 'package:unittest/unittest.dart'; |
17 | 19 |
18 import 'resolver_test.dart'; | 20 import 'resolver_test.dart'; |
19 | 21 |
20 /** | 22 /** |
21 * The class `EngineTestCase` defines utility methods for making assertions. | 23 * The class `EngineTestCase` defines utility methods for making assertions. |
22 */ | 24 */ |
23 class EngineTestCase { | 25 class EngineTestCase { |
24 /** | 26 /** |
25 * Assert that the given collection has the same number of elements as the num
ber of specified | 27 * Assert that the given collection has the same number of elements as the num
ber of specified |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 MethodElement getMethod(InterfaceType type, String methodName) { | 86 MethodElement getMethod(InterfaceType type, String methodName) { |
85 for (MethodElement method in type.element.methods) { | 87 for (MethodElement method in type.element.methods) { |
86 if (method.name == methodName) { | 88 if (method.name == methodName) { |
87 return method; | 89 return method; |
88 } | 90 } |
89 } | 91 } |
90 fail("Could not find method named $methodName in ${type.displayName}"); | 92 fail("Could not find method named $methodName in ${type.displayName}"); |
91 return null; | 93 return null; |
92 } | 94 } |
93 | 95 |
94 void setUp() {} | 96 void setUp() { |
| 97 List<Plugin> plugins = <Plugin>[]; |
| 98 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 99 plugins.add(AnalysisEngine.instance.commandLinePlugin); |
| 100 plugins.add(AnalysisEngine.instance.optionsPlugin); |
| 101 new ExtensionManager().processPlugins(plugins); |
| 102 } |
95 | 103 |
96 void tearDown() {} | 104 void tearDown() {} |
97 | 105 |
98 /** | 106 /** |
99 * Assert that the given object is an instance of the expected class. | 107 * Assert that the given object is an instance of the expected class. |
100 * | 108 * |
101 * @param expectedClass the class that the object is expected to be an instanc
e of | 109 * @param expectedClass the class that the object is expected to be an instanc
e of |
102 * @param object the object being tested | 110 * @param object the object being tested |
103 * @return the object that was being tested | 111 * @return the object that was being tested |
104 * @throws Exception if the object is not an instance of the expected class | 112 * @throws Exception if the object is not an instance of the expected class |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 String _contents; | 558 String _contents; |
551 int _modificationStamp = 0; | 559 int _modificationStamp = 0; |
552 bool exists2 = true; | 560 bool exists2 = true; |
553 | 561 |
554 /** | 562 /** |
555 * A flag indicating whether an exception should be generated when an attempt | 563 * A flag indicating whether an exception should be generated when an attempt |
556 * is made to access the contents of this source. | 564 * is made to access the contents of this source. |
557 */ | 565 */ |
558 bool generateExceptionOnRead = false; | 566 bool generateExceptionOnRead = false; |
559 | 567 |
560 @override | |
561 int get modificationStamp => | |
562 generateExceptionOnRead ? -1 : _modificationStamp; | |
563 | |
564 /** | 568 /** |
565 * The number of times that the contents of this source have been requested. | 569 * The number of times that the contents of this source have been requested. |
566 */ | 570 */ |
567 int readCount = 0; | 571 int readCount = 0; |
568 | 572 |
569 TestSource([this._name = '/test.dart', this._contents]); | 573 TestSource([this._name = '/test.dart', this._contents]); |
570 | 574 |
571 TimestampedData<String> get contents { | 575 TimestampedData<String> get contents { |
572 readCount++; | 576 readCount++; |
573 if (generateExceptionOnRead) { | 577 if (generateExceptionOnRead) { |
574 String msg = "I/O Exception while getting the contents of " + _name; | 578 String msg = "I/O Exception while getting the contents of " + _name; |
575 throw new Exception(msg); | 579 throw new Exception(msg); |
576 } | 580 } |
577 return new TimestampedData<String>(0, _contents); | 581 return new TimestampedData<String>(0, _contents); |
578 } | 582 } |
579 | 583 |
580 String get encoding { | 584 String get encoding { |
581 throw new UnsupportedOperationException(); | 585 throw new UnsupportedOperationException(); |
582 } | 586 } |
583 | 587 |
584 String get fullName { | 588 String get fullName { |
585 return _name; | 589 return _name; |
586 } | 590 } |
587 | 591 |
588 int get hashCode => 0; | 592 int get hashCode => 0; |
| 593 |
589 bool get isInSystemLibrary { | 594 bool get isInSystemLibrary { |
590 return false; | 595 return false; |
591 } | 596 } |
592 | 597 |
| 598 @override |
| 599 int get modificationStamp => |
| 600 generateExceptionOnRead ? -1 : _modificationStamp; |
| 601 |
593 String get shortName { | 602 String get shortName { |
594 return _name; | 603 return _name; |
595 } | 604 } |
596 | 605 |
597 Uri get uri { | 606 Uri get uri { |
598 throw new UnsupportedOperationException(); | 607 throw new UnsupportedOperationException(); |
599 } | 608 } |
600 | 609 |
601 UriKind get uriKind { | 610 UriKind get uriKind { |
602 throw new UnsupportedOperationException(); | 611 throw new UnsupportedOperationException(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 if (other is TestSource) { | 662 if (other is TestSource) { |
654 return other.uri == uri; | 663 return other.uri == uri; |
655 } | 664 } |
656 return false; | 665 return false; |
657 } | 666 } |
658 | 667 |
659 Uri resolveRelativeUri(Uri uri) { | 668 Uri resolveRelativeUri(Uri uri) { |
660 return this.uri.resolveUri(uri); | 669 return this.uri.resolveUri(uri); |
661 } | 670 } |
662 } | 671 } |
OLD | NEW |