| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.driver; | 5 library analyzer.test.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
| 22 import 'package:analyzer/src/error/codes.dart'; | 22 import 'package:analyzer/src/error/codes.dart'; |
| 23 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; | 23 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; |
| 24 import 'package:analyzer/src/generated/sdk.dart'; | 24 import 'package:analyzer/src/generated/sdk.dart'; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/src/summary/idl.dart'; | 26 import 'package:analyzer/src/summary/idl.dart'; |
| 27 import 'package:convert/convert.dart'; | 27 import 'package:convert/convert.dart'; |
| 28 import 'package:crypto/crypto.dart'; | 28 import 'package:crypto/crypto.dart'; |
| 29 import 'package:test/test.dart'; | 29 import 'package:test/test.dart'; |
| 30 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 30 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 31 import 'package:typed_mock/typed_mock.dart'; |
| 31 | 32 |
| 32 import '../../context/mock_sdk.dart'; | 33 import '../../context/mock_sdk.dart'; |
| 33 import 'base.dart'; | 34 import 'base.dart'; |
| 34 | 35 |
| 35 main() { | 36 main() { |
| 36 defineReflectiveSuite(() { | 37 defineReflectiveSuite(() { |
| 37 defineReflectiveTests(AnalysisDriverTest); | 38 defineReflectiveTests(AnalysisDriverTest); |
| 38 defineReflectiveTests(AnalysisDriverSchedulerTest); | 39 defineReflectiveTests(AnalysisDriverSchedulerTest); |
| 39 }); | 40 }); |
| 40 } | 41 } |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 library lib; | 627 library lib; |
| 627 part 'foo.dart'; | 628 part 'foo.dart'; |
| 628 '''); | 629 '''); |
| 629 | 630 |
| 630 AnalysisResult result = await driver.getResult(testFile); | 631 AnalysisResult result = await driver.getResult(testFile); |
| 631 List<AnalysisError> errors = result.errors; | 632 List<AnalysisError> errors = result.errors; |
| 632 expect(errors, hasLength(1)); | 633 expect(errors, hasLength(1)); |
| 633 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST); | 634 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST); |
| 634 } | 635 } |
| 635 | 636 |
| 637 test_generatedFile() async { |
| 638 Uri uri = Uri.parse('package:aaa/foo.dart'); |
| 639 String templatePath = _p('/aaa/lib/foo.dart'); |
| 640 String generatedPath = _p('/generated/aaa/lib/foo.dart'); |
| 641 |
| 642 provider.newFile( |
| 643 templatePath, |
| 644 r''' |
| 645 a() {} |
| 646 b() {} |
| 647 '''); |
| 648 |
| 649 provider.newFile( |
| 650 generatedPath, |
| 651 r''' |
| 652 aaa() {} |
| 653 bbb() {} |
| 654 '''); |
| 655 |
| 656 Source generatedSource = new _SourceMock(); |
| 657 when(generatedSource.uri).thenReturn(uri); |
| 658 when(generatedSource.fullName).thenReturn(generatedPath); |
| 659 |
| 660 when(generatedUriResolver.resolveAbsolute(uri, uri)) |
| 661 .thenReturn(generatedSource); |
| 662 when(generatedUriResolver.restoreAbsolute(anyObject)) |
| 663 .thenInvoke((Source source) { |
| 664 String path = source.fullName; |
| 665 if (path == templatePath || path == generatedPath) { |
| 666 return uri; |
| 667 } else { |
| 668 return null; |
| 669 } |
| 670 }); |
| 671 |
| 672 driver.addFile(templatePath); |
| 673 |
| 674 await driver.waitForIdle(); |
| 675 expect(allExceptions, isEmpty); |
| 676 expect(allResults, isEmpty); |
| 677 |
| 678 var result = await driver.getResult(templatePath); |
| 679 expect(result, isNull); |
| 680 expect(allExceptions, isEmpty); |
| 681 expect(allResults, isEmpty); |
| 682 |
| 683 driver.priorityFiles = [templatePath]; |
| 684 driver.changeFile(templatePath); |
| 685 await driver.waitForIdle(); |
| 686 expect(allExceptions, isEmpty); |
| 687 expect(allResults, isEmpty); |
| 688 |
| 689 expect(driver.knownFiles, isNot(contains(templatePath))); |
| 690 } |
| 691 |
| 636 test_getFilesReferencingName() async { | 692 test_getFilesReferencingName() async { |
| 637 var a = _p('/test/bin/a.dart'); | 693 var a = _p('/test/bin/a.dart'); |
| 638 var b = _p('/test/bin/b.dart'); | 694 var b = _p('/test/bin/b.dart'); |
| 639 var c = _p('/test/bin/c.dart'); | 695 var c = _p('/test/bin/c.dart'); |
| 640 var d = _p('/test/bin/d.dart'); | 696 var d = _p('/test/bin/d.dart'); |
| 641 var e = _p('/test/bin/e.dart'); | 697 var e = _p('/test/bin/e.dart'); |
| 642 | 698 |
| 643 provider.newFile(a, 'class A {}'); | 699 provider.newFile(a, 'class A {}'); |
| 644 provider.newFile(b, "import 'a.dart'; A a;"); | 700 provider.newFile(b, "import 'a.dart'; A a;"); |
| 645 provider.newFile(c, "import 'a.dart'; var a = new A();"); | 701 provider.newFile(c, "import 'a.dart'; var a = new A();"); |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 | 1885 |
| 1830 /** | 1886 /** |
| 1831 * Return the [provider] specific path for the given Posix [path]. | 1887 * Return the [provider] specific path for the given Posix [path]. |
| 1832 */ | 1888 */ |
| 1833 String _p(String path) => provider.convertPath(path); | 1889 String _p(String path) => provider.convertPath(path); |
| 1834 | 1890 |
| 1835 static String _md5(String content) { | 1891 static String _md5(String content) { |
| 1836 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1892 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 1837 } | 1893 } |
| 1838 } | 1894 } |
| 1895 |
| 1896 class _SourceMock extends TypedMock implements Source {} |
| OLD | NEW |