Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /svnutils/trunk/src/, /svnutils/trunk/src/tests/

svnutils
Discussion topic

Back to topic list

CVS update: /svnutils/trunk/src/, /svnutils/trunk/src/tests/

Author sunny256
Full name Øyvind A. Holm
Date 2008-09-25 12:28:21 PDT
Message User: sunny256
Date: 2008-09-25 12:28:21-0700
Added:
   svnutils/trunk/src/t​ests/findrev.t
   svnutils/trunk/src/t​ests/mergesvn.t
   svnutils/trunk/src/t​ests/svndiff.t

Modified:
   svnutils/trunk/src/findrev
   svnutils/trunk/src/mergesvn
   svnutils/trunk/src/svndiff

Log:
 r220 | sunny256 | 2008-09-25 16:18:26 +0000 (Thu, 25 Sep 2008) | 15 lines
 
 Add basic tests for findrev, svndiff and mergesvn. Will be expanded
 soonish.
 
 * /trunk/src/mergesvn
 * /trunk/src/findrev
 * /trunk/src/svndiff
   Updated to match the tests.
 
 * /trunk/src/tests/findrev.t
 * /trunk/src/tests/svndiff.t
 * /trunk/src/tests/mergesvn.t
   New.
 
 76de8840-8b1d-11dd-b​028-000475e441b9 (svn)
 15d88792-8b38-11dd-8​7cd-000475e441b9 (cvs)

File Changes:

Directory: /svnutils/trunk/src/
===============================

File [changed]: findrev
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​findrev?r1=1.2&r​2=1.3
Delta lines: +11 -7
--------------------
--- findrev 2008-09-24 14:17:44-0700 1.2
+++ findrev 2008-09-25 12:28:19-0700 1.3
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: findrev 213 2008-09-24 13:27:58Z sunny256 $
+# $Id: findrev 220 2008-09-25 16:18:26Z sunny256 $
 # Locate a Subversion revision based on used defined criteras.
 #
 # Character set: UTF-8
@@ -37,7 +37,7 @@
 our $progname = $0;
 $progname =~ s/^.*\/(.*?)$/$1/;
 
-my $rcs_id = '$Id: findrev 213 2008-09-24 13:27:58Z sunny256 $';
+my $rcs_id = '$Id: findrev 220 2008-09-25 16:18:26Z sunny256 $';
 my $id_date = $rcs_id;
 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;
 
@@ -61,7 +61,10 @@
 
 $Opt{'debug'} && ($Debug = 1);
 $Opt{'help'} && usage(0);
-$Opt{'version'} && print_version();
+if ($Opt{'version'}) {
+ print_version();
+ exit(0);
+}
 
 my ($Start, $End) = (1, "HEAD");
 
@@ -250,7 +253,6 @@
     for (@main::version_array) {
         print("$_\n");
     }
- exit(0);
     # }}}
 } # print_version()
 
@@ -258,10 +260,12 @@
     # Send the help message to stdout {{{
     my $Retval = shift;
 
+ if ($Opt{'verbose'}) {
+ print("\n");
+ print_version();
+ }
     print(<<END);
 
-$rcs_id
-
 Usage: $progname [options] [path]
 
 Do a binary search through revisions of a Subversion working copy for
@@ -348,4 +352,4 @@
 # USA
 
 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w fo+=2 :
-# End of file $Id: findrev 213 2008-09-24 13:27:58Z sunny256 $
+# End of file $Id: findrev 220 2008-09-25 16:18:26Z sunny256 $

File [changed]: mergesvn
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​mergesvn?r1=1.27​&r2=1.28
Delta lines: +25 -12
---------------------
--- mergesvn 2008-09-24 14:17:44-0700 1.27
+++ mergesvn 2008-09-25 12:28:19-0700 1.28
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: mergesvn 213 2008-09-24 13:27:58Z sunny256 $
+# $Id: mergesvn 220 2008-09-25 16:18:26Z sunny256 $
 # Merges new changes into a file version controlled by Subversion.
 #
 # Character set: UTF-8
@@ -11,6 +11,10 @@
 # This file is part of the svnutils project — http://svnutils.tigris.org
 #===================​====================​====================​============
 
