1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
# Arch Perl library, Copyright (C) 2005 Enno Cramer
#
# 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
use 5.005;
use strict;
package Arch::Test::Framework;
use Arch::Test::Archive;
use Arch::Test::Tree;
use Arch::Test::Cases;
use Arch::TempFiles qw();
use Arch::Util qw();
sub new ($;%) {
my $class = shift;
my %args = @_;
my $home = $args{home} || Arch::TempFiles::temp_dir('arch-test');
my $self = {
arch_uid => '',
home => $home,
library => $args{library} || "$home/library",
archives => $args{archives} || "$home/archives",
trees => $args{trees} || "$home/trees",
ids => {},
};
die "Cannot access directory $self->{home}\n"
unless -d $home && -w $home;
bless $self, $class;
# setup home directory
foreach my $dir ((
$self->archives_dir,
$self->library_dir,
$self->trees_dir
)) {
mkdir $dir unless -d $dir;
}
unless (-d "$self->{home}/.arch-params") {
$self->run_tla(
'my-id',
$args{userid} || 'Arch Perl Test <arch-perl-test@example.com>'
);
$self->run_tla(
'my-revision-library',
$self->library_dir
);
$self->run_tla(
'library-config',
'--sparse', '--non-greedy',
$self->library_dir
);
}
$self->{arch_uid} = $self->run_tla('my-id', '--uid');
return $self;
}
# field access
sub arch_uid ($) {
my $self = shift;
return $self->{arch_uid};
}
sub home_dir ($) {
my $self = shift;
return $self->{home};
}
sub library_dir ($) {
my $self = shift;
return $self->{library};
}
sub archives_dir ($) {
my $self = shift;
return $self->{archives};
}
sub trees_dir ($) {
my $self = shift;
return $self->{trees};
}
# run with correct environment
sub run_tla ($@) {
my $self = shift;
local $ENV{HOME} = $self->home_dir;
my @lines = Arch::Util::run_tla(@_);
die "run_tla(".join(' ', @_).") failed: $?\n"
if $?;
return wantarray ? @lines : $lines[0];
}
sub gen_id ($$) {
my $self = shift;
my $section = shift;
$self->{ids}->{$section} = 0
unless exists $self->{ids}->{$section};
return $self->{ids}->{$section}++;
}
sub make_archive ($;$) {
my $self = shift;
my $name = shift
|| $self->arch_uid . '--archive-' . $self->gen_id('archives');
my $path = $self->archives_dir . "/$name";
$self->run_tla('make-archive', $name, $path);
return Arch::Test::Archive->new($self, $name);
}
sub make_tree ($$;$) {
my $self = shift;
my $version = shift;
my $tree = shift || 'tree-' . $self->gen_id('trees');
my $path = $self->trees_dir . "/$tree";
mkdir($path) || die "mkdir($path) failed: $!\n";
$self->run_tla('init-tree', '-d', $path, $version);
return Arch::Test::Tree->new($self, $path);
}
1;
__END__
=head1 NAME
Arch::Test::Framework - A test framework for Arch-Perl
=head1 SYNOPSIS
use Arch::Test::Framework;
my $fw = Arch::Test::Framework->new;
my $archive = $fw->make_archive;
my $version = $archive->make_version();
my $tree = $fw->make_tree($version);
#
# do something with $tree
#
$tree->import('initial import');
=head1 DESCRIPTION
Arch::Test::Framework is a framework to quickly generate testing data
(archives, versions, trees, changesets, etc) for arch-perl unit tests.
=head1 METHODS
B<new>,
B<arch_uid>,
B<home_dir>,
B<library_dir>,
B<archives_dir>,
B<trees_dir>,
B<make_archive>,
B<make_category>,
B<make_branch>,
B<make_version>,
B<make_tree>.
=over 4
=item B<new> [I<%args>]
Create a new arch-perl test environment.
Valid keys for I<%args> are I<home> to specify an existing test
environment to reuse, I<library> to specify a different revision
library path, I<archives> to specify a different archives directory,
and I<trees> to specify a differente project tree directory. The
default values are C<$home/library>, C<$home/archives>, and
C<$home/trees> respectively.
A different arch user id can be selected with the I<userid> key, the
default is C<Arch Perl Test E<lt>arch-perl-test@example.comE<gt>>.
=item B<arch_uid>
=item B<home_dir>
=item B<library_dir>
=item B<archives_dir>
=item B<trees_dir>
These methods return the environment parameters as initialized by B<new>.
=item B<make_archive> [I<archive_name>]
Create a new archive in the archives directory. If I<archive_name> is
not specified a unique name is generated. The archive name is
returned. Returns an L<Arch::Test::Archive> reference for the archive.
=item B<make_tree> I<version> [I<name>]
Create and initialize (C<tla init-tree>) a new project tree for
I<version>. I I<name> is not specified, a unique identifier will be
generated. Returns an L<Arch::Test::Tree> reference for the project
tree.
=back
=head1 AUTHORS
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).
Enno Cramer (uebergeek@web.de--2003/arch-perl--devel).
=cut
|