<commit_before>use v6;
use Test;

sub throws_like($code, $ex_type, *%matcher) {
    if $code ~~ Callable {
        $code()
    } else {
        eval $code;
    }
    ok 0, 'code died';
    skip 'Code did not die, can not check exception', 1 + %matcher.elems;
    CATCH {
        default {
            ok 1, 'code died';
            my $type_ok = $_.WHAT === $ex_type;
            ok $type_ok , "right exception type ({$ex_type.^name})";
            if $type_ok {
                for %matcher.kv -> $k, $v {
                    my $got = $_."$k"();
                    my $ok = $got ~~ $v,;
                    ok $ok, ".$k matches $v";
                    unless $ok {
                        diag "Got:      $got\n"
                            ~"Expected: $v";

                    }
                }
            } else {
                diag "Got:      {$_.WHAT.gist}\n"
                    ~"Expected: {$ex_type.gist}";
                skip 'wrong exception type', %matcher.elems;
            }
        }
    }
}
<commit_msg>even nicer test output<commit_after>use v6;
use Test;

sub throws_like($code, $ex_type, *%matcher) {
    my $msg;
    if $code ~~ Callable {
        $msg = 'code dies';
        $code()
    } else {
        $msg = "'$code' died";
        eval $code;
    }
    ok 0, $msg;
    skip 'Code did not die, can not check exception', 1 + %matcher.elems;
    CATCH {
        default {
            ok 1, $msg;
            my $type_ok = $_.WHAT === $ex_type;
            ok $type_ok , "right exception type ({$ex_type.^name})";
            if $type_ok {
                for %matcher.kv -> $k, $v {
                    my $got = $_."$k"();
                    my $ok = $got ~~ $v,;
                    ok $ok, ".$k matches $v";
                    unless $ok {
                        diag "Got:      $got\n"
                            ~"Expected: $v";

                    }
                }
            } else {
                diag "Got:      {$_.WHAT.gist}\n"
                    ~"Expected: {$ex_type.gist}";
                skip 'wrong exception type', %matcher.elems;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.14352941176470588, 'fraction_numerical': 0.0037647058823529413, 'mean_word_length': 1.0521235521235521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2602266', 'n_tokens_mistral': 695, 'n_tokens_neox': 653, 'n_words': 173}