+BEGIN {
+ our @version_array;
+}
+
 use strict;
 use Getopt::Long;
 
@@ -33,12 +37,14 @@
 );
 
 our $progname = $0;
-$progname =~ s#^.*/(.*?)$#$1#;
+$progname =~ s/^.*\/(.*?)$/$1/;
 
-my $rcs_id = '$Id: mergesvn 213 2008-09-24 13:27:58Z sunny256 $';
+my $rcs_id = '$Id: mergesvn 220 2008-09-25 16:18:26Z sunny256 $';
 my $id_date = $rcs_id;
 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;
 
+push(@main::version_array, $rcs_id);
+
 Getopt::Long::Config​ure("bundling");
 GetOptions(
     "alias|a=s" => \$Opt{'alias'},
@@ -60,7 +66,10 @@
 
 $Opt{'debug'} && ($Debug = 1);
 $Opt{'help'} && usage(0);
-$Opt{'version'} && print_version();
+if ($Opt{'version'}) {
+ print_version();
+ exit(0);
+}
 
 my @Files = @ARGV;
 
@@ -110,7 +119,8 @@
                 my $Repos = repos_url($File);
                 mysyst(
                     $CMD_SVN, "diff",
- repos_url($master_file) . "\@$last_merge",
+ repos_url($master_file),
+ "-r", $last_merge,
                     $Repos
                 );
                 next LOOP;
@@ -374,8 +384,9 @@
 
 sub print_version {
     # Print program version {{{
- print("$rcs_id\n");
- exit(0);
+ for (@main::version_array) {
+ print("$_\n");
+ }
     # }}}
 } # print_version()
 
@@ -383,10 +394,12 @@
     # Send the help message to stdout {{{
     my $Retval = shift;
 
+ if ($Opt{'verbose'}) {
+ print("\n");
+ print_version();
+ }
     print(<<END);
 
-$rcs_id
-
 Merge changes between Subversion controlled files or directories.
 Elements without the "$PROP_NAME" property will be ignored. If no
 filenames are specified on the command line, it reads filenames from
@@ -469,7 +482,7 @@
 
 =head1 REVISION
 
-$Id: mergesvn 213 2008-09-24 13:27:58Z sunny256 $
+$Id: mergesvn 220 2008-09-25 16:18:26Z sunny256 $
 
 =head1 SYNOPSIS
 
@@ -604,5 +617,5 @@
 
 # }}}
 
-# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=0 et fo+=w :
-# End of file $Id: mergesvn 213 2008-09-24 13:27:58Z sunny256 $
+# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
+# End of file $Id: mergesvn 220 2008-09-25 16:18:26Z sunny256 $

File [changed]: svndiff
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​svndiff?r1=1.40&​r2=1.41
Delta lines: +23 -11
---------------------
--- svndiff 2008-09-24 14:17:44-0700 1.40
+++ svndiff 2008-09-25 12:28:19-0700 1.41
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: svndiff 213 2008-09-24 13:27:58Z sunny256 $
+# $Id: svndiff 220 2008-09-25 16:18:26Z sunny256 $
 # Uses a specified diff program for viewing differences in a Subversion
 # versioned directory tree.
 #
@@ -12,6 +12,10 @@
 # This file is part of the svnutils project — http://svnutils.tigris.org
 #===================​====================​====================​============
 
+BEGIN {
+ our @version_array;
+}
+
 use strict;
 use Getopt::Long;
 
@@ -36,12 +40,14 @@
 );
 
 our $progname = $0;
-$progname =~ s#^.*/(.*?)$#$1#;
+$progname =~ s/^.*\/(.*?)$/$1/;
 
-my $rcs_id = '$Id: svndiff 213 2008-09-24 13:27:58Z sunny256 $';
+my $rcs_id = '$Id: svndiff 220 2008-09-25 16:18:26Z sunny256 $';
 my $id_date = $rcs_id;
 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;
 
+push(@main::version_array, $rcs_id);
+
 Getopt::Long::Config​ure("bundling");
 GetOptions(
     "conflict|C" => \$Opt{'conflict'},
@@ -79,7 +85,10 @@
 } # deprecated()
 
 $Opt{'debug'} && ($Debug = 1);
