| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 { | 355 { |
| 356 AnalysisResult ar = allResults.firstWhere((r) => r.path == a); | 356 AnalysisResult ar = allResults.firstWhere((r) => r.path == a); |
| 357 expect(_getTopLevelVarType(ar.unit, 'A'), 'int'); | 357 expect(_getTopLevelVarType(ar.unit, 'A'), 'int'); |
| 358 } | 358 } |
| 359 allResults.clear(); | 359 allResults.clear(); |
| 360 | 360 |
| 361 // Change "b" and notify. | 361 // Change "b" and notify. |
| 362 provider.updateFile(b, 'var B = 1.2;'); | 362 provider.updateFile(b, 'var B = 1.2;'); |
| 363 driver.changeFile(b); | 363 driver.changeFile(b); |
| 364 | 364 |
| 365 // "b" is not an added file, so it is not scheduled for analysis. |
| 366 expect(driver.test.filesToAnalyze, isEmpty); |
| 367 |
| 365 // While "b" is not analyzed explicitly, it is analyzed implicitly. | 368 // While "b" is not analyzed explicitly, it is analyzed implicitly. |
| 366 // The change causes "a" to be reanalyzed. | 369 // The change causes "a" to be reanalyzed. |
| 367 await _waitForIdle(); | 370 await _waitForIdle(); |
| 368 expect(allResults, hasLength(1)); | 371 expect(allResults, hasLength(1)); |
| 369 { | 372 { |
| 370 AnalysisResult ar = allResults.firstWhere((r) => r.path == a); | 373 AnalysisResult ar = allResults.firstWhere((r) => r.path == a); |
| 371 expect(_getTopLevelVarType(ar.unit, 'A'), 'double'); | 374 expect(_getTopLevelVarType(ar.unit, 'A'), 'double'); |
| 372 } | 375 } |
| 373 } | 376 } |
| 374 | 377 |
| 378 test_changeFile_notUsed() async { |
| 379 var a = _p('/test/lib/a.dart'); |
| 380 var b = _p('/other/b.dart'); |
| 381 provider.newFile(a, ''); |
| 382 provider.newFile(b, 'class B1 {}'); |
| 383 |
| 384 driver.addFile(a); |
| 385 |
| 386 await _waitForIdle(); |
| 387 allResults.clear(); |
| 388 |
| 389 // Change "b" and notify. |
| 390 // Nothing depends on "b", so nothing is analyzed. |
| 391 provider.updateFile(b, 'class B2 {}'); |
| 392 driver.changeFile(b); |
| 393 await _waitForIdle(); |
| 394 expect(allResults, isEmpty); |
| 395 |
| 396 // This should not add "b" to the file state. |
| 397 expect(driver.fsState.knownFilePaths, isNot(contains(b))); |
| 398 } |
| 399 |
| 375 test_changeFile_selfConsistent() async { | 400 test_changeFile_selfConsistent() async { |
| 376 var a = _p('/test/lib/a.dart'); | 401 var a = _p('/test/lib/a.dart'); |
| 377 var b = _p('/test/lib/b.dart'); | 402 var b = _p('/test/lib/b.dart'); |
| 378 provider.newFile( | 403 provider.newFile( |
| 379 a, | 404 a, |
| 380 r''' | 405 r''' |
| 381 import 'b.dart'; | 406 import 'b.dart'; |
| 382 var A1 = 1; | 407 var A1 = 1; |
| 383 var A2 = B1; | 408 var A2 = B1; |
| 384 '''); | 409 '''); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 allResults.clear(); | 473 allResults.clear(); |
| 449 provider.updateFile(testFile, 'var V = 1.2'); | 474 provider.updateFile(testFile, 'var V = 1.2'); |
| 450 | 475 |
| 451 // No new results. | 476 // No new results. |
| 452 await pumpEventQueue(); | 477 await pumpEventQueue(); |
| 453 expect(allResults, isEmpty); | 478 expect(allResults, isEmpty); |
| 454 | 479 |
| 455 // Notify the driver about the change. | 480 // Notify the driver about the change. |
| 456 driver.changeFile(testFile); | 481 driver.changeFile(testFile); |
| 457 | 482 |
| 483 // The file was added, so it is scheduled for analysis. |
| 484 expect(driver.test.filesToAnalyze, contains(testFile)); |
| 485 |
| 458 // We get a new result. | 486 // We get a new result. |
| 459 { | 487 { |
| 460 await _waitForIdle(); | 488 await _waitForIdle(); |
| 461 expect(allResults, hasLength(1)); | 489 expect(allResults, hasLength(1)); |
| 462 AnalysisResult result = allResults[0]; | 490 AnalysisResult result = allResults[0]; |
| 463 expect(result.path, testFile); | 491 expect(result.path, testFile); |
| 464 expect(_getTopLevelVarType(result.unit, 'V'), 'double'); | 492 expect(_getTopLevelVarType(result.unit, 'V'), 'double'); |
| 465 } | 493 } |
| 466 } | 494 } |
| 467 | 495 |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1651 String _p(String path) => provider.convertPath(path); | 1679 String _p(String path) => provider.convertPath(path); |
| 1652 | 1680 |
| 1653 Future<Null> _waitForIdle() async { | 1681 Future<Null> _waitForIdle() async { |
| 1654 await idleStatusMonitor.signal; | 1682 await idleStatusMonitor.signal; |
| 1655 } | 1683 } |
| 1656 | 1684 |
| 1657 static String _md5(String content) { | 1685 static String _md5(String content) { |
| 1658 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1686 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 1659 } | 1687 } |
| 1660 } | 1688 } |
| OLD | NEW |