| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.options_test; | 5 library analyzer.test.src.task.options_test; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/source/analysis_options_provider.dart'; | 10 import 'package:analyzer/source/analysis_options_provider.dart'; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 '''; | 350 '''; |
| 351 AnalysisTarget target = newSource(optionsFilePath, code); | 351 AnalysisTarget target = newSource(optionsFilePath, code); |
| 352 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 352 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 353 expect(task, isGenerateOptionsErrorsTask); | 353 expect(task, isGenerateOptionsErrorsTask); |
| 354 List<AnalysisError> errors = | 354 List<AnalysisError> errors = |
| 355 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 355 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 356 expect(errors, hasLength(0)); | 356 expect(errors, hasLength(0)); |
| 357 } | 357 } |
| 358 | 358 |
| 359 test_perform_include_bad_value() { | 359 test_perform_include_bad_value() { |
| 360 newSource( | 360 newSource('/other_options.yaml', ''' |
| 361 '/other_options.yaml', | |
| 362 ''' | |
| 363 analyzer: | 361 analyzer: |
| 364 errors: | 362 errors: |
| 365 unused_local_variable: ftw | 363 unused_local_variable: ftw |
| 366 '''); | 364 '''); |
| 367 String code = r''' | 365 String code = r''' |
| 368 include: other_options.yaml | 366 include: other_options.yaml |
| 369 '''; | 367 '''; |
| 370 AnalysisTarget target = newSource(optionsFilePath, code); | 368 AnalysisTarget target = newSource(optionsFilePath, code); |
| 371 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 369 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 372 expect(task, isGenerateOptionsErrorsTask); | 370 expect(task, isGenerateOptionsErrorsTask); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 445 } |
| 448 } | 446 } |
| 449 | 447 |
| 450 @reflectiveTest | 448 @reflectiveTest |
| 451 class OptionsFileValidatorTest { | 449 class OptionsFileValidatorTest { |
| 452 final OptionsFileValidator validator = | 450 final OptionsFileValidator validator = |
| 453 new OptionsFileValidator(new TestSource()); | 451 new OptionsFileValidator(new TestSource()); |
| 454 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 452 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 455 | 453 |
| 456 test_analyzer_error_code_supported() { | 454 test_analyzer_error_code_supported() { |
| 457 validate( | 455 validate(''' |
| 458 ''' | |
| 459 analyzer: | 456 analyzer: |
| 460 errors: | 457 errors: |
| 461 unused_local_variable: ignore | 458 unused_local_variable: ignore |
| 462 invalid_assignment: warning | 459 invalid_assignment: warning |
| 463 missing_return: error | 460 missing_return: error |
| 464 dead_code: info | 461 dead_code: info |
| 465 ''', | 462 ''', []); |
| 466 []); | |
| 467 } | 463 } |
| 468 | 464 |
| 469 test_analyzer_error_code_supported_bad_value() { | 465 test_analyzer_error_code_supported_bad_value() { |
| 470 validate( | 466 validate(''' |
| 471 ''' | |
| 472 analyzer: | 467 analyzer: |
| 473 errors: | 468 errors: |
| 474 unused_local_variable: ftw | 469 unused_local_variable: ftw |
| 475 ''', | 470 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
| 476 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); | |
| 477 } | 471 } |
| 478 | 472 |
| 479 test_analyzer_error_code_unsupported() { | 473 test_analyzer_error_code_unsupported() { |
| 480 validate( | 474 validate(''' |
| 481 ''' | |
| 482 analyzer: | 475 analyzer: |
| 483 errors: | 476 errors: |
| 484 not_supported: ignore | 477 not_supported: ignore |
| 485 ''', | 478 ''', [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]); |
| 486 [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]); | |
| 487 } | 479 } |
| 488 | 480 |
| 489 test_analyzer_language_supported() { | 481 test_analyzer_language_supported() { |
| 490 validate( | 482 validate(''' |
| 491 ''' | |
| 492 analyzer: | 483 analyzer: |
| 493 language: | 484 language: |
| 494 enableSuperMixins: true | 485 enableSuperMixins: true |
| 495 ''', | 486 ''', []); |
| 496 []); | |
| 497 } | 487 } |
| 498 | 488 |
| 499 test_analyzer_language_unsupported_key() { | 489 test_analyzer_language_unsupported_key() { |
| 500 validate( | 490 validate(''' |
| 501 ''' | |
| 502 analyzer: | 491 analyzer: |
| 503 language: | 492 language: |
| 504 unsupported: true | 493 unsupported: true |
| 505 ''', | 494 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
| 506 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); | |
| 507 } | 495 } |
| 508 | 496 |
| 509 test_analyzer_language_unsupported_value() { | 497 test_analyzer_language_unsupported_value() { |
| 510 validate( | 498 validate(''' |
| 511 ''' | |
| 512 analyzer: | 499 analyzer: |
| 513 language: | 500 language: |
| 514 enableSuperMixins: foo | 501 enableSuperMixins: foo |
| 515 ''', | 502 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]); |
| 516 [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]); | |
| 517 } | 503 } |
| 518 | 504 |
| 519 test_analyzer_strong_mode_error_code_supported() { | 505 test_analyzer_strong_mode_error_code_supported() { |
| 520 validate( | 506 validate(''' |
| 521 ''' | |
| 522 analyzer: | 507 analyzer: |
| 523 errors: | 508 errors: |
| 524 strong_mode_assignment_cast: ignore | 509 strong_mode_assignment_cast: ignore |
| 525 ''', | 510 ''', []); |
| 526 []); | |
| 527 } | 511 } |
| 528 | 512 |
| 529 test_analyzer_supported_exclude() { | 513 test_analyzer_supported_exclude() { |
| 530 validate( | 514 validate(''' |
| 531 ''' | |
| 532 analyzer: | 515 analyzer: |
| 533 exclude: | 516 exclude: |
| 534 - test/_data/p4/lib/lib1.dart | 517 - test/_data/p4/lib/lib1.dart |
| 535 ''', | 518 ''', []); |
| 536 []); | |
| 537 } | 519 } |
| 538 | 520 |
| 539 test_analyzer_supported_strong_mode() { | 521 test_analyzer_supported_strong_mode() { |
| 540 validate( | 522 validate(''' |
| 541 ''' | |
| 542 analyzer: | 523 analyzer: |
| 543 strong-mode: true | 524 strong-mode: true |
| 544 ''', | 525 ''', []); |
| 545 []); | |
| 546 } | 526 } |
| 547 | 527 |
| 548 test_analyzer_supported_strong_mode_supported_bad_value() { | 528 test_analyzer_supported_strong_mode_supported_bad_value() { |
| 549 validate( | 529 validate(''' |
| 550 ''' | |
| 551 analyzer: | 530 analyzer: |
| 552 strong-mode: w00t | 531 strong-mode: w00t |
| 553 ''', | 532 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]); |
| 554 [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]); | |
| 555 } | 533 } |
| 556 | 534 |
| 557 test_analyzer_unsupported_option() { | 535 test_analyzer_unsupported_option() { |
| 558 validate( | 536 validate(''' |
| 559 ''' | |
| 560 analyzer: | 537 analyzer: |
| 561 not_supported: true | 538 not_supported: true |
| 562 ''', | 539 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
| 563 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); | |
| 564 } | 540 } |
| 565 | 541 |
| 566 test_linter_supported_rules() { | 542 test_linter_supported_rules() { |
| 567 Registry.ruleRegistry.register(new TestRule()); | 543 Registry.ruleRegistry.register(new TestRule()); |
| 568 validate( | 544 validate(''' |
| 569 ''' | |
| 570 linter: | 545 linter: |
| 571 rules: | 546 rules: |
| 572 - fantastic_test_rule | 547 - fantastic_test_rule |
| 573 ''', | 548 ''', []); |
| 574 []); | |
| 575 } | 549 } |
| 576 | 550 |
| 577 test_linter_unsupported_option() { | 551 test_linter_unsupported_option() { |
| 578 validate( | 552 validate(''' |
| 579 ''' | |
| 580 linter: | 553 linter: |
| 581 unsupported: true | 554 unsupported: true |
| 582 ''', | 555 ''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
| 583 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); | |
| 584 } | 556 } |
| 585 | 557 |
| 586 void validate(String source, List<ErrorCode> expected) { | 558 void validate(String source, List<ErrorCode> expected) { |
| 587 var options = optionsProvider.getOptionsFromString(source); | 559 var options = optionsProvider.getOptionsFromString(source); |
| 588 var errors = validator.validate(options); | 560 var errors = validator.validate(options); |
| 589 expect(errors.map((AnalysisError e) => e.errorCode), | 561 expect(errors.map((AnalysisError e) => e.errorCode), |
| 590 unorderedEquals(expected)); | 562 unorderedEquals(expected)); |
| 591 } | 563 } |
| 592 } | 564 } |
| 593 | 565 |
| 594 class TestRule extends LintRule { | 566 class TestRule extends LintRule { |
| 595 TestRule() : super(name: 'fantastic_test_rule'); | 567 TestRule() : super(name: 'fantastic_test_rule'); |
| 596 } | 568 } |
| OLD | NEW |