-$Opt{'version'} && print_version();
+if ($Opt{'version'}) {
+ print_version();
+ exit(0);
+}
 
 # Default value, can be overridden in ~/.svndiffrc
 my $Cmd = "vimdiff";
@@ -488,8 +497,9 @@
 
 sub print_version {
     # Print program version {{{
- print("$rcs_id\n");
- exit(0);
+ for (@main::version_array) {
+ print("$_\n");
+ }
     # }}}
 } # print_version()
 
@@ -497,10 +507,12 @@
     # Send the help message to stdout {{{
     my $Retval = shift;
 
+ if ($Opt{'verbose'}) {
+ print("\n");
+ print_version();
+ }
     print(<<END);
 
-$rcs_id
-
 Usage: $progname [options] [file [...]]
 
 "file" can also be an URL, but then the --revision option has to be
@@ -578,7 +590,7 @@
 
 =head1 REVISION
 
-$Id: svndiff 213 2008-09-24 13:27:58Z sunny256 $
+$Id: svndiff 220 2008-09-25 16:18:26Z sunny256 $
 
 =head1 SYNOPSIS
 
@@ -768,5 +780,5 @@
 
 # }}}
 
-# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=0 et fo+=w :
-# End of file $Id: svndiff 213 2008-09-24 13:27:58Z sunny256 $
+# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
+# End of file $Id: svndiff 220 2008-09-25 16:18:26Z sunny256 $

Directory: /svnutils/trunk/src/tests/
====================​=================

File [added]: findrev.t
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​tests/findrev.t?rev=​1.1&content-type​=text/vnd.viewcvs-ma​rkup
Added lines: 342
----------------
#!/usr/bin/perl -w

#===================​====================​====================​============
# $Id: findrev.t 220 2008-09-25 16:18:26Z sunny256 $
# Test suite for findrev(1).
#
# Character set: UTF-8
# ©opyleft 2008– Øyvind A. Holm <sunny at sunbase dot org>
# License: GNU General Public License version 2 or later, see end of
# file for legal stuff.
#===================​====================​====================​============

BEGIN {
    # push(@INC, "$ENV{'HOME'}/bin/S​TDlibdirDTS");
    our @version_array;
    use Test::More qw{no_plan};
    # use_ok() goes here
}

use strict;
use Getopt::Long;

$| = 1;

our $Debug = 0;
our $CMD = "../findrev";

our %Opt = (
    'all' => 0,
    'debug' => 0,
    'help' => 0,
    'todo' => 0,
    'verbose' => 0,
    'version' => 0,
);

our $progname = $0;
$progname =~ s/^.*\/(.*?)$/$1/;

my $rcs_id = '$Id: findrev.t 220 2008-09-25 16:18:26Z sunny256 $';
my $id_date = $rcs_id;
$id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;

push(@main::version_array, $rcs_id);

my @cmdline_array = @ARGV;

Getopt::Long::Config​ure("bundling");
GetOptions(
    "all|a" => \$Opt{'all'},
    "debug" => \$Opt{'debug'},
    "help|h" => \$Opt{'help'},
    "todo|t" => \$Opt{'todo'},
    "verbose|v+" => \$Opt{'verbose'},
    "version" => \$Opt{'version'},
) || die("$progname: Option error. Use -h for help.\n");

$Opt{'debug'} && ($Debug = 1);
$Opt{'help'} && usage(0);
if ($Opt{'version'}) {
    print_version();
    exit(0);
}

diag(sprintf("========== Executing \"%s%s%s\" ==========",
    $progname,
    scalar(@cmdline_array) ? " " : "",
    join(" ", @cmdline_array)));

if ($Opt{'todo'} && !$Opt{'all'}) {
    goto todo_section;
}

=pod

testcmd("$CMD command", # {{{
    <<END,
[expected stdin]
END
    "",
    "description",
);

# }}}

=cut

diag("Testing -h (--help) option...");
likecmd("$CMD -h", # {{{
    '/ Show this help\./',
    '/^$/',
    "Option -h prints help screen",
);

