Apache-Logmonster

 view release on metacpan or  search on metacpan

t/Utility.t  view on Meta::CPAN


use strict;
#use warnings;

use lib "lib";

use Cwd;
use English qw( -no_match_vars );
use Test::More;

if ( $OSNAME =~ /cygwin|win32|windows/i ) {
   plan skip_all => "no windows support";
};

my $deprecated = 0;    # run the deprecated tests.
my $network    = 0;    # run tests that require network
$network = 1 if $OSNAME =~ /freebsd|darwin/;
my $r;

use_ok('Apache::Logmonster');
use_ok('Apache::Logmonster::Utility');

# let the testing begin
my $monster = Apache::Logmonster->new();
my $log = my $util = Apache::Logmonster::Utility->new();
ok( defined $util, 'get Apache::Logmonster::Utility object' );
isa_ok( $util, 'Apache::Logmonster::Utility' );

# for internal use
if ( -e "Utility.t" ) { chdir "../"; }

# we need this stuff during subsequent tests
my $debug = 0;
my ($cwd) = cwd =~ /^([\/\w\-\s\.]+)$/;       # get our current directory

print "\t\twd: $cwd\n" if $debug;

my $tmp = "$cwd/t/trash";
mkdir $tmp, 0755;
if ( ! -d $tmp ) {
    $util->mkdir_system( dir => $tmp, fatal => 0 );
};
skip "$tmp dir creation failed!\n", 2 if ( ! -d $tmp );
ok( -d $tmp, "temp dir: $tmp" );
ok( $util->syscmd( "cp TODO $tmp/", fatal => 0 ), 'cp TODO' );


# ask - asks a question and retrieves the answer
SKIP: {
    skip "annoying", 4 if 1 == 1;
    skip "ask is an interactive only feature", 4 unless $util->is_interactive;
    ok( $r = $util->ask( 'test yes ask',
            default  => 'yes',
            timeout  => 5
        ),
        'ask, proper args'
    );
    is( lc($r), "yes", 'ask' );
    ok( $r = $util->ask( 'any (non empty) answer' ), 'ask, tricky' );

    # multiline prompt
    ok( $r = $util->ask( 'test any (non empty) answer',
            default  => 'just hit enter',
        ),
        'ask, multiline'



( run in 1.408 second using v1.01-cache-2.11-cpan-39bf76dae61 )