-
Notifications
You must be signed in to change notification settings - Fork 53
Add --ignore-files option to exclude files from code coverage using path patterns #496
Changes from 6 commits
7c03004
87dbbac
06d0e78
634c39b
736378a
d8c4d33
4fe06f5
d066ce9
b5586c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ import 'dart:io'; | |
|
||
import 'package:coverage/coverage.dart'; | ||
import 'package:coverage/src/util.dart'; | ||
import 'package:glob/glob.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
import 'package:test_process/test_process.dart'; | ||
|
||
final _sampleAppPath = p.join('test', 'test_files', 'test_app.dart'); | ||
final _sampleGeneratedPath = p.join('test', 'test_files', 'test_app.g.dart'); | ||
final _isolateLibPath = p.join('test', 'test_files', 'test_app_isolate.dart'); | ||
|
||
final _sampleAppFileUri = p.toUri(p.absolute(_sampleAppPath)).toString(); | ||
|
@@ -31,19 +33,19 @@ void main() { | |
final sampleAppFuncNames = sampleAppHitMap?.funcNames; | ||
final sampleAppBranchHits = sampleAppHitMap?.branchHits; | ||
|
||
expect(sampleAppHitLines, containsPair(46, greaterThanOrEqualTo(1)), | ||
expect(sampleAppHitLines, containsPair(53, greaterThanOrEqualTo(1)), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitLines, containsPair(50, 0), | ||
expect(sampleAppHitLines, containsPair(57, 0), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitLines, isNot(contains(32)), | ||
expect(sampleAppHitLines, isNot(contains(39)), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitFuncs, containsPair(45, 1), | ||
expect(sampleAppHitFuncs, containsPair(52, 1), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitFuncs, containsPair(49, 0), | ||
expect(sampleAppHitFuncs, containsPair(56, 0), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppFuncNames, containsPair(45, 'usedMethod'), | ||
expect(sampleAppFuncNames, containsPair(52, 'usedMethod'), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppBranchHits, containsPair(41, 1), | ||
expect(sampleAppBranchHits, containsPair(48, 1), | ||
reason: 'be careful if you modify the test file'); | ||
}); | ||
|
||
|
@@ -59,17 +61,17 @@ void main() { | |
final sampleAppHitFuncs = sampleAppHitMap?.funcHits; | ||
final sampleAppFuncNames = sampleAppHitMap?.funcNames; | ||
|
||
expect(sampleAppHitLines, containsPair(46, greaterThanOrEqualTo(1)), | ||
expect(sampleAppHitLines, containsPair(53, greaterThanOrEqualTo(1)), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitLines, containsPair(50, 0), | ||
expect(sampleAppHitLines, containsPair(57, 0), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitLines, isNot(contains(32)), | ||
expect(sampleAppHitLines, isNot(contains(39)), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitFuncs, containsPair(45, 1), | ||
expect(sampleAppHitFuncs, containsPair(52, 1), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppHitFuncs, containsPair(49, 0), | ||
expect(sampleAppHitFuncs, containsPair(56, 0), | ||
reason: 'be careful if you modify the test file'); | ||
expect(sampleAppFuncNames, containsPair(45, 'usedMethod'), | ||
expect(sampleAppFuncNames, containsPair(52, 'usedMethod'), | ||
reason: 'be careful if you modify the test file'); | ||
}); | ||
|
||
|
@@ -122,6 +124,37 @@ void main() { | |
expect(res, contains(p.absolute(p.join('lib', 'src', 'util.dart')))); | ||
}); | ||
|
||
test('formatLcov() excludes files matching glob patterns', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
final resolver = await Resolver.create(packagePath: '.'); | ||
final res = hitmap.formatLcov( | ||
resolver, | ||
ignoreGlobs: {Glob('**/*.g.dart'), Glob('**/util.dart')}, | ||
); | ||
|
||
expect(res, isNot(contains(p.absolute(_sampleGeneratedPath)))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should be able to add an extra check for this file to all the other tests in this file: At the moment I think these tests could pass accidentally by, for example, mistyping the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this check as well as some additional checks in globs related tests to make the expected behaviour more explicit |
||
expect( | ||
res, | ||
isNot(contains(p.absolute(p.join('lib', 'src', 'util.dart')))), | ||
); | ||
}); | ||
|
||
test( | ||
'formatLcov() excludes files matching glob patterns regardless of their' | ||
'presence on reportOn list', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
final resolver = await Resolver.create(packagePath: '.'); | ||
final res = hitmap.formatLcov( | ||
resolver, | ||
reportOn: ['test/'], | ||
ignoreGlobs: {Glob('**/*.g.dart')}, | ||
); | ||
|
||
expect(res, isNot(contains(p.absolute(_sampleGeneratedPath)))); | ||
}); | ||
|
||
test('formatLcov() uses paths relative to basePath', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
|
@@ -209,6 +242,39 @@ void main() { | |
expect(res, contains(p.absolute(p.join('lib', 'src', 'util.dart')))); | ||
}); | ||
|
||
test('prettyPrint() excludes files matching glob patterns', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
final resolver = await Resolver.create(packagePath: '.'); | ||
final res = await hitmap.prettyPrint( | ||
resolver, | ||
Loader(), | ||
ignoreGlobs: {Glob('**/*.g.dart'), Glob('**/util.dart')}, | ||
); | ||
|
||
expect(res, isNot(contains(p.absolute(_sampleGeneratedPath)))); | ||
expect( | ||
res, | ||
isNot(contains(p.absolute(p.join('lib', 'src', 'util.dart')))), | ||
); | ||
}); | ||
|
||
test( | ||
'prettyPrint() excludes files matching glob patterns regardless of' | ||
'their presence on reportOn list', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
final resolver = await Resolver.create(packagePath: '.'); | ||
final res = await hitmap.prettyPrint( | ||
resolver, | ||
Loader(), | ||
reportOn: ['test/'], | ||
ignoreGlobs: {Glob('**/*.g.dart')}, | ||
); | ||
|
||
expect(res, isNot(contains(p.absolute(_sampleGeneratedPath)))); | ||
}); | ||
|
||
test('prettyPrint() functions', () async { | ||
final hitmap = await _getHitMap(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
careful making unrelated changes. Makes reviews harder.