# }}}
unlike(`$CMD -h`, # {{{
    '/\$Id: /',
    "\"$CMD -h\" - No Id with only -h",
);

# }}}
diag("Testing -v (--verbose) option...");
likecmd("$CMD -hv", # {{{
    '/\$Id: .*? \$.* Show this help\./s',
    '/^$/',
    "Option --version with -h returns Id string and help screen",
);

# }}}
diag("Testing --version option...");
likecmd("$CMD --version", # {{{
    '/\$Id: .*? \$/',
    '/^$/',
    "Option --version returns Id string",
);

# }}}

todo_section:
;

if ($Opt{'all'} || $Opt{'todo'}) {
    diag("Running TODO tests..."); # {{{

    TODO: {

local $TODO = "";
# Insert TODO tests here.

    }
    # TODO tests }}}
}

diag("Testing finished.");

sub testcmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "findrev-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub likecmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "findrev-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub file_data {
    # Return file content as a string {{{
    my $File = shift;
    my $Txt;
    if (open(FP, "<", $File)) {
        $Txt = join("", <FP>);
        close(FP);
        return($Txt);
    } else {
        return undef;
    }
    # }}}
}

sub print_version {
    # Print program version {{{
    for (@main::version_array) {
        print("$_\n");
    }
    # }}}
} # print_version()

sub usage {
    # Send the help message to stdout {{{
    my $Retval = shift;

    if ($Opt{'verbose'}) {
        print("\n");
        print_version();
    }
    print(<<END);

Usage: $progname [options] [file [files [...]]]

Contains tests for the findrev(1) program.

Options:

  -a, --all
    Run all tests, also TODOs.
  -h, --help
    Show this help.
  -t, --todo
    Run only the TODO tests.
  -v, --verbose
    Increase level of verbosity. Can be repeated.
  --version
    Print version information.
  --debug
    Print debugging messages.

END
    exit($Retval);
    # }}}
} # usage()

sub msg {
    # Print a status message to stderr based on verbosity level {{{
    my ($verbose_level, $Txt) = @_;

    if ($Opt{'verbose'} >= $verbose_level) {
        print(STDERR "$progname: $Txt\n");
    }
    # }}}
} # msg()

__END__

# Plain Old Documentation (POD) {{{

=pod

=head1 NAME

run-tests.pl

=head1 REVISION

$Id: findrev.t 220 2008-09-25 16:18:26Z sunny256 $

=head1 SYNOPSIS

findrev.t [options] [file [files [...]]]

=head1 DESCRIPTION

Contains tests for the findrev(1) program.

=head1 OPTIONS

=over 4

=item B<-a>, B<--all>

Run all tests, also TODOs.

=item B<-h>, B<--help>

Print a brief help summary.

=item B<-t>, B<--todo>

Run only the TODO tests.

=item B<-v>, B<--verbose>

Increase level of verbosity. Can be repeated.

=item B<--version>

Print version information.

=item B<--debug>

Print debugging messages.

=back

=head1 AUTHOR

Made by Øyvind A. Holm S<E<lt>sunn​y@sunbase.orgE<gt​>>.

=head1 COPYRIGHT

Copyleft © Øyvind A. Holm E<lt>sunny@sun​base.orgE<gt>
This is free software; see the file F<COPYING> for legalese stuff.

=head1 LICENCE

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

=head1 SEE ALSO

=cut

# }}}

# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
# End of file $Id: findrev.t 220 2008-09-25 16:18:26Z sunny256 $

File [added]: mergesvn.t
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​tests/mergesvn.t?rev​=1.1&content-typ​e=text/vnd.viewcvs-m​arkup
Added lines: 342
----------------
#!/usr/bin/perl -w

#===================​====================​====================​============
# $Id: mergesvn.t 220 2008-09-25 16:18:26Z sunny256 $
# Test suite for mergesvn(1).
#
# Character set: UTF-8
# ©opyleft 2008– Øyvind A. Holm <sunny at sunbase dot org>
# License: GNU General Public License version 2 or later, see end of
# file for legal stuff.
#===================​====================​====================​============

