Gen::T...Result(3pm)

πŸ“¦
version 0.06 Β· 2 versions
  • 0.06 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.05 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ Gen::Test::Rinci::FuncResult πŸ’…

okay so bestie, this page is the manual for Gen::Test::Rinci::FuncResult (yes the terminal chops it down to Gen::T...Result(3pm), that's just the header being dramatic) β€” and it's about generating a test function for a function. iykyk. 🌸


✨ VERSION ✨

This document describes version 0.06 of Gen::Test::Rinci::FuncResult (from Perl distribution Gen-Test-Rinci-FuncResult), released on 2017-07-11. she's a little vintage, she's still iconic. πŸ‘‘


🌈 SYNOPSIS 🌈

use Gen::Test::Rinci::FuncResult qw(gen_test_func);
use Test::More;

sub divide {
    my %args = @_;
    my ($a, $b) = ($args{a}, $args{b});
    return [500, "undefined"] if $a == 0 && $b == 0;
    [200, "OK", $a/$b];
}

gen_test_func(name => 'test_divide', func => \&divide);

test_divide(args=>{a=>6, b=>3}, result=>2);
test_divide(args=>{a=>6, b=>0}, dies=>1);
test_divide(args=>{a=>0, b=>0}, status=>500);
done_testing;

like… look at her go. ✨ you write ONE test-generator call and then you just keep calling the generated function with vibes and args. obsessed.


πŸ’œ DESCRIPTION πŸ’œ

ngl the original page leaves this section completely empty β€” no cap, there's literally nothing here before FUNCTIONS starts. so consider this the aesthetic whitespace moment of the manpage. πŸ¦‹ the actual tea is right below. πŸ‘‡


πŸ”₯ FUNCTIONS πŸ”₯

🌟 gen_test_func

Usage:

gen_test_func(%args) -> [status, msg, result, meta]

Generate a test function for a function.

okay so here's the lore, bestie: this function (let's call her A) will generate a function (let's call her B). it's giving meta. it's giving function factory. πŸ’…

A accepts, among others, the name or the reference to the function that you want to test (T) and the name of the generated function, B.

B will run T once with some specified arguments, catch exception, and test its result. The result is expected to be an enveloped result (see the documentation of "Rinci::function" for more details about enveloped result). 🫢

B will accept the following arguments:

  • name (str)

Name of the test. Will default to "T (ARGS...)" to show the name of the target function and the arguments that it is called with.

  • args (hash or array)

Argument to feed to function T.

  • dies (bool, default => 0)

Whether function T should die when run. If set to 1, further tests will not be done except the test that function dies.

  • status (int, default => 200)

Will test the result's status code.

  • result (any)

If specified, will test the actual result of the function.

  • run (code)

Instead of running function T with "args", will execute this code instead.

  • posttest (code)

Run this code for additional tests.

Todo:

  • Handle function with "result_naked" => 1.

This function is not exported by default, but exportable. (so yes bestie, you do have to ask for her by name. πŸ™ˆ)

Arguments ('*' denotes required arguments):

  • func* => code β€” Target function to test.
  • install => bool (default: 1) β€” Whether to install the function.
  • name* => str β€” Name of the test function to generate (B). Can be fully qualified, e.g. "Pkg::SubPkg::funcname" or unqualified "funcname" (where the package will be taken from the "package" argument). Relevant for when installing the function.
  • package => any β€” Perl package to put this function in. Relevant only when installing the function.

Returns an enveloped result (an array). πŸ’–

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)


🧚 FAQ 🧚

okay so this section is empty in the original β€” no questions, no answers, just vibes. 🌸 she said "ask me nothing." iconic behaviour honestly.


🌐 HOMEPAGE 🌐

Please visit the project's homepage at <https://metacpan.org/release/Gen-Test-Rinci-FuncResult>.


πŸ“¦ SOURCE πŸ“¦

Source repository is at <https://github.com/perlancar/perl-Gen-Test-Rinci-FuncResult>.


πŸ’€ BUGS πŸ’€

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Gen-Test-Rinci-FuncResult>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. (fr fr, a failing test is worth a thousand "it doesn't work" messages. 🫢)


πŸ‘€ SEE ALSO πŸ‘€

Rinci


πŸ’Œ AUTHOR πŸ’Œ

perlancar <perlancar@cpan.org>


This software is copyright (c) 2017, 2015, 2014, 2013 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page, bestie!! πŸŽ€ this one came to you courtesy of perl v5.34.0 and it was last touched on 2022-06-14 β€” go forth and generate some test functions, you absolute main character. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from