[Bps-public-commit] r17062 - in Prophet/trunk: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Dec 2 06:47:16 EST 2008


Author: sunnavy
Date: Tue Dec  2 06:47:15 2008
New Revision: 17062

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/t/aliases.t

Log:
 r17979 at sunnavys-mb:  sunnavy | 2008-12-02 19:35:44 +0800
 more aliases tests


Modified: Prophet/trunk/t/aliases.t
==============================================================================
--- Prophet/trunk/t/aliases.t	(original)
+++ Prophet/trunk/t/aliases.t	Tue Dec  2 06:47:15 2008
@@ -11,16 +11,70 @@
 use_ok('Prophet::Config');
 my $aliases = Prophet::Config->new(app_handle =>
         Prophet::CLI->new->app_handle)->aliases;
-# default aliases is empty
-is_deeply( $aliases, {} );
 
-my $out = run_command( 'aliases',
-    '--add', q{pull -a=pull --all},
+is_deeply( $aliases, {}, 'initial alias is empty' );
+
+my @cmds = (
+    {
+        cmd => [ '--add', 'pull -a=pull --all' ],
+        output  => qr/added alias 'pull -a = pull --all/,
+        comment => 'add a new alias',
+    },
+    {
+        cmd => [ '--add', 'pull -a=pull --all' ],
+        output  => qr/alias 'pull -a = pull --all' isn't changed, won't update/,
+        comment => 'add the same alias will not change anything',
+    },
+    {
+
+        # this alias is bad, please don't use it in real life
+        cmd => [ '--set', 'pull -a=pull --local' ],
+        output =>
+          qr/changed alias 'pull -a' from 'pull --all' to 'pull --local'/,
+        comment =>
+          q{changed alias 'pull -a' from 'pull --all' to 'pull --local'},
+    },
+    {
+        cmd     => [ '--delete', 'pull -a' ],
+        output  => qr/deleted alias 'pull -a = pull --local'/,
+        comment => q{deleted alias 'pull -a = pull --local'},
+    },
+    {
+        cmd => [ '--add', 'pull -a=pull --all' ],
+        output  => qr/added alias 'pull -a = pull --all/,
+        comment => 'readd a new alias',
+    },
+    {
+        cmd => [ '--add', 'pull -l=pull --local' ],
+        output  => qr/added alias 'pull -l = pull --local/,
+        comment => 'add a new alias',
+    },
 );
 
-like($out, qr/added alias 'pull -a = pull --all'/);
+for my $item ( @cmds ) {
+    my $out = run_command( 'aliases', @{$item->{cmd}} );
+    like( $out, $item->{output}, $item->{comment} );
+}
+
 
-unlink $ENV{'PROPHET_APP_CONFIG'};
+# check aliases in config
+$aliases = Prophet::Config->new(app_handle =>
+        Prophet::CLI->new->app_handle)->aliases;
+is_deeply(
+    $aliases,
+    {
+        'pull -l' => 'pull --local',
+        'pull -a' => 'pull --all',
+    },
+    'non empty aliases',
+);
 
-#TODO XXX
-#more tests soon
+# check content in config
+my $content;
+open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'}
+  or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
+{ local $/; $content = <$fh>; }
+is( $content, <<EOF, 'content in config' );
+alias pull -l = pull --local
+alias pull -a = pull --all
+EOF



More information about the Bps-public-commit mailing list