-
Notifications
You must be signed in to change notification settings - Fork 78
Closed
Closed
Copy link
Labels
Description
The coverage tool incorrectly marks function names as uncovered when the extension method's name appears on a different line from its return type.
This results in inaccurate coverage reports despite the code being fully tested.
Example
The following patterns all show the issue:
extension.dart
class AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz {}
extension FunctionNameInOtherLineByLongReturnTypeExtension on String {
AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz
functionNameInOtherLineByLongReturnType() {
return AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz();
}
}
extension FunctionNameInOtherLineByCommentsExtension on String {
bool
//
functionNameInOtherLineByComments() {
return true;
}
}
extension FunctionNameInOtherLineByLongNameExtension on String {
bool
functionNameInOtherLineByLongNameAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrs() {
return true;
}
}
extension_test.dart
import 'package:test_coverage_demo/extension.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('function Name In Other Line By Long Return Type', () {
expect(''.functionNameInOtherLineByLongReturnType(), isA<Object>());
});
test('function Name In Other Line By Comments', () {
expect(''.functionNameInOtherLineByComments(), isA<Object>());
});
test('function Name In Other Line By Long Name', () {
expect(
''.functionNameInOtherLineByLongNameAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrs(),
isA<Object>(),
);
});
}
flutter test --coverage && \
genhtml coverage/lcov.info -o coverage/html && \
open coverage/html/index.html
Line data Source code
1 : class AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz {}
2 :
3 : extension FunctionNameInOtherLineByLongReturnTypeExtension on String {
4 1 : AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz
5 0 : functionNameInOtherLineByLongReturnType() {
6 1 : return AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyz();
7 : }
8 : }
9 :
10 : extension FunctionNameInOtherLineByCommentsExtension onString {
11 1 : bool
12 : //
13 0 : functionNameInOtherLineByComments() {
14 : return true;
15 : }
16 : }
17 :
18 : extension FunctionNameInOtherLineByLongNameExtension onString {
19 1 : bool
20 0 : functionNameInOtherLineByLongNameAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnpqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrs() {
21 : return true;
22 : }
23 : }Environment
- Dart version 3.7.0