Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.services.linter; | |
| 6 | |
| 7 import 'package:analysis_server/src/services/linter/linter.dart'; | |
| 8 import 'package:analyzer/analyzer.dart'; | |
| 9 import 'package:analyzer/source/analysis_options_provider.dart'; | |
| 10 import 'package:analyzer/src/generated/engine.dart'; | |
| 11 import 'package:analyzer/src/generated/source.dart'; | |
| 12 import 'package:analyzer/src/task/options.dart'; | |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 14 import 'package:unittest/unittest.dart'; | |
| 15 | |
| 16 import '../../utils.dart'; | |
| 17 | |
| 18 main() { | |
| 19 initializeTestEnvironment(); | |
| 20 defineReflectiveTests(LinterRuleOptionsValidatorTest); | |
| 21 } | |
| 22 | |
| 23 @reflectiveTest | |
| 24 class LinterRuleOptionsValidatorTest { | |
| 25 final CompositeValidator validator = | |
| 26 new CompositeValidator([new LinterRuleOptionsValidator()]); | |
|
Brian Wilkerson
2015/10/24 15:32:17
Is it necessary to wrap the LinterRuleOptionsValid
pquitslund
2015/10/26 15:48:59
Nope. And done.
| |
| 27 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | |
| 28 | |
| 29 RecordingErrorListener recorder; | |
| 30 ErrorReporter reporter; | |
| 31 | |
| 32 List<AnalysisError> get errors => recorder.errors; | |
| 33 | |
| 34 setUp() { | |
| 35 recorder = new RecordingErrorListener(); | |
| 36 reporter = new ErrorReporter(recorder, new _TestSource()); | |
| 37 } | |
| 38 | |
| 39 test_linter_defined_rules() { | |
| 40 validate( | |
| 41 ''' | |
| 42 linter: | |
| 43 rules: | |
| 44 - camel_case_types | |
| 45 ''', | |
| 46 []); | |
| 47 } | |
| 48 | |
| 49 test_linter_no_rules() { | |
| 50 validate( | |
| 51 ''' | |
| 52 linter: | |
| 53 rules: | |
| 54 ''', | |
| 55 []); | |
| 56 } | |
| 57 | |
| 58 test_linter_undefined_rule() { | |
| 59 validate( | |
| 60 ''' | |
| 61 linter: | |
| 62 rules: | |
| 63 - undefined | |
| 64 ''', | |
| 65 [UNDEFINED_LINT_WARNING]); | |
| 66 } | |
| 67 | |
| 68 validate(String source, List<AnalysisOptionsErrorCode> expected) { | |
| 69 var options = optionsProvider.getOptionsFromString(source); | |
| 70 validator.validate(reporter, options); | |
| 71 expect(errors.map((AnalysisError e) => e.errorCode), | |
| 72 unorderedEquals(expected)); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 class _TestSource implements Source { | |
| 77 @override | |
| 78 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 79 } | |
| OLD | NEW |