[Bps-public-commit] r13516 - in Shipwright/trunk: t

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sat Jun 21 03:04:24 EDT 2008


Author: sunnavy
Date: Sat Jun 21 03:04:24 2008
New Revision: 13516

Modified:
   Shipwright/trunk/   (props changed)
   Shipwright/trunk/t/71.script_cmds.t

Log:
 r13600 at sunnavys-mb:  sunnavy | 2008-06-20 22:01:53 +0800
 refactor cmd test a bit


Modified: Shipwright/trunk/t/71.script_cmds.t
==============================================================================
--- Shipwright/trunk/t/71.script_cmds.t	(original)
+++ Shipwright/trunk/t/71.script_cmds.t	Sat Jun 21 03:04:24 2008
@@ -34,152 +34,141 @@
     my $repo = shift;
 
     # test create
-    test_cmd(
-        $repo,
-        [ $sw, 'create', '-r', $repo ],
-        qr/created with success/,
-        "create $repo"
-    );
-
-    # test non exist cmd
-    test_cmd(
-        $repo, [ $sw, 'obra', '-r', $repo ],
-        undef, undef,
-        qr/Command not recognized/,
-        "non exist cmd",
-    );
-
-    # test list
-    test_cmd( $repo, [ $sw, 'list', '-r', $repo ], '', "list null $repo" );
-    test_cmd(
-        $repo,
-        [ $sw, 'list', '-r', $repo, '--name', 'foo' ],
-        qr/foo doesn't exist/,
-        "list non exist name $repo"
-    );
-
-    # test import
-    test_cmd(
-        $repo, [ $sw, 'import', '-r', $repo ],
-        undef, undef,
-        qr/need source arg/,
-        'import without --source ...'
-    );
+    my @cmds = (
+        [ [ 'create', '-r', $repo ], qr/created with success/, "create $repo" ],
 
-    test_cmd(
-        $repo, [ $sw, 'import', '-r', $repo, '--source' ],
-        undef, undef,
-        qr/source requires an argument/,
-        'import with --source but no value'
-    );
-
-    test_cmd(
-        $repo, [ $sw, 'import', '-r', $repo, '--source', 'foo' ],
-        undef, undef,
-        qr/invalid source: foo/,
-        'import with invalid source'
-    );
+        # test non exist cmd
+        [
+            [ 'obra', '-r', $repo ],
+            undef,
+            undef,
+            qr/Command not recognized/,
+            "non exist cmd",
+        ],
 
-    test_cmd(
-        $repo, [ $sw, 'import', '-r', $repo, 'foo' ],
-        undef, undef,
-        qr/invalid source: foo/,
-        'import with invalid source'
-    );
+        # test list
+        [ [ 'list', '-r', $repo ], '', "list null $repo" ],
+        [
+            [ 'list', '-r', $repo, '--name', 'foo' ],
+            qr/foo doesn't exist/,
+            "list non exist name $repo"
+        ],
 
-    test_cmd(
-        $repo,
+        # test import
         [
-            $sw, 'import', '-r', $repo, 'file:t/hello/Acme-Hello-0.03.tar.gz',
-            '--follow', 0
+            [ 'import', '-r', $repo ],
+            undef,
+            undef,
+            qr/need source arg/,
+            'import without --source ...'
+        ],
+        [
+            [ 'import', '-r', $repo, '--source' ],
+            undef,
+            undef,
+            qr/source requires an argument/,
+            'import with --source but no value'
+        ],
+        [
+            [ 'import', '-r', $repo, '--source', 'foo' ],
+            undef, undef,
+            qr/invalid source: foo/,
+            'import with invalid source'
+        ],
+        [
+            [ 'import', '-r', $repo, 'foo' ],
+            undef,
+            undef,
+            qr/invalid source: foo/,
+            'import with invalid source'
         ],
-        qr/imported with success/,
-        'import tar.gz file',
-    );
 
-    test_cmd(
-        $repo,
-        [ $sw, 'list', '-r', $repo, ],
-        qr{Acme-Hello:\s+
+        [
+            [
+                'import', '-r', $repo, 'file:t/hello/Acme-Hello-0.03.tar.gz',
+                '--follow', 0
+            ],
+            qr/imported with success/,
+            'import tar.gz file',
+        ],
+        [
+            [ 'list', '-r', $repo, ],
+            qr{Acme-Hello:\s+
         version:\s+0\.03\s+
         from:\s+\Qfile:t/hello/Acme-Hello-0.03.tar.gz\E}mx,
-        'list the repo',
-    );
+            'list the repo'
+        ],
 
-    # test rename
-    test_cmd(
-        $repo,
+        # test rename
         [
-            $sw,      'rename',     '-r',         $repo,
-            '--name', 'Acme-Hello', '--new-name', 'foo'
+            [
+                'rename',     '-r',         $repo, '--name',
+                'Acme-Hello', '--new-name', 'foo'
+            ],
+            qr/renamed Acme-Hello to foo with success/
         ],
-        qr/renamed Acme-Hello to foo with success/,
-    );
-    test_cmd(
-        $repo,
-        [ $sw, 'list', '-r', $repo, ],
-        qr{foo:\s+
+
+        [
+            [ 'list', '-r', $repo, ],
+            qr{foo:\s+
         version:\s+0\.03\s+
         from:\s+\Qfile:t/hello/Acme-Hello-0.03.tar.gz\E}mx,
-        'list the repo',
-    );
-
-    for ( [ '--name', 'foo', '--new-name' ], ['--name'], ) {
-        my $prefix = '';
-        $prefix = 'new-' if "@$_" =~ /foo/;
-        test_cmd(
-            $repo, [ $sw, 'rename', '-r', $repo, @$_, ],
-            undef, undef, qr/${prefix}name requires an argument/,
-        );
-    }
+            'list the repo'
+        ],
 
-    for ( [ '--name', 'foo' ], [], ) {
-        my $prefix = '';
-        $prefix = 'new-' if "@$_" =~ /foo/;
-        test_cmd(
-            $repo, [ $sw, 'rename', '-r', $repo, @$_, ],
+        [
+            [ 'rename', '-r', $repo, '--name', 'foo', '--new-name' ],
+            undef, undef, qr/new-name requires an argument/
+        ],
+        [
+            [ 'rename', '-r', $repo, '--name' ],
+            undef, undef, qr/name requires an argument/
+        ],
+        [
+            [ 'rename', '-r', $repo, ],
+            undef,
+            undef,
+            qr/need name arg/,
+            "rename without name arg"
+        ],
+        [
+            [ 'rename', '-r', $repo, '--name', 'foo' ],
             undef, undef,
-            qr/need ${prefix}name arg/,
-            "rename without ${prefix}name arg",
-        );
-    }
-
-    test_cmd(
-        $repo,
+            qr/need new-name arg/,
+            "rename without new-name arg"
+        ],
         [
-            $sw,      'rename',     '-r',         $repo,
-            '--name', 'Acme-Hello', '--new-name', '@'
+            [
+                'rename', '-r', $repo, '--name', 'Acme-Hello', '--new-name', '@'
+            ],
+            undef, undef,
+            qr/invalid new-name: @/,
+            'rename with invalid new-name'
         ],
-        undef, undef,
-        qr/invalid new-name: @/,
-        'rename with invalid new-name',
-    );
-
-    test_cmd(
-        $repo,
         [
-            $sw,      'rename',   '-r',         $repo,
-            '--name', 'NonExist', '--new-name', 'foo'
+            [
+                'rename', '-r', $repo, '--name', 'NonExist', '--new-name', 'foo'
+            ],
+            undef, undef,
+            qr/no such dist: NonExist/,
+            'rename nonexist dist'
         ],
-        undef, undef,
-        qr/no such dist: NonExist/,
-        'rename nonexist dist',
-    );
 
-    # now the dist is renamed to 'foo'
-
-    test_cmd(
-        $repo,
-        [ $sw, 'delete', '-r', $repo, '--name', 'foo' ],
-        qr/deleted foo with success/,
-        'deleted foo',
+        # now the dist is renamed to 'foo'
+        [
+            [ 'delete', '-r', $repo, '--name', 'foo' ],
+            qr/deleted foo with success/,
+            'deleted foo'
+        ],
+        [
+            [ 'list', '-r', $repo, '--name', 'foo' ],
+            qr/foo doesn't exist/,
+            "foo is deleted"
+        ],
     );
 
-    test_cmd(
-        $repo,
-        [ $sw, 'list', '-r', $repo, '--name', 'foo' ],
-        qr/foo doesn't exist/,
-        "foo is deleted"
-    );
+    for my $item (@cmds) {
+        test_cmd( $repo, [ $sw, @{ $item->[0] } ], @$item[ 1 .. $#$item ] );
+    }
 }
 



More information about the Bps-public-commit mailing list