### ----------------------------------------------------
### -- Code::Coverage
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: xt/02-buildplan.rakutest
### ----------------------------------------------------
use Test;

use Code::Coverage;

plan 10;

my $tester := $*PROGRAM.sibling("buildplan.raku").absolute;

my $cc := Code::Coverage.new(
  targets => "BUILDPLAN",
  runners => $*PROGRAM.sibling("buildplan.raku").absolute,
  extra   => "-I.",
);
is $cc.coverables.values.head.line-numbers,
  "1 27 29 33 34 43 44 53 54 58 61 62 65 72 73 74 78 112 117 118 120 121 123 124 130 131 137 141 143 144 146 147 149 150 152 153 155 156 157 160 162 164 170 174 177 181 182 185",
  "are the line numbers ok";

$cc.run;
is $cc.out, Q:to/OUT/, "out on first run ok";
class Code::Coverage BUILDPLAN:
 0 nqp::getattr(obj,Code::Coverage,'@!targets') = :$targets if possible
 1 nqp::getattr(obj,Code::Coverage,'@!runners') = :$runners if possible
 2 nqp::getattr(obj,Code::Coverage,'@!extra') = :$extra if possible
 3 nqp::getattr(obj,Code::Coverage,'$!repo') = :$repo if possible
 4 nqp::getattr(obj,Code::Coverage,'$!tmpdir') = :$tmpdir if possible
 5 nqp::getattr(obj,Code::Coverage,'$!slug') = :$slug if possible
 6 nqp::getattr(obj,Code::Coverage,'$!keep') = :$keep if possible
 7 nqp::getattr(obj,Code::Coverage,'$!repo') = execute-code() if not set
 8 nqp::getattr(obj,Code::Coverage,'$!tmpdir') = execute-code() if not set
 9 nqp::getattr(obj,Code::Coverage,'$!slug') = "code-coverage-" if not set
10 vivify nqp::getattr(obj,Code::Coverage,'@!targets') if part of a mixin
11 vivify nqp::getattr(obj,Code::Coverage,'@!runners') if part of a mixin
12 vivify nqp::getattr(obj,Code::Coverage,'@!extra') if part of a mixin
13 vivify nqp::getattr(obj,Code::Coverage,'$!keep') if part of a mixin
14 vivify nqp::getattr(obj,Code::Coverage,'%!coverables') if part of a mixin
15 vivify nqp::getattr(obj,Code::Coverage,'$!num-coverable-lines') if part of a mixin
16 vivify nqp::getattr(obj,Code::Coverage,'%!covered') if part of a mixin
17 vivify nqp::getattr(obj,Code::Coverage,'@!out') if part of a mixin
18 vivify nqp::getattr(obj,Code::Coverage,'@!err') if part of a mixin
19 call obj.Code::Coverage::TWEAK
OUT
is $cc.err, "", "err on first run ok";
is $cc.covered.values.head,
  "1 21 27 28 29 33 34 53 54 58 61 62 65 72 73 74 78 112 113 114 115 117 118 121 124 131 141 144 147 177 181 182 185",
  "is the first coverage ok";

$cc.run(42);
is $cc.out, Q:to/OUT/, "out on second run ok";
class Telemetry BUILDALLPLAN:
 0 nqp::getattr(obj,Telemetry,'$!message') = :$message if possible
OUT
is $cc.err, "", "err on second run ok";
is $cc.covered.values.head,
  "1 21 27 28 29 33 34 43 44 53 54 58 61 62 65 72 73 74 78 112 113 114 115 117 118 121 124 131 141 144 147 177 181 182 185",
  "is the second coverage ok";

is $cc.missed.values.head,
  "120 123 130 137 143 146 149 150 152 153 155 156 157 160 162 164 170 174",
  "is missed ok";

my $key := $cc.keys.head;
is $cc.coverage{$key}, "62.50%", "is the coverage ok";

is $cc.annotated($key).lines(:!chomp)>>.substr(2).join,
  $cc.source($key).slurp,
  'did the annotated file match the original';

# vim: expandtab shiftwidth=4


