Skip to content

Commit

Permalink
Test cli output
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Dec 14, 2016
1 parent ecc71d2 commit fc1ab03
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/squaretag
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use Getopt::Long

( my $app = $0 ) =~ s;.*/;;;

run(@ARGV) if !caller;
if ( !caller ) {
run(@ARGV);
exit 0;
}

sub run {

Expand Down Expand Up @@ -74,15 +77,15 @@ sub run {
}

if ( my $check = $modes{$mode}->{check} ) {
$check->(\%options,@_);
$check->( \%options, @_ );
}

$cmd->( \%options, @_ );
}
else {
pod2usage(1);
}
exit 0;
return;
}

sub add_tags { modify( shift, '+', @_ ) }
Expand Down
48 changes: 48 additions & 0 deletions t/08cli.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/perl

use strict;
use warnings;

use FindBin '$Bin';
use Test::More;
use File::Temp 'tempdir';

require_ok("$Bin/../bin/squaretag");

my $tempdir = tempdir( CLEANUP => 1 );
chdir $tempdir;

my $fh;
open($fh,'>','file.txt');

sub test_output {
my ( $args, $expect, $name ) = @_;
my $got;
open( my $fh, '>', \$got );
my $old = select($fh);
eval { run(@$args) };
select($old);
return is( $got, $expect, $name );
}

test_output [qw(add -v foo file.txt)], <<EOF;
file.txt -> file[foo].txt
EOF

test_output [qw(rename -v foo bar file[foo].txt)], <<EOF;
file[foo].txt -> file[bar].txt
EOF

test_output [qw(list file[bar].txt)], <<EOF;
bar 1
EOF

test_output [qw(search bar file[bar].txt)], <<EOF;
file[bar].txt
EOF

test_output [qw(clear -v file[bar].txt)], <<EOF;
file[bar].txt -> file.txt
EOF

done_testing;

0 comments on commit fc1ab03

Please sign in to comment.