Skip to content

Commit

Permalink
Release 1.4.1
Browse files Browse the repository at this point in the history
- add --fix-compunit flag
- fix tests for all three platforms
- improve CI
- update README
  • Loading branch information
atroxaper committed Oct 21, 2021
2 parents b3e140e + 87c35c8 commit dbdaee3
Show file tree
Hide file tree
Showing 43 changed files with 270 additions and 134 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: MacOS

on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master ]

workflow_dispatch:

jobs:
raku:
strategy:
matrix:
os:
- macOS-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Install App::Prove6
run: zef install --/test App::Prove6
- name: Run Tests
run: prove6 t
- name: Run XT Tests
run: prove6 xt
28 changes: 20 additions & 8 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ on:
workflow_dispatch:

jobs:
build:
name: prove
runs-on: ubuntu-latest
raku:
strategy:
matrix:
os:
- ubuntu-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Runs tests
id: tests
uses: JJ/raku-container-action@master
- uses: actions/checkout@v2
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Install App::Prove6
run: zef install --/test App::Prove6
- name: Run Tests
run: prove6 t
- name: Run XT Tests
run: prove6 xt
75 changes: 18 additions & 57 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,24 @@ on:
workflow_dispatch:

jobs:
build:
name: prove
runs-on: windows-latest
env:
RAKUBREW_HOME: engine/brew
raku:
strategy:
matrix:
os:
- windows-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Set PATH
shell: bash
run: |
echo "$GITHUB_WORKSPACE/engine/brew/shims" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/engine" >> $GITHUB_PATH
- name: Install Rakubrew
uses: suisei-cn/actions-download-file@v1
with:
url: "https://rakubrew.org/win/rakubrew.exe"
target: engine/

- name: Install Raku
run: |
rakubrew mode shim
rakubrew download
raku -v
- uses: suisei-cn/actions-download-file@v1
name: Download Zef
- uses: actions/checkout@v2
- uses: Raku/setup-raku@v1
with:
url: https://github.com/ugexe/zef/tarball/master
target: engine/

- name: Unpack Zef
shell: bash
run: |
mkdir engine/zef
tar -xf engine/master -C engine/zef --strip 1
- name: Install Zef [no tests]
working-directory: engine/zef
run: |
raku -I. bin/zef install . --/test
rakubrew rehash
env:
RAKUBREW_HOME: ../brew

- name: Install Prove6 [no tests]
run: |
zef install App::Prove6 --/test
rakubrew rehash
- name: Install dependencies [no tests]
run: zef install . --deps-only --/test

- name: Tests
run: prove6

- name: XT Tests
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Install App::Prove6
run: zef install --/test App::Prove6
- name: Run Tests
run: prove6 t
- name: Run XT Tests
run: prove6 xt
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Version history:

1.4.1 2021-10-21 'Second public release'
- add --fix-compunit flag
- fix tests for all three platforms
- improve CI
- Update README

