| 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 test.services.linter; | 5 library test.services.linter; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/linter/linter.dart'; | 7 import 'package:analysis_server/src/services/linter/linter.dart'; |
| 8 import 'package:analyzer/analyzer.dart'; | 8 import 'package:analyzer/analyzer.dart'; |
| 9 import 'package:analyzer/source/analysis_options_provider.dart'; | 9 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import '../../utils.dart'; | 15 import '../../utils.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 initializeTestEnvironment(); | 18 initializeTestEnvironment(); |
| 19 defineReflectiveTests(LinterRuleOptionsValidatorTest); | 19 defineReflectiveTests(LinterRuleOptionsValidatorTest); |
| 20 } | 20 } |
| 21 | 21 |
| 22 @reflectiveTest | 22 @reflectiveTest |
| 23 class LinterRuleOptionsValidatorTest { | 23 class LinterRuleOptionsValidatorTest { |
| 24 final LinterRuleOptionsValidator validator= new LinterRuleOptionsValidator(); | 24 final LinterRuleOptionsValidator validator = new LinterRuleOptionsValidator(); |
| 25 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 25 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 26 | 26 |
| 27 RecordingErrorListener recorder; | 27 RecordingErrorListener recorder; |
| 28 ErrorReporter reporter; | 28 ErrorReporter reporter; |
| 29 | 29 |
| 30 List<AnalysisError> get errors => recorder.errors; | 30 List<AnalysisError> get errors => recorder.errors; |
| 31 | 31 |
| 32 setUp() { | 32 setUp() { |
| 33 recorder = new RecordingErrorListener(); | 33 recorder = new RecordingErrorListener(); |
| 34 reporter = new ErrorReporter(recorder, new _TestSource()); | 34 reporter = new ErrorReporter(recorder, new _TestSource()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 | 46 |
| 47 test_linter_no_rules() { | 47 test_linter_no_rules() { |
| 48 validate( | 48 validate( |
| 49 ''' | 49 ''' |
| 50 linter: | 50 linter: |
| 51 rules: | 51 rules: |
| 52 ''', | 52 ''', |
| 53 []); | 53 []); |
| 54 } | 54 } |
| 55 | 55 |
| 56 test_linter_null_rule() { |
| 57 validate( |
| 58 ''' |
| 59 linter: |
| 60 rules: |
| 61 - |
| 62 |
| 63 ''', |
| 64 []); |
| 65 } |
| 66 |
| 56 test_linter_undefined_rule() { | 67 test_linter_undefined_rule() { |
| 57 validate( | 68 validate( |
| 58 ''' | 69 ''' |
| 59 linter: | 70 linter: |
| 60 rules: | 71 rules: |
| 61 - undefined | 72 - undefined |
| 62 ''', | 73 ''', |
| 63 [UNDEFINED_LINT_WARNING]); | 74 [UNDEFINED_LINT_WARNING]); |
| 64 } | 75 } |
| 65 | 76 |
| 66 validate(String source, List<AnalysisOptionsErrorCode> expected) { | 77 validate(String source, List<AnalysisOptionsErrorCode> expected) { |
| 67 var options = optionsProvider.getOptionsFromString(source); | 78 var options = optionsProvider.getOptionsFromString(source); |
| 68 validator.validate(reporter, options); | 79 validator.validate(reporter, options); |
| 69 expect(errors.map((AnalysisError e) => e.errorCode), | 80 expect(errors.map((AnalysisError e) => e.errorCode), |
| 70 unorderedEquals(expected)); | 81 unorderedEquals(expected)); |
| 71 } | 82 } |
| 72 } | 83 } |
| 73 | 84 |
| 74 class _TestSource implements Source { | 85 class _TestSource implements Source { |
| 75 @override | 86 @override |
| 76 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 87 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 77 } | 88 } |
| OLD | NEW |