GithubHelp home page GithubHelp logo

perl5-test-applify's Introduction

NAME

Test::Applify - Testing Applify scripts

Build Status Coverage Status Kritika Analysis Status CPAN version

SYNOPSIS

use Test::More;
use Test::Applify 'applify_ok';

my $t = Test::Applify->new('./bin/app.pl');
$t->help_ok(qr/basic/)
  ->documentation_ok
  ->version_ok('1.0.999');
$t->is_option($_) for qw{mode input};
$t->is_required_option($_) for qw{input};

my $app1 = $t->app_instance(qw{-input strings.txt});
is $app1->mode, 'basic', 'basic mode is default';

my $app2 = $t->app_instance(qw{-mode expert -input strings.txt});
is $app2->mode, 'expert', 'expert mode enabled';
is $app2->input, 'strings.txt', 'reading strings.txt';
$t->run_instance_ok($app2);

my $inlineapp = applify_ok("use Applify; app { print 'hello world!'; 0;};");
$t = Test::Applify->new($inlineapp);

DESCRIPTION

Test::Applify is a test agent to be used with Test::More to test Applify scripts. To run your tests use prove.

$ prove -l -v t

Avoid testing the Applify code for correctness, it has its own test suite. Instead, test for consistency of option behaviour, defaults and requiredness, the script is compiled and that attributes and methods of the script behave with different inputs.

The aim is to remove repetition of multiple blocks to retrieve instances and checks for success of do.

my $app = do 'bin/app.pl'; ## check $@ and return value
{
  local @ARGV = qw{...};
  my $instance = $app->_script->app;
  # more tests.
}

EXPORTED FUNCTIONS

applify_ok

use Test::Applify 'applify_ok';
my $inlineapp = applify_ok("use Applify; app { print 'Hello world!'; 0;};");
my $t = Test::Applify->new($inlineapp);

my $helloapp = applify_ok("use Applify; app { print 'Hello $_[1]!'; 0;};",
                          \@ARGV, 'hello app');
my $t = Test::Applify->new($helloapp);

Utility function that wraps "eval" in perlfunc and runs the same tests as "new".

This function must be imported.

applify_subcommands_ok

use Test::Applify 'applify_subcommands_ok';
my $subcmds = applify_subcommands_ok($code);
foreach my $app(@$subcmds){
  Test::Applify->new($app)->help_ok
    ->documentation_ok
    ->version_ok('1')
    ->is_required_option('global_option')
}

Like "applify_ok", but creates each of the subcommands and return in an array reference.

METHODS

app

my $t   = Test::Applify->new('./bin/app.pl');
my $app = $t->app;

Access to the application.

N.B. The removal of . from @INC requires relative paths to start with ./. See link for further information https://goo.gl/eJ6k9E

app_script

my $script = $t->app_script;
isa_ok $script, 'Applify', 'the Applify object';

Access to the Applify object.

app_instance

my $safe  = $t->app_instance(qw{-opt value -mode safe});
is $safe->mode, 'safe', 'will run in safe mode';
my $risky = $t->app_instance();
is $risky->mode, 'expert', 'expert mode is the default';

Create an instance of the application class, which will be the contents of the Applify script created. The array passed will be turned into @ARGV as if those options had been passed on the command line.

can_ok

$t->can_ok(qw{mode input});

Test for the presence of methods that the script has.

documentation_ok

$t->documentation_ok;

Test the documentation.

extends_ok

$t->extends_ok('Parent::Class');
$t->extends_ok('Parent::Class', 'object name');

Test the inheritance.

help_ok

my $help = $t->help_ok;

Test and access the help for the script.

is_option

$t->is_option('mode');
$t->is_option($_) for qw{mode input};

Test for the presence of an option with the supplied name

is_required_option

$t->is_required_option('input');

Test that the option is a required option.

new

my $t = Test::Applify->new('./script.pl');
# instance for the 'list' subcommand
my $t = Test::Applify->new('./script.pl', 'list');

Instantiate a new test instance for the supplied script name.

run_instance_ok

my $t = Test::Applify->new('./script.pl');
my $app = $t->app_instance(qw{-mode expert});
is $app->mode, 'expert', 'everyone is an expert';
my ($retval, $stdout, $stderr, $exited) = $t->run_instance_ok($app);

Call run on the Applify application class instance (execute the app {} block). Returns a list of scalars which are:

retval - the return value of the app block

This is undef when "die" in perlfunc called

stdout - the content that was printed to STDOUT during the run
stderr - "$@" in perlvar or the content that was printed to STDERR during the run
exit - whether the code exited

run_ok

my $t = Test::Applify->new('./script.pl');
my ($exit, $stdout, $stderr, $retval) = $t->run_ok(qw{-mode expert});

Same as "run_instance_ok", but less code.

subcommand_ok

my $subcommand = $t->subcommand_ok('list');

Test that the subcommand computed from @ARGV matches the supplied subcommand.

version_ok

$t->version_ok('1.0.999');

Test that the version matches the supplied version.

perl5-test-applify's People

Contributors

kiwiroy avatar

Stargazers

Jan Henning Thorsen avatar

Watchers

Jan Henning Thorsen avatar  avatar James Cloos avatar

perl5-test-applify's Issues

Test suite started to fail

The test suite started to fail like this:

PERL_DL_NONLAZY=1 "/usr/perl5.18.4p/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-basic.t ............... ok
Can't locate object method "_attr_to_option" via package "Applify" at /home/cpansand/.cpan/build/2019110318/Test-Applify-0.06-11/blib/lib/Test/Applify.pm line 122.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 25 just after 35.
t/applify-ok-subcommand.t ..
Dubious, test returned 25 (wstat 6400, 0x1900)
All 35 subtests passed
Can't locate object method "_attr_to_option" via package "Applify" at /home/cpansand/.cpan/build/2019110318/Test-Applify-0.06-11/blib/lib/Test/Applify.pm line 110.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 25 just after 16.
t/applify-ok.t .............
Dubious, test returned 25 (wstat 6400, 0x1900)
All 16 subtests passed
Can't locate object method "_attr_to_option" via package "Applify" at /home/cpansand/.cpan/build/2019110318/Test-Applify-0.06-11/blib/lib/Test/Applify.pm line 110.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 25 just after 11.
t/basic.t ..................
Dubious, test returned 25 (wstat 6400, 0x1900)
All 11 subtests passed
Can't locate object method "_attr_to_option" via package "Applify" at /home/cpansand/.cpan/build/2019110318/Test-Applify-0.06-11/blib/lib/Test/Applify.pm line 110.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 25 just after 13.
t/file.t ...................
Dubious, test returned 25 (wstat 6400, 0x1900)
All 13 subtests passed

#   Failed test 'empty stdout'
#   at t/run-ok.t line 219.
#          got: 'extra: -verbose
# verbosely: -verbose
# verbose: 1
# '
#     expected: 'verbose: 1
# '

#   Failed test 'empty stdout'
#   at t/run-ok.t line 227.
#          got: 'extra: -verbose here
# verbosely: -verbose here
# verbose: 1
# '
#     expected: 'extra: here
# verbosely: here
# verbose: 1
# '
# Looks like you failed 2 tests of 153.   
t/run-ok.t .................
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/153 subtests
t/subclass.t ............... ok

Statistical analysis suggests that there are no more pass reports if Applify 0.17 is installed (@jhthorsen: FYI). See http://analysis.cpantesters.org/solved?distv=Test-Applify-0.06#mod%3AApplify

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.