diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..a065aea --- /dev/null +++ b/.github/workflows/macos.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index b81c4e9..fb83ab0 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 562d195..e9b3edf 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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 \ No newline at end of file diff --git a/Changes b/Changes index c6e867c..e547aad 100644 --- a/Changes +++ b/Changes @@ -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 \ No newline at end of file diff --git a/META6.json b/META6.json index ec659bc..f5caf8b 100644 --- a/META6.json +++ b/META6.json @@ -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" diff --git a/README.md b/README.md index 984e8ff..c5e9682 100644 --- a/README.md +++ b/README.md @@ -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 @@ -18,6 +19,21 @@ 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 /.precomp path or use --fix-compunit flag for the next RaCoCo launch +to erase .precomp directory automatically. +> racoco --fix-compunit +[...] +Coverage: 89.2% ``` # DESCRIPTION @@ -25,14 +41,20 @@ Coverage: 89.2% `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 `/.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 `/.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 @@ -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. + + + + diff --git a/lib/App/Racoco/Cli.rakumod b/lib/App/Racoco/Cli.rakumod index 62603ee..331cf14 100644 --- a/lib/App/Racoco/Cli.rakumod +++ b/lib/App/Racoco/Cli.rakumod @@ -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) { @@ -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) { @@ -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, @@ -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, :$raku-bin-dir); @@ -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); diff --git a/lib/App/Racoco/Coverable/CoverableOutliner.rakumod b/lib/App/Racoco/Coverable/CoverableOutliner.rakumod index b469fe0..e81f29a 100644 --- a/lib/App/Racoco/Coverable/CoverableOutliner.rakumod +++ b/lib/App/Racoco/Coverable/CoverableOutliner.rakumod @@ -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) diff --git a/lib/App/Racoco/CoveredLinesCollector.rakumod b/lib/App/Racoco/CoveredLinesCollector.rakumod index f001e47..047e0c3 100644 --- a/lib/App/Racoco/CoveredLinesCollector.rakumod +++ b/lib/App/Racoco/CoveredLinesCollector.rakumod @@ -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 } diff --git a/lib/App/Racoco/Precomp/PrecompSupplier.rakumod b/lib/App/Racoco/Precomp/PrecompSupplier.rakumod index ee6cc6f..e3dfe6f 100644 --- a/lib/App/Racoco/Precomp/PrecompSupplier.rakumod +++ b/lib/App/Racoco/Precomp/PrecompSupplier.rakumod @@ -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); diff --git a/lib/App/Racoco/Precomp/Precompiler.rakumod b/lib/App/Racoco/Precomp/Precompiler.rakumod index 9c21994..eb182d0 100644 --- a/lib/App/Racoco/Precomp/Precompiler.rakumod +++ b/lib/App/Racoco/Precomp/Precompiler.rakumod @@ -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; } diff --git a/lib/App/Racoco/ProjectName.rakumod b/lib/App/Racoco/ProjectName.rakumod index 985576c..a50c352 100644 --- a/lib/App/Racoco/ProjectName.rakumod +++ b/lib/App/Racoco/ProjectName.rakumod @@ -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 } diff --git a/lib/App/Racoco/RunProc.rakumod b/lib/App/Racoco/RunProc.rakumod index 9f28675..e9f7605 100644 --- a/lib/App/Racoco/RunProc.rakumod +++ b/lib/App/Racoco/RunProc.rakumod @@ -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 + } + } } diff --git a/lib/App/Racoco/X.rakumod b/lib/App/Racoco/X.rakumod index c89e935..c992fc7 100644 --- a/lib/App/Racoco/X.rakumod +++ b/lib/App/Racoco/X.rakumod @@ -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 /.precomp path or use --fix-compunit flag for the next ' ~ + 'RaCoCo launch to erase .precomp directory automatically.' } method backtrace() { '' } } diff --git a/t-resources/root-folder-backup/two-precomp-lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/.keep b/t-resources/root-folder-backup/fix-compunit/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF4/.keep similarity index 100% rename from t-resources/root-folder-backup/two-precomp-lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/.keep rename to t-resources/root-folder-backup/fix-compunit/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF4/.keep diff --git a/t-resources/root-folder/two-precomp-lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/.keep b/t-resources/root-folder-backup/fix-compunit/.precomp/current_compiler_id/.keep similarity index 100% rename from t-resources/root-folder/two-precomp-lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/.keep rename to t-resources/root-folder-backup/fix-compunit/.precomp/current_compiler_id/.keep diff --git a/t-resources/root-folder-backup/fix-compunit/M1.rakumod b/t-resources/root-folder-backup/fix-compunit/M1.rakumod new file mode 100644 index 0000000..ba9c332 --- /dev/null +++ b/t-resources/root-folder-backup/fix-compunit/M1.rakumod @@ -0,0 +1,3 @@ +sub m1() is export { + 'm1' +} \ No newline at end of file diff --git a/t-resources/root-folder-backup/fix-compunit/t/m1-test.t b/t-resources/root-folder-backup/fix-compunit/t/m1-test.t new file mode 100644 index 0000000..91ec4e3 --- /dev/null +++ b/t-resources/root-folder-backup/fix-compunit/t/m1-test.t @@ -0,0 +1,9 @@ +use Test; +use lib 'fix-compunit'; +use M1; + +plan 1; + +is m1, 'm1', 'm1 ok'; + +done-testing; diff --git a/t-resources/root-folder-backup/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 b/t-resources/root-folder-backup/lib/.precomp/current_compiler_id/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 similarity index 100% rename from t-resources/root-folder-backup/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 rename to t-resources/root-folder-backup/lib/.precomp/current_compiler_id/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 diff --git a/t-resources/root-folder-backup/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/this-from-module b/t-resources/root-folder-backup/lib/.precomp/current_compiler_id/B8/this-from-module similarity index 100% rename from t-resources/root-folder-backup/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/this-from-module rename to t-resources/root-folder-backup/lib/.precomp/current_compiler_id/B8/this-from-module diff --git a/t-resources/root-folder/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/this-from-module b/t-resources/root-folder-backup/two-precomp-lib/.precomp/current_compiler_id/.keep similarity index 100% rename from t-resources/root-folder/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/this-from-module rename to t-resources/root-folder-backup/two-precomp-lib/.precomp/current_compiler_id/.keep diff --git a/t-resources/root-folder/fix-compunit/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF4/.keep b/t-resources/root-folder/fix-compunit/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF4/.keep new file mode 100644 index 0000000..e69de29 diff --git a/t-resources/root-folder/fix-compunit/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/.keep b/t-resources/root-folder/fix-compunit/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/.keep new file mode 100644 index 0000000..e69de29 diff --git a/t-resources/root-folder/fix-compunit/M1.rakumod b/t-resources/root-folder/fix-compunit/M1.rakumod new file mode 100644 index 0000000..ba9c332 --- /dev/null +++ b/t-resources/root-folder/fix-compunit/M1.rakumod @@ -0,0 +1,3 @@ +sub m1() is export { + 'm1' +} \ No newline at end of file diff --git a/t-resources/root-folder/fix-compunit/t/m1-test.t b/t-resources/root-folder/fix-compunit/t/m1-test.t new file mode 100644 index 0000000..91ec4e3 --- /dev/null +++ b/t-resources/root-folder/fix-compunit/t/m1-test.t @@ -0,0 +1,9 @@ +use Test; +use lib 'fix-compunit'; +use M1; + +plan 1; + +is m1, 'm1', 'm1 ok'; + +done-testing; diff --git a/t-resources/root-folder/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 b/t-resources/root-folder/lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 similarity index 100% rename from t-resources/root-folder/lib/.precomp/7011F868022706D0DB123C03898593E0AB8D8AF3/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 rename to t-resources/root-folder/lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/B8/B8FF02892916FF59F7FBD4E617FCCD01F6BCA576 diff --git a/t-resources/root-folder/lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/B8/this-from-module b/t-resources/root-folder/lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/B8/this-from-module new file mode 100644 index 0000000..e69de29 diff --git a/t-resources/root-folder/two-precomp-lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/.keep b/t-resources/root-folder/two-precomp-lib/.precomp/9CD767C372539B56DF2683AC6D8FC078BDCD9795/.keep new file mode 100644 index 0000000..e69de29 diff --git a/t/01-paths.t b/t/01-paths.t index 966c517..18bc95d 100644 --- a/t/01-paths.t +++ b/t/01-paths.t @@ -6,7 +6,7 @@ use App::Racoco::TmpDir; plan 8; -my ($sources, $lib) = create-tmp-lib('racoco-tests'); +my ($sources, $lib) = TmpDir::create-tmp-lib('racoco-tests'); { my $racoco-path = racoco-path(:$lib); diff --git a/t/02-ext-proc.t b/t/02-ext-proc.t index 941245e..67e3a63 100644 --- a/t/02-ext-proc.t +++ b/t/02-ext-proc.t @@ -5,22 +5,37 @@ use App::Racoco::RunProc; use App::Racoco::TmpDir; use App::Racoco::Fixture; -plan 4; +plan 7; -my $sources = create-tmp-dir('racoco-tests'); +my $sources = TmpDir::create-tmp-dir('racoco-tests'); my $test-file = $sources.add('file'); { - my $result = RunProc.new.run('echo boom', out => $test-file.open(:w)); - ok $test-file.e, 'run echo into file'; - is $test-file.slurp.trim, 'boom', 'echo into file correct'; + my $out = $test-file.open(:w); + LEAVE { .close with $out } + my %vars = V1 => 'v1', V2 => 'v2'; + my $result = RunProc.new + .run(q/raku -e "say qq[vars: %*ENV{'V1'} %*ENV{'V2'}]"/, :$out, :%vars); + ok $test-file.e, 'run say into file'; + is $test-file.slurp.trim, 'vars: v1 v2', 'say into file with vars correct'; + is $result.exitcode, 0, 'exitcode 0'; +} + +{ + my $out = $test-file.open(:w); + LEAVE { .close with $out } + my $result = RunProc.new + .run(qq/raku -e "q[{$test-file}].IO.spurt(q[no vars and out])"/); + ok $test-file.e, 'run spurt into file'; + is $test-file.slurp.trim, 'no vars and out', + 'say into file without any params'; is $result.exitcode, 0, 'exitcode 0'; } { Fixture::suppressErr; LEAVE { Fixture::restoreErr } - nok RunProc.new.run('not-exists', :!err), 'run not-exists ok'; + nok RunProc.new.run(q/not-exists/, :!err), 'run not-exists ok'; } done-testing \ No newline at end of file diff --git a/t/03-tmp-file.t b/t/03-tmp-file.t index 59d4106..5f9c0d0 100644 --- a/t/03-tmp-file.t +++ b/t/03-tmp-file.t @@ -4,22 +4,22 @@ use App::Racoco::TmpDir; plan 9; -my $sources = create-tmp-dir('racoco-tests'); +my $sources = TmpDir::create-tmp-dir('racoco-tests'); ok $sources.e, 'create sources'; -my $sub-dir = register-dir($sources.add('sub-dir')); +my $sub-dir = TmpDir::register-dir($sources.add('sub-dir')); nok $sub-dir.e, 'register sub-dir'; $sub-dir.mkdir; ok $sub-dir.e, 'mkdir sub-dir'; -lives-ok { register-dir('not-exists') }, 'register not-exists'; +lives-ok { TmpDir::register-dir('not-exists') }, 'register not-exists'; -my $dir-with-file = create-dir($sources.add('dir-with-file')); +my $dir-with-file = TmpDir::create-dir($sources.add('dir-with-file')); $dir-with-file.add('file').spurt: ''; ok $dir-with-file.add('file').e, 'create dir-with-file/file'; -lives-ok { clean-up }, 'good clean-up'; +lives-ok { TmpDir::clean-up }, 'good TmpDir::clean-up'; nok $sub-dir.e, 'rmdir sub-dir'; nok $sources.e, 'rmdir sources'; diff --git a/t/04-precomp-lookup.t b/t/04-precomp-lookup.t index c4967f5..d0ea5ee 100644 --- a/t/04-precomp-lookup.t +++ b/t/04-precomp-lookup.t @@ -10,6 +10,8 @@ use App::Racoco::TmpDir; plan 9; +Fixture::restore-root-folder(); + my $sources = Fixture::root-folder(); my ($file-name, $lib, $lookup); @@ -22,7 +24,7 @@ sub setUp($file, $lib-name) { { setUp('Module.rakumod', 'lib'); my $expected = lib-precomp-path(:$lib) - .add('7011F868022706D0DB123C03898593E0AB8D8AF3') + .add(Fixture::compiler-id()) .add('B8').add('B8FF02892916FF59F7FBD4E617FCCD01F6BCA576'); my $actual = $lookup.lookup(:$file-name); isa-ok $actual, IO::Path, 'lookup is io'; @@ -43,7 +45,6 @@ sub setUp($file, $lib-name) { throws-like { $lookup.lookup(file-name => 'any.rakumod') }, App::Racoco::X::AmbiguousPrecompContent, 'two precomp contents', message => /$lib/; - } { @@ -52,9 +53,9 @@ sub setUp($file, $lib-name) { nok $actual.DEFINITE, 'cannot lookup .precomp dir'; my $precomp-path = lib-precomp-path(:$lib); - my $expected = $precomp-path.add('7011F868022706D0DB123C03898593E0AB8D8AF3') + my $expected = $precomp-path.add(Fixture::compiler-id()) .add('B8').add('B8FF02892916FF59F7FBD4E617FCCD01F6BCA576'); - LEAVE { App::Racoco::TmpDir::rmdir($precomp-path) } + LEAVE { TmpDir::rmdir($precomp-path) } $expected.parent.mkdir; $expected.spurt: ''; diff --git a/t/05-precomp-supplier.t b/t/05-precomp-supplier.t index 191692d..ca7406c 100644 --- a/t/05-precomp-supplier.t +++ b/t/05-precomp-supplier.t @@ -8,18 +8,20 @@ use App::Racoco::TmpDir; plan 3; +Fixture::restore-root-folder(); + my $sources = Fixture::root-folder(); my $lib = $sources.add('lib'); my $raku = 'raku'; my $proc = Fixture::fakeProc; my $module1-path = lib-precomp-path(:$lib) - .add('7011F868022706D0DB123C03898593E0AB8D8AF3').add('B8') + .add(Fixture::compiler-id()).add('B8') .add('B8FF02892916FF59F7FBD4E617FCCD01F6BCA576').IO; my $module2-path = our-precomp-path(:$lib).add('C4') .add('C42D08C62F336741E9DBBDC10EFA8A4673AA820F').IO; my $module3-path = our-precomp-path(:$lib).add('5F') .add('5FB62D3D27EB6AAE0FD30F0E99F9EB7D3907F2F8').IO; -register-dir($module3-path.parent); +TmpDir::register-dir($module3-path.parent); my $supplier = PrecompSupplierReal.new(:$lib, :$raku, :$proc); is $supplier.supply(:file-name), $module1-path, 'precomp ok'; diff --git a/t/06-precomp-hashcode-reader.t b/t/06-precomp-hashcode-reader.t index b075dcb..8f84821 100644 --- a/t/06-precomp-hashcode-reader.t +++ b/t/06-precomp-hashcode-reader.t @@ -7,10 +7,12 @@ use App::Racoco::Precomp::PrecompHashcodeReader; plan 1; +Fixture::restore-root-folder(); + my $reader = PrecompHashcodeReaderReal.new; my $path = lib-precomp-path(lib => Fixture::root-folder().add('lib')) - .add('7011F868022706D0DB123C03898593E0AB8D8AF3') + .add(Fixture::compiler-id()) .add('B8').add('B8FF02892916FF59F7FBD4E617FCCD01F6BCA576'); is $reader.read(:$path), '266B9F83542BC85F73639D2D300D0701AF14F9E5', diff --git a/t/08-coverable-outliner.t b/t/08-coverable-outliner.t index 53184a2..4e2da24 100644 --- a/t/08-coverable-outliner.t +++ b/t/08-coverable-outliner.t @@ -8,9 +8,11 @@ use App::Racoco::Fixture; plan 2; +Fixture::restore-root-folder(); + my $proc = RunProc.new; my $path = lib-precomp-path(lib => Fixture::root-folder().add('lib')) - .add('7011F868022706D0DB123C03898593E0AB8D8AF3') + .add(Fixture::compiler-id()) .add('B8').add('B8FF02892916FF59F7FBD4E617FCCD01F6BCA576'); my $outliner = CoverableOutlinerReal.new(:moar, :$proc); diff --git a/t/09-coverable-index.t b/t/09-coverable-index.t index 334610b..c16b763 100644 --- a/t/09-coverable-index.t +++ b/t/09-coverable-index.t @@ -5,6 +5,7 @@ use App::Racoco::Coverable::Coverable; use App::Racoco::Coverable::CoverableIndex; use App::Racoco::Paths; use App::Racoco::Fixture; +use App::Racoco::TmpDir; plan 6; @@ -55,7 +56,8 @@ my $index = CoverableIndexFile.new(:$lib); } { - lives-ok { CoverableIndexFile.new(:lib($*TMPDIR)) }, 'without index file' + my $lib = TmpDir::create-tmp-dir('lib'); + lives-ok { CoverableIndexFile.new(:$lib) }, 'without index file' } done-testing \ No newline at end of file diff --git a/t/14-reporter-basic.t b/t/14-reporter-basic.t index dccf52d..a641b5e 100644 --- a/t/14-reporter-basic.t +++ b/t/14-reporter-basic.t @@ -8,7 +8,7 @@ use App::Racoco::TmpDir; plan 5; -my ($sources, $lib) = create-tmp-lib('racoco-test'); +my ($sources, $lib) = TmpDir::create-tmp-lib('racoco-test'); my $report-path = report-basic-path(:$lib); my %coverable-lines = %{ @@ -76,7 +76,7 @@ my $report-expect = Report.new(fileReportData => ( } { - my ($, $lib) = create-tmp-lib('racoco-test-not-exists-report'); + my ($, $lib) = TmpDir::create-tmp-lib('racoco-test-not-exists-report'); throws-like { ReporterBasic.read(:$lib) }, App::Racoco::X::CannotReadReport, 'no report file, no reporter', message => /$lib/; } diff --git a/t/15-reporter-html.t b/t/15-reporter-html.t index 13120f3..f251643 100644 --- a/t/15-reporter-html.t +++ b/t/15-reporter-html.t @@ -74,7 +74,7 @@ do-test { ok report-basic-path(:$lib).e, 'basic report exists'; my $read-reporter = ReporterHtml.read(:$lib); ok $read-reporter.report eqv $report-expect, 'read correct data'; - App::Racoco::TmpDir::rmdir(report-html-data-path(:$lib)); + TmpDir::rmdir(report-html-data-path(:$lib)); }; do-test { @@ -106,7 +106,7 @@ do-test { } do-test { - my ($, $lib) = create-tmp-lib('racoco-test-not-exists-report'); + my ($, $lib) = TmpDir::create-tmp-lib('racoco-test-not-exists-report'); throws-like { ReporterHtml.read(:$lib) }, App::Racoco::X::CannotReadReport, 'no report, exception', message => /'lib'/; }; diff --git a/t/16-project-name.t b/t/16-project-name.t index 4d4e095..a1e4f65 100644 --- a/t/16-project-name.t +++ b/t/16-project-name.t @@ -10,7 +10,7 @@ plan 2; is project-name(lib => Fixture::root-folder().add('lib')), 'Test Project', 'project name from meta ok'; -is project-name(lib => create-tmp-dir('racoco-tests').add('lib')), 'racoco-tests', +is project-name(lib => TmpDir::create-tmp-dir('racoco-tests').add('lib')), 'racoco-tests', 'project name from path ok'; diff --git a/t/lib/App/Racoco/Fixture.rakumod b/t/lib/App/Racoco/Fixture.rakumod index 4b73366..9b8dd75 100644 --- a/t/lib/App/Racoco/Fixture.rakumod +++ b/t/lib/App/Racoco/Fixture.rakumod @@ -42,6 +42,10 @@ our sub fakePath($path, :$modified) { $result } +our sub compiler-id() { + $*RAKU.compiler.id +} + my role TestKeyValueStore { has %.mock; multi method add($key, $value) { %!mock{$key} = $value } @@ -94,7 +98,7 @@ our sub restoreErr() { } my $out; -my @out-collect = []; +my @out-collect; our sub capture-out() { $out = $*OUT; $*OUT = (class :: is IO::Handle { @@ -121,12 +125,16 @@ sub cp($from, $to) { $from.copy($to); } -sub create($create) { +sub make-dir($create is copy) { + if ($create.basename eq 'current_compiler_id') { + $create = $create.parent.add(compiler-id()); + } $create.mkdir; + $create } -sub copy($from, $to) { - create($to); +sub copy($from, $to is copy) { + $to = make-dir($to); for $from.dir() -> $ls-from { my $ls-to = $to.add($ls-from.basename); if $ls-from.d { @@ -144,7 +152,7 @@ our sub need-restore-root-folder() { our sub restore-root-folder() { my $to = 't-resources/root-folder'.IO; my $from = 't-resources/root-folder-backup'.IO; - App::Racoco::TmpDir::rmdir($to); + TmpDir::rmdir($to); copy($from, $to); } diff --git a/t/lib/App/Racoco/TmpDir.rakumod b/t/lib/App/Racoco/TmpDir.rakumod index e63cb24..d074341 100644 --- a/t/lib/App/Racoco/TmpDir.rakumod +++ b/t/lib/App/Racoco/TmpDir.rakumod @@ -1,27 +1,27 @@ -unit module App::Racoco::TmpDir; +unit module TmpDir; my @tmp-dirs; -our sub create-tmp-dir($name --> IO::Path:D) is export { +our sub create-tmp-dir($name --> IO::Path:D) { mkdir register-dir($*TMPDIR.add($name)) } -our sub create-tmp-lib($name) is export { +our sub create-tmp-lib($name) { my $dir = create-tmp-dir($name); my $lib = create-dir($dir.add('lib')); $dir, $lib } -our sub create-dir(IO() $path --> IO::Path:D) is export { +our sub create-dir(IO() $path --> IO::Path:D) { mkdir register-dir($path) } -our sub register-dir(IO() $path --> IO::Path:D) is export { +our sub register-dir(IO() $path --> IO::Path:D) { @tmp-dirs.push: $path; $path } -our sub clean-up() is export { +our sub clean-up() { for @tmp-dirs.reverse -> $path { rmdir($path) } diff --git a/xt/12-covered-collector.t b/xt/12-covered-collector.t index 7872787..5d21a8a 100644 --- a/xt/12-covered-collector.t +++ b/xt/12-covered-collector.t @@ -25,8 +25,7 @@ sub do-test(&code) { do-test { my $proc = Fixture::fakeProc; my $collector = CoveredLinesCollector.new(:$exec, :$proc, :$lib); - $collector.collect(); - is $proc.c, \("MVM_COVERAGE_LOG=$coverage-log prove6"), 'run test ok'; + lives-ok { $collector.collect() }, 'collect lives ok'; }; do-test { diff --git a/xt/17-cli.t b/xt/17-cli.t index 6bf05d9..337c551 100644 --- a/xt/17-cli.t +++ b/xt/17-cli.t @@ -6,8 +6,9 @@ use App::Racoco::Fixture; use App::Racoco::Paths; use App::Racoco::X; -plan 13; +plan 14; +Fixture::restore-root-folder(); Fixture::capture-out; END { Fixture::restore-out } @@ -46,7 +47,7 @@ do-test { }; do-test { - throws-like { App::Racoco::Cli::MAIN(exec => False) }, App::Racoco::X::CannotReadReport, + throws-like { App::Racoco::Cli::MAIN(:!exec) }, App::Racoco::X::CannotReadReport, 'no report, exception', message => /'lib'/; }; @@ -58,14 +59,15 @@ do-test { }; do-test { - App::Racoco::Cli::MAIN(silent => True); + App::Racoco::Cli::MAIN(:silent); is Fixture::get-out, 'Coverage: 62.5%', 'pass silent'; }; do-test { App::Racoco::Cli::MAIN(); App::Racoco::Cli::MAIN(:append, exec => 'echo "foo"'); - is Fixture::get-out, "Coverage: 62.5%\n\nCoverage: 62.5%", 'pass append'; + my $on-screen = Fixture::get-out().lines.map(*.trim).grep(*.chars).join(' '); + is $on-screen, "Coverage: 62.5% Coverage: 62.5%", 'pass append'; }; do-test { @@ -77,4 +79,13 @@ do-test { ok Fixture::get-out.contains(report-html-path(:lib)), 'pass html'; }; +do-test { + App::Racoco::Cli::MAIN( + lib => 'fix-compunit', + :fix-compunit, + exec => 'prove6 fix-compunit/t' + ); + is Fixture::get-out.trim, 'Coverage: 100%', 'two precomp with fix-compunit'; +} + done-testing \ No newline at end of file