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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/driver_test.dart

Issue 2575353002: Another hermetic test for a case found in instrumentation logs. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
11 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 11 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
12 import 'package:analyzer/dart/element/element.dart'; 12 import 'package:analyzer/dart/element/element.dart';
13 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/error/error.dart'; 14 import 'package:analyzer/error/error.dart';
14 import 'package:analyzer/file_system/file_system.dart'; 15 import 'package:analyzer/file_system/file_system.dart';
15 import 'package:analyzer/file_system/memory_file_system.dart'; 16 import 'package:analyzer/file_system/memory_file_system.dart';
16 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 17 import 'package:analyzer/src/dart/analysis/byte_store.dart';
17 import 'package:analyzer/src/dart/analysis/driver.dart'; 18 import 'package:analyzer/src/dart/analysis/driver.dart';
18 import 'package:analyzer/src/dart/analysis/file_state.dart'; 19 import 'package:analyzer/src/dart/analysis/file_state.dart';
19 import 'package:analyzer/src/dart/analysis/status.dart'; 20 import 'package:analyzer/src/dart/analysis/status.dart';
20 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
21 import 'package:analyzer/src/error/codes.dart'; 22 import 'package:analyzer/src/error/codes.dart';
22 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; 23 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 997
997 // Once analysis is done, there is nothing to analyze. 998 // Once analysis is done, there is nothing to analyze.
998 await future; 999 await future;
999 expect(driver.hasFilesToAnalyze, isFalse); 1000 expect(driver.hasFilesToAnalyze, isFalse);
1000 1001
1001 // Request of referenced names is not analysis of a file. 1002 // Request of referenced names is not analysis of a file.
1002 driver.getFilesReferencingName('X'); 1003 driver.getFilesReferencingName('X');
1003 expect(driver.hasFilesToAnalyze, isFalse); 1004 expect(driver.hasFilesToAnalyze, isFalse);
1004 } 1005 }
1005 1006
1007 test_hermetic_modifyLibraryFile_resolvePart() async {
1008 var a = _p('/test/lib/a.dart');
1009 var b = _p('/test/lib/b.dart');
1010
1011 provider.newFile(
1012 a,
1013 r'''
1014 library a;
1015 part 'b.dart';
1016 class C {
1017 int foo;
1018 }
1019 ''');
1020 provider.newFile(
1021 b,
1022 r'''
1023 part of a;
1024 var c = new C();
1025 ''');
1026
1027 driver.addFile(a);
1028 driver.addFile(b);
1029
1030 await driver.getResult(b);
1031
1032 // Modify the library, but don't notify the driver.
1033 // The driver should use the previous library content and elements.
1034 provider.newFile(
1035 a,
1036 r'''
1037 library a;
1038 part 'b.dart';
1039 class C {
1040 int bar;
1041 }
1042 ''');
1043
1044 var result = await driver.getResult(b);
1045 var c = _getTopLevelVar(result.unit, 'c');
1046 var typeC = c.element.type as InterfaceType;
1047 // The class C has an old field 'foo', not the new 'bar'.
1048 expect(typeC.element.getField('foo'), isNotNull);
1049 expect(typeC.element.getField('bar'), isNull);
1050 }
1051
1052 test_hermetic_overlayOnly_part() async {
1053 var a = _p('/test/lib/a.dart');
1054 var b = _p('/test/lib/b.dart');
1055 contentOverlay[a] = r'''
1056 library a;
1057 part 'b.dart';
1058 class A {}
1059 var b = new B();
1060 ''';
1061 contentOverlay[b] = 'part of a; class B {}';
1062
1063 driver.addFile(a);
1064 driver.addFile(b);
1065
1066 AnalysisResult result = await driver.getResult(a);
1067 expect(result.errors, isEmpty);
1068 expect(_getTopLevelVarType(result.unit, 'b'), 'B');
1069 }
1070
1006 test_knownFiles() async { 1071 test_knownFiles() async {
1007 var a = _p('/test/lib/a.dart'); 1072 var a = _p('/test/lib/a.dart');
1008 var b = _p('/test/lib/b.dart'); 1073 var b = _p('/test/lib/b.dart');
1009 var c = _p('/test/lib/c.dart'); 1074 var c = _p('/test/lib/c.dart');
1010 1075
1011 provider.newFile( 1076 provider.newFile(
1012 a, 1077 a,
1013 r''' 1078 r'''
1014 import 'b.dart'; 1079 import 'b.dart';
1015 '''); 1080 ''');
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1221
1157 driver.addFile(c); 1222 driver.addFile(c);
1158 1223
1159 // There is no library which c.dart is a part of, so it has unresolved 1224 // There is no library which c.dart is a part of, so it has unresolved
1160 // A and B references. 1225 // A and B references.
1161 AnalysisResult result = await driver.getResult(c); 1226 AnalysisResult result = await driver.getResult(c);
1162 expect(result.errors, isNotEmpty); 1227 expect(result.errors, isNotEmpty);
1163 expect(result.unit, isNotNull); 1228 expect(result.unit, isNotNull);
1164 } 1229 }
1165 1230
1166 test_part_getResult_overlayOnly() async {
1167 var a = _p('/test/lib/a.dart');
1168 var b = _p('/test/lib/b.dart');
1169 contentOverlay[a] = r'''
1170 library a;
1171 part 'b.dart';
1172 class A {}
1173 var b = new B();
1174 ''';
1175 contentOverlay[b] = 'part of a; class B {}';
1176
1177 driver.addFile(a);
1178 driver.addFile(b);
1179
1180 AnalysisResult result = await driver.getResult(a);
1181 expect(result.errors, isEmpty);
1182 expect(_getTopLevelVarType(result.unit, 'b'), 'B');
1183 }
1184
1185 test_part_results_afterLibrary() async { 1231 test_part_results_afterLibrary() async {
1186 var a = _p('/test/lib/a.dart'); 1232 var a = _p('/test/lib/a.dart');
1187 var b = _p('/test/lib/b.dart'); 1233 var b = _p('/test/lib/b.dart');
1188 var c = _p('/test/lib/c.dart'); 1234 var c = _p('/test/lib/c.dart');
1189 provider.newFile( 1235 provider.newFile(
1190 a, 1236 a,
1191 r''' 1237 r'''
1192 library a; 1238 library a;
1193 import 'b.dart'; 1239 import 'b.dart';
1194 part 'c.dart'; 1240 part 'c.dart';
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 String _p(String path) => provider.convertPath(path); 1645 String _p(String path) => provider.convertPath(path);
1600 1646
1601 Future<Null> _waitForIdle() async { 1647 Future<Null> _waitForIdle() async {
1602 await idleStatusMonitor.signal; 1648 await idleStatusMonitor.signal;
1603 } 1649 }
1604 1650
1605 static String _md5(String content) { 1651 static String _md5(String content) {
1606 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 1652 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
1607 } 1653 }
1608 } 1654 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698