Skip to content

Commit

Permalink
Merge pull request #17 from emanuel-braz/develop
Browse files Browse the repository at this point in the history
Change Process.run to startProcess
  • Loading branch information
emanuel-braz authored Mar 20, 2022
2 parents ebe91db + 39cb2f4 commit 65fbd6c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "dart",
"program": "bin/dlcov.dart",
"flutterMode": "debug",
"args": ["-c", "80"]
"args": ["-c", "80", "--lcov-gen=\"flutter test --coverage\""]
},
{
"name": "gen-refs",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [4.0.1] 2022-03-20
#### Chore
- refactoring code


# [4.0.0] 2022-03-19
#### Break
- `--coverage` parameter becomes optional (default = 0)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#### The command above does:
- `--coverage=80` Check if code coverage threshold is equal or greater than 80.0%
- `--include-untested-files=true` Generate references to untested files (defalt equals "true")
- `--include-untested-files=true` Generate references to untested files (defalt equals "false")
- `--lcov-gen="flutter test --coverage"` Generate `lcov.info` through the command "flutter test --coverage", it can be used with "test_cov" for dart only for example, or others if you prefer.
- `--log=true` Log every test coverage info in dlcov.log - Limit up to 1000 lines

Expand All @@ -15,7 +15,7 @@ or add as dev dependency to `pubspec.yaml`

```yaml
dev_dependencies:
dlcov: 4.0.0
dlcov: 4.0.1
```
#### Uses
Expand All @@ -25,16 +25,16 @@ dev_dependencies:

#### Verify if code coverage threshold is equal or greater than 80.0%
`dlcov gen-refs && flutter test --coverage && dlcov -c 80`
`dlcov -c 80 --lcov-gen="flutter test --coverage"`
`dlcov -c 80 --lcov-gen="test_cov"`
`dlcov -c 80 --lcov-gen="flutter test --coverage" --include-untested-files=true`
`dlcov -c 80 --lcov-gen="test_cov" --include-untested-files=true`

## Parameters availables
| Long | Short | Mandatory | Default | Sample | Description |
|---|---|---|---|---|---|
| --coverage | -c | false | 0 | 80.0 | min coverage threshold |
| --log | -l | false | false | true | Log every test coverage info in dlcov.log - Limit up to 1000 lines |
| --exclude-suffix | -e | false | .g.dart,.freezed.dart | .g.dart | Remove generated or other files from test coverage results, separated by commas |
| --include-untested-files | | false | true | true | Get reports more coherent with reality, and do not ignore untested files during the analysis |
| --include-untested-files | | false | false | true | Get reports more coherent with reality, and do not ignore untested files during the analysis |
| --lcov-gen | | false | | "flutter test --coverage" | Generate `lcov.info` through the command "flutter test --coverage", it can be used with "test_cov" for dart only for example, or others if you prefer |

| Command | Description |
Expand Down
5 changes: 2 additions & 3 deletions bin/dlcov.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:args/args.dart';
import 'package:dlcov/core/app_constants.dart';
import 'package:dlcov/entities/config.dart';
Expand All @@ -13,6 +12,7 @@ import 'package:dlcov/usecases/parse_arguments.dart';
import 'package:dlcov/usecases/verify_coverage.dart';
import 'package:dlcov/utils/commands/app_command.dart';
import 'package:dlcov/utils/file_system/file_system_util.dart';
import 'package:dlcov/utils/process_util.dart';

void main(List<String> arguments) async {
final parser = ArgParser();
Expand Down Expand Up @@ -44,8 +44,7 @@ void main(List<String> arguments) async {
// Generate lcov.info
final lcovGeneratorParams = config.lcovGen!.split(' ');
final executable = lcovGeneratorParams.removeAt(0);
await Process.run(executable, lcovGeneratorParams,
runInShell: Platform.isWindows);
await ProcessUtil().startProcess(executable, lcovGeneratorParams);
}

// Verify minimum coverage threshold
Expand Down
4 changes: 2 additions & 2 deletions lib/repositories/config_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConfigRepository {
late bool log;
late String? packageName;
late ArgResults? command;
bool includeUntestedFiles = true;
bool includeUntestedFiles = false;
late String? lcovGen;

try {
Expand All @@ -26,7 +26,7 @@ class ConfigRepository {

includeUntestedFiles = includeUntestedFilesInput != null
? includeUntestedFilesInput == 'true'
: true;
: false;

lcovGen = argResults[AppConstants.argLcovGen];

Expand Down
2 changes: 1 addition & 1 deletion lib/usecases/parse_arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ showHelpAndExit(bool help) {
'--coverage, -c\t\t\tMin coverage threshold\n'
'--log, -l\t\t\tLog every test coverage info in dlcov.log - Limit up to 1000 lines\n'
'--exclude-suffix, -e\t\tRemove generated files from test coverage results, separated by commas\n'
'--include-untested-files\tUse this, if root folder is not the same as the package name\n'
'--include-untested-files\tGet reports more coherent with reality, and do not ignore untested files during the analysis\n'
'--lcov-gen\t\t\tGenerate `lcov.info` through the command "flutter test --coverage"\n'
'\nCommands:\n\n'
'gen-refs\t\t\tGenerate tested and untested file references, it should be used before `lcov.info` file generation step.\n\n'
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/commands/gen_refs_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class GenRefsCommand extends Command {
final CreateFileReferences createFileReferences;

@override
final name = 'gen-refs';
final name = AppConstants.cmdGenRefs;
@override
final description =
'Generate tested and untested file references, it should be used before generate lcov.info file';
final description = AppConstants.cmdGenRefsHelp;

GenRefsCommand({
required this.config,
Expand Down
26 changes: 26 additions & 0 deletions lib/utils/process_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

class ProcessUtil {
Future<String> startProcess(String executable, List<String> args) async {
stderr.write('Running "$executable ${args.join(' ')}".\n');
final List<int> output = <int>[];
final Completer<int> completer = Completer<int>();
final Process process =
await Process.start(executable, args, runInShell: Platform.isWindows);

process.stdout.listen((List<int> event) {
output.addAll(event);
stdout.add(event);
}, onDone: () async => completer.complete(await process.exitCode));

final int exitCode = await completer.future;
if (exitCode != 0) {
stderr.write(
'Running "$executable ${args.join(' ')}" failed with $exitCode.\n');
exit(exitCode);
}
return utf8.decoder.convert(output).trim();
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dlcov
description: A CLI to add code coverage threshold (CI/CD, git hooks, etc.)
version: 4.0.0
version: 4.0.1
homepage: https://github.com/emanuel-braz/dlcov

environment:
Expand Down

0 comments on commit 65fbd6c

Please sign in to comment.