1.3.1 2021-03-14 'The first public release'
- Production ready code coverage tool
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "App::RaCoCo",
"description": "Raku Code Coverage tool and library.",
"version": "1.3.1",
"description": "Raku Code Coverage tool.",
"version": "1.4.1",
"perl": "6.*",
"authors": [
"Mikhail Khorkov"
Expand Down
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![Build Status](https://github.com/atroxaper/raku-RaCoCo/workflows/Ubuntu/badge.svg)](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/ubuntu.yml)
[![Build Status](https://github.com/atroxaper/raku-RaCoCo/workflows/Windows/badge.svg)](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/windows.yml)
[![Ubuntu](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/ubuntu.yml)
[![MacOS](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/macos.yml/badge.svg)](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/macos.yml)
[![Windows](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/windows.yml/badge.svg)](https://github.com/atroxaper/raku-RaCoCo/actions/workflows/windows.yml)
# NAME

`App::RaCoCo` - Raku Code Coverage tool and library.
`App::RaCoCo` - Raku Code Coverage tool.

# SYNOPSIS

Expand All @@ -18,21 +19,42 @@ Coverage: 89.2%
Visualisation: file://.racoco/report.html
Coverage: 89.2%
> browsername .racoco/report.html

> racoco --exec='prove6 -Ilib' --fail-level=95 --silent
Coverage: 89.2%
# exit code: 6

> racoco
[...]
===SORRY!===
Library path 「lib/.precomp」 has ambiguous .precomp directory with more than one
CompUnit Repository. Please, make sure you have only the one directory in
the <library>/.precomp path or use --fix-compunit flag for the next RaCoCo launch
to erase .precomp directory automatically.
> racoco --fix-compunit
[...]
Coverage: 89.2%
```

# DESCRIPTION

`App::RaCoCo` provides the `racoco` application, which can be used to run tests and calculate code coverage.

You may specify the following parameters:
* **--lib** - path to directory with coverable source files (`'./lib'` by default);
* **--lib** - path to directory with target source files (`'./lib'` by default);
* **--raku-bin-dir** - path to directory with raku and moar binaries (`$*EXECUTABLE.parent` by default);
* **--exec** - command, which need to be executed to run tests. For example, you may pass `'prove --exec raku'` to the `exec` parameter to say `prove` to manage your tests, or use `--/exec` parameter to not run tests and use coverage data from the previous run (`prove6` by default);
* **--fail-level** - integer number - if coverage will be less than it then `racoco` will exit with non-zero exitcode;
* **--silent** - hide test result output;
* **--append** - do not clean coverage data before this `racoco` run and append its result to the previous one;
* **--html** - produce simple html page to visualize results;
* **--color-blind** - addition to `--html` parameter - use more readable colors than green/red pare.
* **--color-blind** - addition to `--html` parameter - use more readable colors than green/red pare;
* **--fix-compunit** - erase `<library>/.precomp` directory before run tests. See [details below](#common-difficult-cases).

# COMMON DIFFICULT CASES

* It is common practise to not include `use lib 'lib'` line in test files. In such case we need to run tests with command like `prove6 -Ilib`. As RaCoCo uses just `prove6` command by default, then we will need to run it like `racoco --exec='prove6 -Ilib'`.
* If `<library>/.precomp` directory has more than one directory with compiled sources, then RaCoCo cannot be sure which one need to be analysed. The situation arises, for example, after updating raku compiler. You need to clean `.precomp` directory or delete only the old directories inside. Alternatively, you can run RaCoCo with `--fix-compunit` flag ones to erase `.precomp` directory automatically.

# NOTE

Expand All @@ -49,3 +71,7 @@ Source can be located at: [github](https://github.com/atroxaper/raku-RaCoCo). Co
Copyright 2021 Mikhail Khorkov

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.




25 changes: 21 additions & 4 deletions lib/App/Racoco/Cli.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use App::Racoco::CoveredLinesCollector;
use App::Racoco::Report::Report;
use App::Racoco::Report::ReporterHtml;
use App::Racoco::Report::ReporterBasic;
use App::Racoco::Paths;
use App::Racoco::X;

multi sub get(:$lib) {
Expand All @@ -23,11 +24,11 @@ multi sub get(:$raku-bin-dir, :$name) {
unless $result.IO ~~ :e & :d {
App::Racoco::X::WrongRakuBinDirPath.new(path => $result).throw
}
my $moar = $result.IO.add($name);
unless $moar.e {
my $app = $result.IO.add($name ~ ($*DISTRO.is-win ?? '.exe' !! ''));
unless $app.e {
App::Racoco::X::WrongRakuBinDirPath.new(path => $result).throw
}
$moar.Str
$app.Str
}

multi sub get(:$reporter, :$html) {
Expand Down Expand Up @@ -57,6 +58,19 @@ sub read-reporter(:$reporter-class, :$lib) {
$reporter-class.read(:$lib)
}

sub rmdir($path, :$rm-path) {
return unless $path ~~ :d & :e;
for $path.dir() -> $sub-path {
rmdir($sub-path, :rm-path) if $sub-path.d;
$sub-path.unlink;
}
$path.rmdir if $rm-path;
}

sub rm-precomp(:$lib) {
rmdir(lib-precomp-path(:$lib), :!rm-path)
}

our sub MAIN(
Str :lib($lib-dir) = 'lib',
Str :$raku-bin-dir,
Expand All @@ -65,7 +79,8 @@ our sub MAIN(
Bool :$color-blind = False,
Bool :$silent = False,
Bool :$append = False,
Int :$fail-level = 0
Int() :$fail-level = 0,
Bool :$fix-compunit = False
) is export {
my $lib = get(lib => $lib-dir);
my $moar = get(:name<moar>, :$raku-bin-dir);
Expand All @@ -85,6 +100,8 @@ our sub MAIN(
my $coverable-collector = CoverableLinesCollector.new(
supplier => $coverable-supplier, :$lib);

rm-precomp(:$lib) if $fix-compunit && $exec;

my $reporter = $exec === False
?? read-reporter(:$reporter-class, :$lib)
!! calculate-reporter(:$covered-collector, :$coverable-collector, :$reporter-class);
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Racoco/Coverable/CoverableOutliner.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CoverableOutlinerReal does CoverableOutliner is export {
has Str $.moar;

method outline(IO::Path :$path --> Positional) {
my $proc = $!proc.run("$!moar --dump $path", :out);
my $proc = $!proc.run(qq/$!moar --dump $path/, :out);
LEAVE { $proc.out.close if $proc && $proc.out }
return () if $proc.exitcode;
self!parse-dump($proc.out)
Expand Down
6 changes: 4 additions & 2 deletions lib/App/Racoco/CoveredLinesCollector.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class CoveredLinesCollector is export {

method !run-tests() {
return unless $!exec;
my $arg = "MVM_COVERAGE_LOG=$!coverage-log-path $!exec";
my $proc = $!print-test-log ?? $!proc.run($arg) !! $!proc.run($arg, :!out);
my %vars = MVM_COVERAGE_LOG => $!coverage-log-path;
my $proc = $!print-test-log
?? $!proc.run($!exec, :%vars)
!! $!proc.run($!exec, :%vars, :!out);
if $proc.exitcode {
App::Racoco::X::NonZeroExitCode.new(exitcode => $proc.exitcode).throw
}
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Racoco/Precomp/PrecompSupplier.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ role PrecompSupplier is export {

class PrecompSupplierReal does PrecompSupplier is export {
has PrecompLookup $!lookup;
has Precompiler $!precompiler;
has Precompiler $!precompiler;

submethod BUILD(:$lib, :$raku, :$proc) {
$!lookup = PrecompLookup.new(:$lib);
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Racoco/Precomp/Precompiler.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Precompiler is export {
$out-path.parent.mkdir;
my $source-file = $!lib.add($file-name);
my $proc = $!proc.run(
"$!raku -I$!lib --target=mbc --output=$out-path $source-file", :!out
qq/$!raku -I$!lib --target=mbc --output=$out-path $source-file/, :!out
);
$proc.exitcode ?? Nil !! $out-path;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Racoco/ProjectName.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ our sub project-name(IO::Path :$lib --> Str) is export {
sub from-meta(:$lib) {
my $path = meta6-path(:$lib);
return Nil unless $path.e;
my $line-with-name = $path.lines.grep(* ~~ /'"name"'/).first;
my $line-with-name = $path.slurp.lines.grep(* ~~ /'"name"'/).first;
return Nil unless $line-with-name;
($line-with-name.split(':').[*-1].trim ~~ / <-['",]>+/).Str
}
Expand Down
25 changes: 18 additions & 7 deletions lib/App/Racoco/RunProc.rakumod
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
unit module App::Racoco::RunProc;

class RunProc is export {
method run(|c --> Proc) {
my $proc = shell(|c);
if $proc.exitcode != 0 {
$*ERR.say: "Fail execute: {c.List[0]}";
}
$proc
}
method run(:%vars, |c --> Proc) {
my $comand = self!tweak-command(c.list[0], :%vars);
my $proc = shell($comand, |c.hash);
if $proc.exitcode != 0 {
$*ERR.say: "Fail execute: { $comand }";
}
$proc
}

method !tweak-command($command, :%vars) {
return $command unless %vars.elems;
if $*DISTRO.is-win {
my $vars-str = %vars.kv.map(-> $k, $v { "$k=$v&&" }).join(' set ');
qq[cmd /S /C "set $vars-str $command"]
} else {
%vars.kv.map(-> $k, $v { "$k=$v" }).join(' ') ~ ' ' ~ $command
}
}
}
7 changes: 5 additions & 2 deletions lib/App/Racoco/X.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class WrongRakuBinDirPath is Exception {
class AmbiguousPrecompContent is Exception {
has $.path;

method message() { "Library path 「$!path」 has ambiguous .precomp folder with "
~ 'more than one CompUnit Repository' }
method message() {
"Library path 「$!path」 has ambiguous .precomp directory with more than one " ~
'CompUnit Repository. Please, make sure you have only the one directory ' ~
'in the <library>/.precomp path or use --fix-compunit flag for the next ' ~
'RaCoCo launch to erase .precomp directory automatically.' }
method backtrace() { '' }
}

Expand Down
3 changes: 3 additions & 0 deletions t-resources/root-folder-backup/fix-compunit/M1.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sub m1() is export {
'm1'
}
Loading

0 comments on commit dbdaee3

Please sign in to comment.