| Arch documentation | Contained in the Arch distribution. |
Arch::Test::Tree - A test framework for Arch-Perl
use Arch::Test::Framework;
my $fw = Arch::Test::Framework->new;
my $tree = $fw->make_tree($dir, $version);
my $dir = $tree->add_dir;
$tree->add_file($dir);
$tree->import;
Arch::Test::Tree provides methods to quickly build and modify Arch project trees within the Arch::Test framework.
new, root, framework, run_tla, add_file, add_dir, add_link, modify_file, rename_file, rename_dir, remove_file, remove_dir, inventory, import, commit.
Create a new Arch::Test::Tree instance for path. This method should not be called directly.
Returns the project trees root directory.
Returns the associated Arch::Test::Framework reference.
Run tla @args from the tree root.
Add a new file name in directory dir. Fill file with content.
dir defaults to the project root (.). If name is not
specified, a unique filename is generated. A default content is
generated if none is given.
Add a new directory under parent, or . if parent is not
specified. If name is not given, a unique name is generated.
Add a new symbolic link under parent, or . if parent is not
specified. If name is not given, a unique name is generated. If
target is omitted, a (probably) non-existing target is generated.
Change files content to content, or append Has been modified.
if new content is omitted.
Rename file old to new. Returns new.
Rename directory old to new. Returns new.
Delete file and its associated arch id.
Recursively delete dir and its content.
Returns the inventory as generated by running tla inventory
flags. flags default to -Bs if not specified.
Create a base-0 revision from tree using the summary line
summary and log as log text. If tree contains a log file,
summary and log can be omitted.
Commit a patch-n revision from tree using the summary line
summary and log as log text. If tree contains a log file,
summary and log can be omitted.
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).
Enno Cramer (uebergeek@web.de--2003/arch-perl--devel).
| Arch documentation | Contained in the Arch distribution. |
# 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::Tree; use Arch::TempFiles qw(); use Arch::Util qw(); use POSIX qw(getcwd); sub new { my $class = shift; my $fw = shift; my $path = shift; my $self = { root => $path, framework => $fw, files => { } }; bless $self, $class; return $self; } sub root ($) { my $self = shift; return $self->{root}; } sub framework ($) { my $self = shift; return $self->{framework}; } sub run_tla ($@) { my $self = shift; my $cwd = getcwd; chdir($self->root); my @ret = $self->framework->run_tla(@_); chdir($cwd); return wantarray ? @ret : $ret[0]; } sub run_cmd ($@) { my $self = shift; my $cwd = getcwd; chdir($self->root); my @ret = Arch::Util::run_cmd(@_); chdir($cwd); die "run_cmd(".join(' ', @_).") failed: $?\n" if $?; return wantarray ? @ret : $ret[0]; } sub gen_id ($$) { my $self = shift; my $parent = shift; $self->{files}->{$parent} = 0 unless exists $self->{files}->{$parent}; return $self->{files}->{$parent}++; } sub add_file ($;$$$) { my $self = shift; my $dir = shift || '.'; my $name = shift || 'file-' . $self->gen_id($dir); my $cont = shift || "Content for $name.\n"; my $fname = "$dir/$name"; my $path = $self->root . "/$fname"; Arch::Util::save_file($path, $cont); $self->run_tla('add-id', $fname); return $fname; } sub add_dir ($;$$) { my $self = shift; my $dir = shift || '.'; my $name = shift || 'dir-' . $self->gen_id($dir); my $fname = "$dir/$name"; my $path = $self->root . "/$fname"; mkdir($path) || die "mkdir($path) failed: $!\n"; $self->run_tla('add-id', $fname); return $fname; } sub add_link ($;$$$) { my $self = shift; my $dir = shift || '.'; my $name = shift || 'file-' . $self->gen_id($dir); my $cont = shift || "Link-target-for-$name"; my $fname = "$dir/$name"; $self->run_cmd('/bin/ln', '-s', $cont, $fname); $self->run_tla('add-id', $fname); return $fname; } sub modify_file($$;$) { my $self = shift; my $file = shift; my $content = shift || Arch::Util::load_file($self->root . "/$file") . "Has been modified.\n"; Arch::Util::save_file($self->root . "/$file", $content); } sub rename_file ($$$) { my $self = shift; my ($old, $new) = @_; my $ret = $new; if (-d $self->root . "/$new") { (my $name = $old) =~ s,(.+/),,; $ret .= "/$name"; } $ret = './' . $ret unless $ret =~ /^\.\//; $self->run_tla('mv', $old, $new); return $ret; } sub rename_dir ($$$) { my $self = shift; my ($old, $new) = @_; my $ret = $new; if (-d $self->root . "/$new") { (my $name = $old) =~ s,(.+/),,; $ret .= "/$name"; } $ret = './' . $ret unless $ret =~ /^\.\//; $self->run_cmd('mv', $old, $new); return $ret; } sub remove_file ($$) { my $self = shift; my $file = shift; $self->run_tla('rm', $file); } sub remove_dir ($$) { my $self = shift; my $dir = shift; Arch::Util::remove_dir($self->root . "/$dir"); } sub inventory ($;$) { my $self = shift; my $flags = shift || '-Bs'; return $self->run_tla('inventory', $flags); } # this fails in baz-1.2 (that is broken), but not in baz-1.1 and baz-1.3 sub import ($;$$) { my $self = shift; return unless ref($self); # this is not for "use" my @opts = ('-d', $self->root); push @opts, ('-s', shift) if @_; push @opts, ('-L', shift) if @_; $self->run_tla('import', @opts); } sub commit ($;$$) { my $self = shift; my @opts = ('-d', $self->root); push @opts, ('-s', shift) if @_; push @opts, ('-L', shift) if @_; $self->run_tla('commit', @opts); } 1; __END__