BEGIN {
    # push(@INC, "$ENV{'HOME'}/bin/S​TDlibdirDTS");
    our @version_array;
    use Test::More qw{no_plan};
    # use_ok() goes here
}

use strict;
use Getopt::Long;

$| = 1;

our $Debug = 0;
our $CMD = "../mergesvn";

our %Opt = (
    'all' => 0,
    'debug' => 0,
    'help' => 0,
    'todo' => 0,
    'verbose' => 0,
    'version' => 0,
);

our $progname = $0;
$progname =~ s/^.*\/(.*?)$/$1/;

my $rcs_id = '$Id: mergesvn.t 220 2008-09-25 16:18:26Z sunny256 $';
my $id_date = $rcs_id;
$id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;

push(@main::version_array, $rcs_id);

my @cmdline_array = @ARGV;

Getopt::Long::Config​ure("bundling");
GetOptions(
    "all|a" => \$Opt{'all'},
    "debug" => \$Opt{'debug'},
    "help|h" => \$Opt{'help'},
    "todo|t" => \$Opt{'todo'},
    "verbose|v+" => \$Opt{'verbose'},
    "version" => \$Opt{'version'},
) || die("$progname: Option error. Use -h for help.\n");

$Opt{'debug'} && ($Debug = 1);
$Opt{'help'} && usage(0);
if ($Opt{'version'}) {
    print_version();
    exit(0);
}

diag(sprintf("========== Executing \"%s%s%s\" ==========",
    $progname,
    scalar(@cmdline_array) ? " " : "",
    join(" ", @cmdline_array)));

if ($Opt{'todo'} && !$Opt{'all'}) {
    goto todo_section;
}

=pod

testcmd("$CMD command", # {{{
    <<END,
[expected stdin]
END
    "",
    "description",
);

# }}}

=cut

diag("Testing -h (--help) option...");
likecmd("$CMD -h", # {{{
    '/ Show this help\./',
    '/^$/',
    "Option -h prints help screen",
);

# }}}
unlike(`$CMD -h`, # {{{
    '/\$Id: /',
    "\"$CMD -h\" - No Id with only -h",
);

# }}}
diag("Testing -v (--verbose) option...");
likecmd("$CMD -hv", # {{{
    '/\$Id: .*? \$.* Show this help\./s',
    '/^$/',
    "Option --version with -h returns Id string and help screen",
);

# }}}
diag("Testing --version option...");
likecmd("$CMD --version", # {{{
    '/\$Id: .*? \$/',
    '/^$/',
    "Option --version returns Id string",
);

# }}}

todo_section:
;

if ($Opt{'all'} || $Opt{'todo'}) {
    diag("Running TODO tests..."); # {{{

    TODO: {

local $TODO = "";
# Insert TODO tests here.

    }
    # TODO tests }}}
}

diag("Testing finished.");

sub testcmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "mergesvn-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub likecmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "mergesvn-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub file_data {
    # Return file content as a string {{{
    my $File = shift;
    my $Txt;
    if (open(FP, "<", $File)) {
        $Txt = join("", <FP>);
        close(FP);
        return($Txt);
    } else {
        return undef;
    }
    # }}}
}

sub print_version {
    # Print program version {{{
    for (@main::version_array) {
        print("$_\n");
    }
    # }}}
} # print_version()

sub usage {
    # Send the help message to stdout {{{
    my $Retval = shift;

    if ($Opt{'verbose'}) {
        print("\n");
        print_version();
    }
    print(<<END);

Usage: $progname [options] [file [files [...]]]

Contains tests for the mergesvn(1) program.

Options:

  -a, --all
    Run all tests, also TODOs.
  -h, --help
    Show this help.
  -t, --todo
    Run only the TODO tests.
  -v, --verbose
    Increase level of verbosity. Can be repeated.
  --version
    Print version information.
  --debug
    Print debugging messages.

END
    exit($Retval);
    # }}}
} # usage()

sub msg {
    # Print a status message to stderr based on verbosity level {{{
    my ($verbose_level, $Txt) = @_;

    if ($Opt{'verbose'} >= $verbose_level) {
        print(STDERR "$progname: $Txt\n");
    }
    # }}}
} # msg()

__END__

