| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // Now remove 'a'. | 328 // Now remove 'a'. |
| 329 driver.removeFile(a); | 329 driver.removeFile(a); |
| 330 | 330 |
| 331 await _waitForIdle(); | 331 await _waitForIdle(); |
| 332 | 332 |
| 333 // Only 'b' has been analyzed, because 'a' was removed before we started. | 333 // Only 'b' has been analyzed, because 'a' was removed before we started. |
| 334 expect(allResults, hasLength(1)); | 334 expect(allResults, hasLength(1)); |
| 335 expect(allResults[0].path, b); | 335 expect(allResults[0].path, b); |
| 336 } | 336 } |
| 337 | 337 |
| 338 test_cachedPriorityResults() async { |
| 339 var a = _p('/test/bin/a.dart'); |
| 340 provider.newFile(a, 'var a = 1;'); |
| 341 |
| 342 driver.priorityFiles = [a]; |
| 343 |
| 344 AnalysisResult result1 = await driver.getResult(a); |
| 345 expect(driver.test.priorityResults, containsPair(a, result1)); |
| 346 |
| 347 AnalysisResult result2 = await driver.getResult(a); |
| 348 expect(result2, same(result1)); |
| 349 } |
| 350 |
| 351 test_cachedPriorityResults_flush_onAnyFileChange() async { |
| 352 var a = _p('/test/bin/a.dart'); |
| 353 var b = _p('/test/bin/b.dart'); |
| 354 provider.newFile(a, 'var a = 1;'); |
| 355 provider.newFile(a, 'var b = 2;'); |
| 356 |
| 357 driver.priorityFiles = [a]; |
| 358 |
| 359 AnalysisResult result1 = await driver.getResult(a); |
| 360 expect(driver.test.priorityResults, containsPair(a, result1)); |
| 361 |
| 362 // Change a file. |
| 363 // The cache is flushed. |
| 364 driver.changeFile(a); |
| 365 expect(driver.test.priorityResults, isEmpty); |
| 366 AnalysisResult result2 = await driver.getResult(a); |
| 367 expect(driver.test.priorityResults, containsPair(a, result2)); |
| 368 |
| 369 // Add a file. |
| 370 // The cache is flushed. |
| 371 driver.addFile(b); |
| 372 expect(driver.test.priorityResults, isEmpty); |
| 373 AnalysisResult result3 = await driver.getResult(a); |
| 374 expect(driver.test.priorityResults, containsPair(a, result3)); |
| 375 |
| 376 // Remove a file. |
| 377 // The cache is flushed. |
| 378 driver.removeFile(b); |
| 379 expect(driver.test.priorityResults, isEmpty); |
| 380 } |
| 381 |
| 382 test_cachedPriorityResults_flush_onPrioritySetChange() async { |
| 383 var a = _p('/test/bin/a.dart'); |
| 384 var b = _p('/test/bin/b.dart'); |
| 385 provider.newFile(a, 'var a = 1;'); |
| 386 provider.newFile(a, 'var b = 2;'); |
| 387 |
| 388 driver.priorityFiles = [a]; |
| 389 |
| 390 AnalysisResult result1 = await driver.getResult(a); |
| 391 expect(driver.test.priorityResults, hasLength(1)); |
| 392 expect(driver.test.priorityResults, containsPair(a, result1)); |
| 393 |
| 394 // Make "a" and "b" priority. |
| 395 // We still have the result for "a" cached. |
| 396 driver.priorityFiles = [a, b]; |
| 397 expect(driver.test.priorityResults, hasLength(1)); |
| 398 expect(driver.test.priorityResults, containsPair(a, result1)); |
| 399 |
| 400 // Get the result for "b". |
| 401 AnalysisResult result2 = await driver.getResult(b); |
| 402 expect(driver.test.priorityResults, hasLength(2)); |
| 403 expect(driver.test.priorityResults, containsPair(a, result1)); |
| 404 expect(driver.test.priorityResults, containsPair(b, result2)); |
| 405 |
| 406 // Only "b" is priority. |
| 407 // The result for "a" is flushed. |
| 408 driver.priorityFiles = [b]; |
| 409 expect(driver.test.priorityResults, hasLength(1)); |
| 410 expect(driver.test.priorityResults, containsPair(b, result2)); |
| 411 } |
| 412 |
| 413 test_cachedPriorityResults_notPriority() async { |
| 414 var a = _p('/test/bin/a.dart'); |
| 415 provider.newFile(a, 'var a = 1;'); |
| 416 |
| 417 AnalysisResult result1 = await driver.getResult(a); |
| 418 expect(driver.test.priorityResults, isEmpty); |
| 419 |
| 420 // The file is not priority, so its result is not cached. |
| 421 AnalysisResult result2 = await driver.getResult(a); |
| 422 expect(result2, isNot(same(result1))); |
| 423 } |
| 424 |
| 338 test_changeFile_implicitlyAnalyzed() async { | 425 test_changeFile_implicitlyAnalyzed() async { |
| 339 var a = _p('/test/lib/a.dart'); | 426 var a = _p('/test/lib/a.dart'); |
| 340 var b = _p('/test/lib/b.dart'); | 427 var b = _p('/test/lib/b.dart'); |
| 341 provider.newFile( | 428 provider.newFile( |
| 342 a, | 429 a, |
| 343 r''' | 430 r''' |
| 344 import 'b.dart'; | 431 import 'b.dart'; |
| 345 var A = B; | 432 var A = B; |
| 346 '''); | 433 '''); |
| 347 provider.newFile(b, 'var B = 1;'); | 434 provider.newFile(b, 'var B = 1;'); |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 expect(unitElement.source.fullName, testFile); | 1103 expect(unitElement.source.fullName, testFile); |
| 1017 expect(unitElement.functions.map((c) => c.name), | 1104 expect(unitElement.functions.map((c) => c.name), |
| 1018 unorderedEquals(['foo', 'main'])); | 1105 unorderedEquals(['foo', 'main'])); |
| 1019 } | 1106 } |
| 1020 | 1107 |
| 1021 test_hasFilesToAnalyze() async { | 1108 test_hasFilesToAnalyze() async { |
| 1022 // No files yet, nothing to analyze. | 1109 // No files yet, nothing to analyze. |
| 1023 expect(driver.hasFilesToAnalyze, isFalse); | 1110 expect(driver.hasFilesToAnalyze, isFalse); |
| 1024 | 1111 |
| 1025 // Add a new file, it should be analyzed. | 1112 // Add a new file, it should be analyzed. |
| 1026 addTestFile('main() {}', priority: true); | 1113 addTestFile('main() {}', priority: false); |
| 1027 expect(driver.hasFilesToAnalyze, isTrue); | 1114 expect(driver.hasFilesToAnalyze, isTrue); |
| 1028 | 1115 |
| 1029 // Wait for idle, nothing to do. | 1116 // Wait for idle, nothing to do. |
| 1030 await _waitForIdle(); | 1117 await _waitForIdle(); |
| 1031 expect(driver.hasFilesToAnalyze, isFalse); | 1118 expect(driver.hasFilesToAnalyze, isFalse); |
| 1032 | 1119 |
| 1033 // Ask to analyze the file, so there is a file to analyze. | 1120 // Ask to analyze the file, so there is a file to analyze. |
| 1034 Future<AnalysisResult> future = driver.getResult(testFile); | 1121 Future<AnalysisResult> future = driver.getResult(testFile); |
| 1035 expect(driver.hasFilesToAnalyze, isTrue); | 1122 expect(driver.hasFilesToAnalyze, isTrue); |
| 1036 | 1123 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 String _p(String path) => provider.convertPath(path); | 1777 String _p(String path) => provider.convertPath(path); |
| 1691 | 1778 |
| 1692 Future<Null> _waitForIdle() async { | 1779 Future<Null> _waitForIdle() async { |
| 1693 await idleStatusMonitor.signal; | 1780 await idleStatusMonitor.signal; |
| 1694 } | 1781 } |
| 1695 | 1782 |
| 1696 static String _md5(String content) { | 1783 static String _md5(String content) { |
| 1697 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1784 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 1698 } | 1785 } |
| 1699 } | 1786 } |
| OLD | NEW |