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 linter.test.rule; | 5 library linter.test.rule; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 int lineNumber = 1; | 346 int lineNumber = 1; |
347 for (var line in file.readAsLinesSync()) { | 347 for (var line in file.readAsLinesSync()) { |
348 var annotation = extractAnnotation(line); | 348 var annotation = extractAnnotation(line); |
349 if (annotation != null) { | 349 if (annotation != null) { |
350 annotation.lineNumber = lineNumber; | 350 annotation.lineNumber = lineNumber; |
351 expected.add(new AnnotationMatcher(annotation)); | 351 expected.add(new AnnotationMatcher(annotation)); |
352 } | 352 } |
353 ++lineNumber; | 353 ++lineNumber; |
354 } | 354 } |
355 | 355 |
356 DartLinter driver = new DartLinter.forRules( | 356 LinterOptions options = new LinterOptions( |
357 [ruleRegistry[ruleName]].where((rule) => rule != null)); | 357 [ruleRegistry[ruleName]].where((rule) => rule != null)) |
| 358 ..useMockSdk = true |
| 359 ..packageRootPath = '.'; |
| 360 |
| 361 DartLinter driver = new DartLinter(options); |
358 | 362 |
359 Iterable<AnalysisErrorInfo> lints = driver.lintFiles([file]); | 363 Iterable<AnalysisErrorInfo> lints = driver.lintFiles([file]); |
360 | 364 |
361 List<Annotation> actual = []; | 365 List<Annotation> actual = []; |
362 lints.forEach((AnalysisErrorInfo info) { | 366 lints.forEach((AnalysisErrorInfo info) { |
363 info.errors.forEach((AnalysisError error) { | 367 info.errors.forEach((AnalysisError error) { |
364 if (error.errorCode.type == ErrorType.LINT) { | 368 if (error.errorCode.type == ErrorType.LINT) { |
365 actual.add(new Annotation.forError(error, info.lineInfo)); | 369 actual.add(new Annotation.forError(error, info.lineInfo)); |
366 } | 370 } |
367 }); | 371 }); |
368 }); | 372 }); |
369 try { | 373 try { |
370 expect(actual, unorderedMatches(expected)); | 374 expect(actual, unorderedMatches(expected)); |
371 } on Error catch (e) { | 375 } on Error catch (e) { |
372 | |
373 if (debug) { | 376 if (debug) { |
374 // Dump results for debugging purposes. | 377 // Dump results for debugging purposes. |
375 | 378 |
376 //AST. | 379 //AST. |
377 new Spelunker(file.absolute.path).spelunk(); | 380 new Spelunker(file.absolute.path).spelunk(); |
378 print(''); | 381 print(''); |
379 // Lints. | 382 // Lints. |
380 var reporter = new ResultReporter(lints); | 383 var reporter = new ResultReporter(lints); |
381 reporter.write(); | 384 reporter.write(); |
382 } | 385 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 451 |
449 class NoFilter implements LintFilter { | 452 class NoFilter implements LintFilter { |
450 @override | 453 @override |
451 bool filter(AnalysisError lint) => false; | 454 bool filter(AnalysisError lint) => false; |
452 } | 455 } |
453 | 456 |
454 class ResultReporter extends DetailedReporter { | 457 class ResultReporter extends DetailedReporter { |
455 ResultReporter(Iterable<AnalysisErrorInfo> errors) | 458 ResultReporter(Iterable<AnalysisErrorInfo> errors) |
456 : super(errors, new NoFilter(), stdout); | 459 : super(errors, new NoFilter(), stdout); |
457 } | 460 } |
OLD | NEW |