# Plain Old Documentation (POD) {{{

=pod

=head1 NAME

run-tests.pl

=head1 REVISION

$Id: mergesvn.t 220 2008-09-25 16:18:26Z sunny256 $

=head1 SYNOPSIS

mergesvn.t [options] [file [files [...]]]

=head1 DESCRIPTION

Contains tests for the mergesvn(1) program.

=head1 OPTIONS

=over 4

=item B<-a>, B<--all>

Run all tests, also TODOs.

=item B<-h>, B<--help>

Print a brief help summary.

=item B<-t>, B<--todo>

Run only the TODO tests.

=item B<-v>, B<--verbose>

Increase level of verbosity. Can be repeated.

=item B<--version>

Print version information.

=item B<--debug>

Print debugging messages.

=back

=head1 AUTHOR

Made by Øyvind A. Holm S<E<lt>sunn​y@sunbase.orgE<gt​>>.

=head1 COPYRIGHT

Copyleft © Øyvind A. Holm E<lt>sunny@sun​base.orgE<gt>
This is free software; see the file F<COPYING> for legalese stuff.

=head1 LICENCE

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

=head1 SEE ALSO

=cut

# }}}

# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
# End of file $Id: mergesvn.t 220 2008-09-25 16:18:26Z sunny256 $

File [added]: svndiff.t
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​tests/svndiff.t?rev=​1.1&content-type​=text/vnd.viewcvs-ma​rkup
Added lines: 342
----------------
#!/usr/bin/perl -w

#===================​====================​====================​============
# $Id: svndiff.t 220 2008-09-25 16:18:26Z sunny256 $
# Test suite for svndiff(1).
#
# Character set: UTF-8
# ©opyleft 2008– Øyvind A. Holm <sunny at sunbase dot org>
# License: GNU General Public License version 2 or later, see end of
# file for legal stuff.
#===================​====================​====================​============

BEGIN {
    # push(@INC, "$ENV{'HOME'}/bin/S​TDlibdirDTS");
    our @version_array;
    use Test::More qw{no_plan};
    # use_ok() goes here
}

use strict;
use Getopt::Long;

$| = 1;

our $Debug = 0;
our $CMD = "../svndiff";

our %Opt = (
    'all' => 0,
    'debug' => 0,
    'help' => 0,
    'todo' => 0,
    'verbose' => 0,
    'version' => 0,
);

our $progname = $0;
$progname =~ s/^.*\/(.*?)$/$1/;

my $rcs_id = '$Id: svndiff.t 220 2008-09-25 16:18:26Z sunny256 $';
my $id_date = $rcs_id;
$id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d​\d:\d\d:\d\d\S​+).*/$1/;

push(@main::version_array, $rcs_id);

my @cmdline_array = @ARGV;

Getopt::Long::Config​ure("bundling");
GetOptions(
    "all|a" => \$Opt{'all'},
    "debug" => \$Opt{'debug'},
    "help|h" => \$Opt{'help'},
    "todo|t" => \$Opt{'todo'},
    "verbose|v+" => \$Opt{'verbose'},
    "version" => \$Opt{'version'},
) || die("$progname: Option error. Use -h for help.\n");

$Opt{'debug'} && ($Debug = 1);
$Opt{'help'} && usage(0);
if ($Opt{'version'}) {
    print_version();
    exit(0);
}

diag(sprintf("========== Executing \"%s%s%s\" ==========",
    $progname,
    scalar(@cmdline_array) ? " " : "",
    join(" ", @cmdline_array)));

if ($Opt{'todo'} && !$Opt{'all'}) {
    goto todo_section;
}

=pod

testcmd("$CMD command", # {{{
    <<END,
[expected stdin]
END
    "",
    "description",
);

# }}}

=cut

diag("Testing -h (--help) option...");
likecmd("$CMD -h", # {{{
    '/ Show this help\./',
    '/^$/',
    "Option -h prints help screen",
);

# }}}
unlike(`$CMD -h`, # {{{
    '/\$Id: /',
    "\"$CMD -h\" - No Id with only -h",
);

