All pastes #73035 Raw Edit

test.pl

public text v1 · immutable
#73035 ·published 2006-06-27 11:21 UTC
rendered paste body
#!/usr/bin/perl

use warnings;
use strict;

use Test::More tests => 7;

use SVN::Core;
use SVN::Repos;
use SVN::Fs;
use SVN::Ra;

my $repo_path = shift;

die "usage: $0 /path/to/repo\n" if ! defined $repo_path;

my $ra   = SVN::Ra->new("file://$repo_path");
my $repo = SVN::Repos::open($repo_path);
my $fs   = $repo->fs();

my $latest_rev_ra   = $ra->get_latest_revnum();
my $latest_rev_repo = $fs->youngest_rev();

is($latest_rev_ra, $latest_rev_repo, 'ra/repos agree on youngest rev');

foreach my $file (qw(/trunk/foo /trunk/bar
                     /branches/test1/foo /branches/test1/bar
                     /branches/test2/foo /branches/test2/bar)) {

  my $ra_rev    = check_ra($file, $latest_rev_ra);
  my $repos_rev = check_repos($file, $latest_rev_repo);

  is($ra_rev, $repos_rev,
     "ra/repos agree on interesting rev for $file ($ra_rev / $repos_rev)");
}

# Both functions return the youngest interesting rev for $path that
# is <= $rev.
#
# check_ra uses SVN::Ra, check_repos uses SVN::Repos.
#
# I would expect them both to return the same result
sub check_ra {
    my $path = shift;
    my $rev  = shift;

    my $ent  = $ra->stat($path, $rev);
    return $ent->created_rev();
}

sub check_repos {
    my $path = shift;
    my $rev  = shift;

    my $root = $fs->revision_root($rev);
    my $hist = $root->node_history($path);

    $hist = $hist->prev(0);
    return ($hist->location())[1];
}