Skip to content

Commit

Permalink
Bump minimum required Perl version to 5.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Henning Thorsen committed Jul 12, 2015
1 parent 9668305 commit 5ac4f58
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 186 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@
Revision history for perl distribution Applify

0.11 Not Released
- Bump minimum required Perl version to 5.10.1
- AUTOLOAD does not work on Perl 5.10.1

0.10 2015-04-23T10:22:16+0200
- Add support for option(..., alias => [...])

Expand Down
1 change: 1 addition & 0 deletions cpanfile
@@ -1,4 +1,5 @@
# You can install this projct with curl -L http://cpanmin.us | perl - https://github.com/jhthorsen/applify/archive/master.tar.gz
requires "perl" => "5.010001";
requires "Cwd" => "3.31",
requires "File::Basename" => "2.70",
requires "Getopt::Long" => "2.38",
Expand Down
27 changes: 27 additions & 0 deletions t/Helper.pm
@@ -0,0 +1,27 @@
package t::Helper;

sub import {
my $caller = caller;

eval <<"HERE" or die $@;
package $caller;
use warnings;
use strict;
use Test::More;
1;
HERE

*{"$caller\::run_method"} = sub {
my ($thing, $method, @args) = @_;
local *STDOUT;
local *STDERR;
my $stdout = '';
my $stderr = '';
open STDOUT, '>', \$stdout;
open STDERR, '>', \$stderr;
my $ret = eval { $thing->$method(@args) };
return $@ || $stdout, $@ || $stderr, $ret;
};
}

1;
18 changes: 18 additions & 0 deletions t/autoload.t
@@ -0,0 +1,18 @@
use warnings;
use strict;
use Test::More;

plan skip_all => 'AUTOLOAD does not work on 5.10.1' unless eval 'require 5.12.0;1';

my $app = eval <<"HERE" or die $@;
package main;
sub not_app_method { 1 }
use Applify;
sub bar { 1 }
sub AUTOLOAD { 'Autoloaded' }
app { 0 };
HERE

is eval { $app->i_am_autoloaded }, 'Autoloaded', 'AUTOLOAD works' or diag $@;

done_testing;
186 changes: 0 additions & 186 deletions t/basic.t

This file was deleted.

17 changes: 17 additions & 0 deletions t/example-test1.t
@@ -0,0 +1,17 @@
use t::Helper;

my $app = do 'example/test1.pl';
my $script = $app->_script;

isa_ok($script, 'Applify');
can_ok($app, qw/ input_file output_dir dry_run generate_exit_value /);

run_method($app, 'run');
is($@, "Required attribute missing: --dry-run\n", '--dry-run missing');

is($app->dry_run, undef, '--dry-run is not set');
$app->dry_run(1);
is($app->dry_run, 1, '--dry-run was set');


done_testing;
39 changes: 39 additions & 0 deletions t/extends.t
@@ -0,0 +1,39 @@
use warnings;
use strict;

package BaseClass;
sub meta {'i am not moose'}

# Sub::Name does something strange on 5.10.1
# which cause this test to die on cleanup
$INC{'App/FatPacker/Trace.pm'} = __FILE__;

my $app = eval <<"HERE" or die $@;
package main;
sub not_app_method { 1 }
use Applify;
sub app::foo { 1 }
sub bar { 1 }
sub AUTOLOAD { 'Autoloaded' }
extends 'BaseClass';
app { 0 };
HERE

package Test;
use Test::More;
my $script = $app->_script;

ok !app->can('foo'), 'foo() was removed from app:: namespace';
ok !main->can('bar'), 'bar() was removed from main:: namespace';
ok !!main->can('not_app_method'), 'not_app_method() was not removed from main:: namespace';
ok !!$app->can('foo'), '...and into the $app namespace';
ok !$app->can('not_app_method'), 'not_app_method() was not applied to app class';
ok !$app->can('app'), 'app() was not applied to app class';
ok !$app->can('option'), 'option() was not applied to app class';
ok !$app->can('documentation'), 'documentation() was not applied to app class';
ok !$app->can('version'), 'version() was not applied to app class';
isa_ok $script, 'Applify';
can_ok $script, qw( option app documentation version options new print_help import );
is $script->{caller}->[0], 'main', 'called from main::';

done_testing;
54 changes: 54 additions & 0 deletions t/help.t
@@ -0,0 +1,54 @@
use t::Helper;

my $app = eval 'use Applify; app {0};' or die $@;
my $script = $app->_script;

$script->option(str => foo_bar => 'Foo can something');
$script->option(str => foo_2 => 'foo_2 can something else', 42);
$script->option(str => foo_3 => 'foo_3 can also something', 123, required => 1);

my $application_class = $script->_generate_application_class(sub { });
like $application_class, qr{^Applify::__ANON__2__::}, 'generated application class';
can_ok $application_class, qw( new run _script foo_bar foo_2 foo_3 );

is_deeply [$script->_default_options], [qw( help )], 'default options';
is + (run_method($script, 'print_help'))[0], <<'HERE', 'print_help()';
Usage:
--foo-bar Foo can something
--foo-2 foo_2 can something else
* --foo-3 foo_3 can also something
--help Print this help text
HERE

eval { $script->documentation(undef) };
like $@, qr{Usage: documentation }, 'need to give documentation(...) a true value';
is $script->documentation('Applify'), $script, 'documentation(...) return $self on set';
is $script->documentation, 'Applify', 'documentation() return what was set';

$script->documentation(__FILE__)->version('1.23');
is_deeply [$script->_default_options], [qw( help man version )], 'default options after documentation() and version()';
is + (run_method($script, 'print_help'))[0], <<'HERE', 'print_help()';
dummy synopsis...
Usage:
--foo-bar Foo can something
--foo-2 foo_2 can something else
* --foo-3 foo_3 can also something
--help Print this help text
--man Display manual for this application
--version Print application name and version
HERE

done_testing;

__END__
=head1 SYNOPSIS
dummy synopsis...
=cut

0 comments on commit 5ac4f58

Please sign in to comment.