# }}}
diag("Testing -v (--verbose) option...");
likecmd("$CMD -hv", # {{{
    '/\$Id: .*? \$.* Show this help\./s',
    '/^$/',
    "Option --version with -h returns Id string and help screen",
);

# }}}
diag("Testing --version option...");
likecmd("$CMD --version", # {{{
    '/\$Id: .*? \$/',
    '/^$/',
    "Option --version returns Id string",
);

# }}}

todo_section:
;

if ($Opt{'all'} || $Opt{'todo'}) {
    diag("Running TODO tests..."); # {{{

    TODO: {

local $TODO = "";
# Insert TODO tests here.

    }
    # TODO tests }}}
}

diag("Testing finished.");

sub testcmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "svndiff-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub likecmd {
    # {{{
    my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
    my $stderr_cmd = "";
    my $deb_str = $Opt{'debug'} ? " --debug" : "";
    my $Txt = join("",
        "\"$Cmd\"",
        defined($Desc)
            ? " - $Desc"
            : ""
    );
    my $TMP_STDERR = "svndiff-stderr.tmp";

    if (defined($Exp_stderr) && !length($deb_str)) {
        $stderr_cmd = " 2>$TMP_STDERR";
    }
    like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
    if (defined($Exp_stderr)) {
        if (!length($deb_str)) {
            like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
            unlink($TMP_STDERR);
        }
    } else {
        diag("Warning: stderr not defined for '$Txt'");
    }
    # }}}
}

sub file_data {
    # Return file content as a string {{{
    my $File = shift;
    my $Txt;
    if (open(FP, "<", $File)) {
        $Txt = join("", <FP>);
        close(FP);
        return($Txt);
    } else {
        return undef;
    }
    # }}}
}

sub print_version {
    # Print program version {{{
    for (@main::version_array) {
        print("$_\n");
    }
    # }}}
} # print_version()

sub usage {
    # Send the help message to stdout {{{
    my $Retval = shift;

    if ($Opt{'verbose'}) {
        print("\n");
        print_version();
    }
    print(<<END);

Usage: $progname [options] [file [files [...]]]

Contains tests for the svndiff(1) program.

Options:

  -a, --all
    Run all tests, also TODOs.
  -h, --help
    Show this help.
  -t, --todo
    Run only the TODO tests.
  -v, --verbose
    Increase level of verbosity. Can be repeated.
  --version
    Print version information.
  --debug
    Print debugging messages.

END
    exit($Retval);
    # }}}
} # usage()

sub msg {
    # Print a status message to stderr based on verbosity level {{{
    my ($verbose_level, $Txt) = @_;

    if ($Opt{'verbose'} >= $verbose_level) {
        print(STDERR "$progname: $Txt\n");
    }
    # }}}
} # msg()

__END__

# Plain Old Documentation (POD) {{{

=pod

=head1 NAME

run-tests.pl

=head1 REVISION

$Id: svndiff.t 220 2008-09-25 16:18:26Z sunny256 $

=head1 SYNOPSIS

svndiff.t [options] [file [files [...]]]

=head1 DESCRIPTION

Contains tests for the svndiff(1) program.

=head1 OPTIONS

=over 4

=item B<-a>, B<--all>

Run all tests, also TODOs.

=item B<-h>, B<--help>

Print a brief help summary.

=item B<-t>, B<--todo>

Run only the TODO tests.

=item B<-v>, B<--verbose>

Increase level of verbosity. Can be repeated.

=item B<--version>

Print version information.

=item B<--debug>

Print debugging messages.

=back

=head1 AUTHOR

Made by Øyvind A. Holm S<E<lt>sunn​y@sunbase.orgE<gt​>>.

=head1 COPYRIGHT

Copyleft © Øyvind A. Holm E<lt>sunny@sun​base.orgE<gt>
This is free software; see the file F<COPYING> for legalese stuff.

=head1 LICENCE

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

=head1 SEE ALSO

=cut

# }}}

# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
# End of file $Id: svndiff.t 220 2008-09-25 16:18:26Z sunny256 $

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /svnutils/trunk/src/, /svnutils/trunk/src/tests/ sunny256 Øyvind A. Holm 2008-09-25 12:28:21 PDT
Messages per page: