Skip to content

Commit c6452f7

Browse files
test: add coverage options file locator tests
1 parent 8d3ca0c commit c6452f7

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'dart:io';
2+
import 'package:coverage/src/coverage_options.dart';
3+
import 'package:path/path.dart' as path;
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
final baseTestPath = 'test/test_file_locator';
8+
late Directory testDirectory;
9+
10+
test('options file exists', () {
11+
testDirectory = Directory('$baseTestPath/pkg1/lib/src');
12+
var filePath =
13+
CoverageOptionsProvider.findOptionsFilePath(directory: testDirectory);
14+
expect(path.normalize('$baseTestPath/pkg1/coverage_options.yaml'),
15+
path.normalize(filePath!));
16+
17+
testDirectory = Directory('$baseTestPath/pkg1/lib');
18+
filePath =
19+
CoverageOptionsProvider.findOptionsFilePath(directory: testDirectory);
20+
expect(path.normalize('$baseTestPath/pkg1/coverage_options.yaml'),
21+
path.normalize(filePath!));
22+
});
23+
24+
test('options file missing', () {
25+
testDirectory = Directory('$baseTestPath/pkg2/lib/src');
26+
var filePath =
27+
CoverageOptionsProvider.findOptionsFilePath(directory: testDirectory);
28+
expect(filePath, isNull);
29+
30+
testDirectory = Directory('$baseTestPath/pkg2/lib');
31+
filePath =
32+
CoverageOptionsProvider.findOptionsFilePath(directory: testDirectory);
33+
expect(filePath, isNull);
34+
});
35+
36+
test('no pubspec found', () {
37+
var filePath = CoverageOptionsProvider.findOptionsFilePath(
38+
directory: Directory.systemTemp);
39+
expect(filePath, isNull);
40+
41+
filePath = CoverageOptionsProvider.findOptionsFilePath(
42+
directory: Directory.systemTemp);
43+
expect(filePath, isNull);
44+
});
45+
}

pkgs/coverage/test/test_file_locator/pkg1/coverage_options.yaml

Whitespace-only changes.

pkgs/coverage/test/test_file_locator/pkg1/pubspec.yaml

Whitespace-only changes.

pkgs/coverage/test/test_file_locator/pkg2/pubspec.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)