minor fixup to a test script...
[gitolite.git] / src / lib / Gitolite / Test.pm
blob904abbf11dd40bec8654bd9649a3709f67d162dc
1 package Gitolite::Test;
3 # functions for the test code to use
4 # ----------------------------------------------------------------------
6 #<<<
7 @EXPORT = qw(
8 try
9 put
10 text
11 lines
12 dump
13 confreset
14 confadd
15 cmp
16 md5sum
18 #>>>
19 use Exporter 'import';
20 use File::Path qw(mkpath);
21 use Carp qw(carp cluck croak confess);
22 use Digest::MD5 qw(md5_hex);
24 use Gitolite::Common;
26 BEGIN {
27 require Gitolite::Test::Tsh;
28 *{'try'} = \&Tsh::try;
29 *{'put'} = \&Tsh::put;
30 *{'text'} = \&Tsh::text;
31 *{'lines'} = \&Tsh::lines;
32 *{'cmp'} = \&Tsh::cmp;
35 use strict;
36 use warnings;
38 # ----------------------------------------------------------------------
40 # make sure the user is ready for it
41 if ( not $ENV{GITOLITE_TEST} or $ENV{GITOLITE_TEST} ne 'y' ) {
42 print "Bail out! See t/README for information on how to run the tests.\n";
43 exit 255;
46 # required preamble for all tests
47 try "
48 DEF gsh = /TRACE: gsh.SOC=/
49 DEF reject = /hook declined to update/; /remote rejected.*hook declined/; /error: failed to push some refs to/
51 DEF AP_1 = cd ../gitolite-admin; ok or die cant find admin repo clone;
52 DEF AP_2 = AP_1; git add conf ; ok; git commit -m %1; ok; /master.* %1/
53 DEF ADMIN_PUSH = AP_2 %1; glt push admin origin; ok; gsh; /master -> master/
55 DEF CS_1 = pwd; //tmp/tsh_tempdir.*gitolite-admin/; git remote -v; ok; /file:///gitolite-admin/
56 DEF CHECK_SETUP = CS_1; git log; ok; /fa7564c1b903ea3dce49314753f25b34b9e0cea0/
58 DEF CLONE = glt clone %1 file:///%2
59 DEF PUSH = glt push %1 origin
61 # clean install
62 mkdir -p $ENV{HOME}/bin
63 ln -sf $ENV{PWD}/t/glt ~/bin
64 ./install -ln
65 cd; rm -vrf .gito* repositories
66 git config --file $ENV{HOME}/.gitconfig.local user.name \"gitolite tester\"
67 git config --file $ENV{HOME}/.gitconfig.local user.email \"tester\@example.com\"
68 git config --global include.path \"~/.gitconfig.local\"
70 # setup
71 gitolite setup -a admin
73 # clone admin repo
74 cd tsh_tempdir
75 glt clone admin --progress file:///gitolite-admin
76 cd gitolite-admin
77 " or die "could not setup the test environment; errors:\n\n" . text() . "\n\n";
79 sub dump {
80 use Data::Dumper;
81 for my $i (@_) {
82 print STDERR "DBG: " . Dumper($i);
86 sub _confargs {
87 return @_ if ( $_[1] );
88 return 'gitolite.conf', $_[0];
91 sub confreset {
92 chdir("../gitolite-admin") or die "in `pwd`, could not cd ../g-a";
93 system( "rm", "-rf", "conf" );
94 mkdir("conf");
95 system("mv ~/repositories/gitolite-admin.git ~/repositories/.ga");
96 system("mv ~/repositories/testing.git ~/repositories/.te");
97 system("find ~/repositories -name '*.git' |xargs rm -rf");
98 system("mv ~/repositories/.ga ~/repositories/gitolite-admin.git");
99 system("mv ~/repositories/.te ~/repositories/testing.git ");
100 put "|cut -c9- > conf/gitolite.conf", '
101 repo gitolite-admin
102 RW+ = admin
103 repo testing
104 RW+ = @all
108 sub confadd {
109 chdir("../gitolite-admin") or die "in `pwd`, could not cd ../g-a";
110 my ( $file, $string ) = _confargs(@_);
111 put "|cat >> conf/$file", $string;
114 sub md5sum {
115 my $out = '';
116 for my $file (@_) {
117 $out .= md5_hex( slurp($file) ) . " $file\n";
119 return $out;