diff --git a/.gitignore b/.gitignore index 7677080a..1deacf77 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,6 @@ pubspec.lock # generated assets in test fixtures /test/fixtures/coverage/browser/coverage/ +/test/fixtures/coverage/non_test_file/coverage/ /test/fixtures/coverage/vm/coverage/ /test/fixtures/docs/docs/doc/api/ diff --git a/lib/src/tasks/coverage/api.dart b/lib/src/tasks/coverage/api.dart index 0ab35585..00e0d076 100644 --- a/lib/src/tasks/coverage/api.dart +++ b/lib/src/tasks/coverage/api.dart @@ -26,6 +26,7 @@ import 'package:dart_dev/src/tasks/coverage/config.dart'; import 'package:dart_dev/src/tasks/coverage/exceptions.dart'; import 'package:dart_dev/src/tasks/task.dart'; +const String _dartFilePattern = '.dart'; const String _testFilePattern = '_test.dart'; class CoverageResult extends TaskResult { @@ -140,7 +141,7 @@ class CoverageTask extends Task { _reportOn = reportOn { // Build the list of test files. tests.forEach((path) { - if (path.endsWith(_testFilePattern) && + if (path.endsWith(_dartFilePattern) && FileSystemEntity.isFileSync(path)) { _files.add(new File(path)); } else if (FileSystemEntity.isDirectorySync(path)) { diff --git a/test/fixtures/coverage/non_test_file/lib/non_test_file.dart b/test/fixtures/coverage/non_test_file/lib/non_test_file.dart new file mode 100644 index 00000000..023fc8b9 --- /dev/null +++ b/test/fixtures/coverage/non_test_file/lib/non_test_file.dart @@ -0,0 +1,9 @@ +library non_test_file; + +import 'dart:io'; + +void notCovered() { + print('nope'); +} + +bool works() => stdout is IOSink; \ No newline at end of file diff --git a/test/fixtures/coverage/non_test_file/pubspec.yaml b/test/fixtures/coverage/non_test_file/pubspec.yaml new file mode 100644 index 00000000..65d9d087 --- /dev/null +++ b/test/fixtures/coverage/non_test_file/pubspec.yaml @@ -0,0 +1,7 @@ +name: non_test_file +version: 0.0.0 +dev_dependencies: + coverage: "^0.7.2" + dart_dev: + path: ../../../.. + test: "^0.12.0" \ No newline at end of file diff --git a/test/fixtures/coverage/non_test_file/test/file.dart b/test/fixtures/coverage/non_test_file/test/file.dart new file mode 100644 index 00000000..75ab458f --- /dev/null +++ b/test/fixtures/coverage/non_test_file/test/file.dart @@ -0,0 +1,11 @@ +@TestOn('vm') +library coverage.non_test_file.test.file; + +import 'package:non_test_file/non_test_file.dart' as lib; +import 'package:test/test.dart'; + +main() { + test('non_test_file', () { + expect(lib.works(), isTrue); + }); +} \ No newline at end of file diff --git a/test/fixtures/coverage/non_test_file/tool/dev.dart b/test/fixtures/coverage/non_test_file/tool/dev.dart new file mode 100644 index 00000000..68dce63c --- /dev/null +++ b/test/fixtures/coverage/non_test_file/tool/dev.dart @@ -0,0 +1,9 @@ +library tool.dev; + +import 'package:dart_dev/dart_dev.dart' show dev, config; + +main(List args) async { + config.test.unitTests = ['test/file.dart']; + + await dev(args); +} \ No newline at end of file diff --git a/test/integration/coverage_test.dart b/test/integration/coverage_test.dart index eef506ea..d5b9afcc 100644 --- a/test/integration/coverage_test.dart +++ b/test/integration/coverage_test.dart @@ -21,6 +21,7 @@ import 'dart:io'; import 'package:dart_dev/util.dart' show TaskProcess; import 'package:test/test.dart'; +const String projectWithDartFile = 'test/fixtures/coverage/non_test_file'; const String projectWithVmTests = 'test/fixtures/coverage/browser'; const String projectWithBrowserTests = 'test/fixtures/coverage/vm'; const String projectWithoutCoveragePackage = @@ -60,6 +61,12 @@ void main() { expect(await runCoverage(projectWithoutCoveragePackage), isFalse); }); + test('should create coverage with non_test file specified', () async { + expect(await runCoverage(projectWithDartFile), isTrue); + File lcov = new File('$projectWithDartFile/coverage/coverage.lcov'); + expect(lcov.existsSync(), isTrue); + }, timeout: new Timeout(new Duration(seconds: 60))); + // TODO: Will need to mock out the `genhtml` command as well. // test('should not fail if "lcov" is installed and --html is set', () async { // MockPlatformUtil.install();