-
Notifications
You must be signed in to change notification settings - Fork 40
CP-907 Coverage: check for lcov dependency, fail helpfully #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| library dart_dev.src.platform_util.api; | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:dart_dev/src/platform_util/platform_util.dart'; | ||
|
|
||
| /// Determines whether or not the project in the current working directory has | ||
| /// defined [packageName] as an immediate dependency. In other words, this | ||
| /// checks if [packageName] is in the project's pubspec.yaml. | ||
| bool hasImmediateDependency(String packageName) => | ||
| PlatformUtil.retrieve().hasImmediateDependency(packageName); | ||
|
|
||
| /// Determines whether or not [executable] is installed on this platform. | ||
| Future<bool> isExecutableInstalled(String executable) => | ||
| PlatformUtil.retrieve().isExecutableInstalled(executable); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| library dart_dev.src.platform_util.mock_platform_util; | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:dart_dev/src/platform_util/platform_util.dart'; | ||
| import 'package:dart_dev/src/platform_util/standard_platform_util.dart'; | ||
|
|
||
| const List<String> _defaultInstalledExecutables = const ['lcov']; | ||
|
|
||
| const Map<String, dynamic> _defaultProjectDependencies = const { | ||
| 'coverage': '^0.7.2', | ||
| 'dart_style': '^0.2.0', | ||
| 'test': '^0.12.0' | ||
| }; | ||
|
|
||
| class MockPlatformUtil implements PlatformUtil { | ||
| /// List of executables installed on this platform. Does not actually need | ||
| /// to be exhaustive, only needs to cover the executables that may be checked | ||
| /// by a dart_dev task. | ||
| static List<String> installedExecutables = | ||
| _defaultInstalledExecutables.toList(); | ||
|
|
||
| /// Map of dependencies that are defined by the current project. This | ||
| /// effectively mocks out any platform util that checks the pubspec.yaml | ||
| /// for dependencies. | ||
| static Map<String, dynamic> projectDependencies = | ||
| new Map.from(_defaultProjectDependencies); | ||
|
|
||
| static void install() { | ||
| platformUtil = new MockPlatformUtil(); | ||
| } | ||
|
|
||
| static void uninstall() { | ||
| platformUtil = new StandardPlatformUtil(); | ||
| installedExecutables = _defaultInstalledExecutables.toList(); | ||
| projectDependencies = new Map.from(_defaultProjectDependencies); | ||
| } | ||
|
|
||
| bool hasImmediateDependency(String packageName) => | ||
| projectDependencies.containsKey(packageName); | ||
|
|
||
| Future<bool> isExecutableInstalled(String executable) async => | ||
| installedExecutables.contains(executable); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| library dart_dev.src.platform_util.platform_util; | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:dart_dev/src/platform_util/standard_platform_util.dart'; | ||
|
|
||
| PlatformUtil platformUtil = new StandardPlatformUtil(); | ||
|
|
||
| abstract class PlatformUtil { | ||
| static PlatformUtil retrieve() { | ||
| if (platformUtil == null) throw new StateError( | ||
| 'dart_dev\'s PlatformUtil instance must not be null.'); | ||
| return platformUtil; | ||
| } | ||
|
|
||
| /// Generates an HTML report for an LCOV formatted coverage file. | ||
| // TODO: Future<bool> generateLcovHtml(String lcovPath, String outputPath); | ||
|
|
||
| /// Determines whether or not the project in the current working directory has | ||
| /// defined [packageName] as an immediate dependency. In other words, this | ||
| /// checks if [packageName] is in the project's pubspec.yaml. | ||
| bool hasImmediateDependency(String packageName); | ||
|
|
||
| /// Determines whether or not [executable] is installed on this platform. | ||
| Future<bool> isExecutableInstalled(String executable); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| library dart_dev.src.platform_util.standard_platform_util; | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:yaml/yaml.dart'; | ||
|
|
||
| import 'package:dart_dev/src/platform_util/platform_util.dart'; | ||
|
|
||
| class StandardPlatformUtil implements PlatformUtil { | ||
| bool hasImmediateDependency(String packageName) { | ||
| File pubspec = new File('pubspec.yaml'); | ||
| Map pubspecYaml = loadYaml(pubspec.readAsStringSync()); | ||
| List deps = []; | ||
| if (pubspecYaml.containsKey('dependencies')) { | ||
| deps.addAll((pubspecYaml['dependencies'] as Map).keys); | ||
| } | ||
| if (pubspecYaml.containsKey('dev_dependencies')) { | ||
| deps.addAll((pubspecYaml['dev_dependencies'] as Map).keys); | ||
| } | ||
| return deps.contains(packageName); | ||
| } | ||
|
|
||
| Future<bool> isExecutableInstalled(String executable) async { | ||
| ProcessResult result = await Process.run('which', [executable]); | ||
| return result.exitCode == 0; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| library dart_dev.src.tasks.coverage.exceptions; | ||
|
|
||
|
Contributor
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. blank file?
Contributor
Author
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. grr.. I originally added
Contributor
Author
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. fixed |
||
| const String missingLcovMessage = ''' | ||
| The "lcov" dependency is missing. It's required for generating the HTML report. | ||
|
|
||
| If using brew, you can install it with: | ||
| brew update | ||
| brew install lcov | ||
|
|
||
| Otherwise, visit http://ltp.sourceforge.net/coverage/lcov.php | ||
| '''; | ||
|
|
||
| /// Thrown when collecting coverage on a test suite that has failing tests. | ||
| class CoverageTestSuiteException implements Exception { | ||
| final String message; | ||
| CoverageTestSuiteException(String testSuite) | ||
| : this.message = 'Test suite has failing tests: $testSuite'; | ||
| String toString() => 'CoverageTestSuiteException: $message'; | ||
| } | ||
|
|
||
| /// Thrown when attempting to generate the HTML coverage report without the | ||
| /// required "lcov" dependency being installed. | ||
| class MissingLcovException implements Exception { | ||
| final String message = missingLcovMessage; | ||
| String toString() => 'MissingLcovException: $message'; | ||
| } | ||
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.
This comment seems misplaced
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.
That was intentional. I want to eventually have the report generation go through here since it's interacting with an executable, and so that it can be mocked. But it will require more than a simple Future return type because I need to be able to listen to the stdout/stderr streams.