File: 02-generic.t

package info (click to toggle)
libsvn-hooks-perl 1.36-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,365; makefile: 7
file content (171 lines) | stat: -rwxr-xr-x 3,142 bytes parent folder | download | duplicates (3)
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
# -*- cperl -*-

use strict;
use warnings;
use lib 't';
use Test::More;

require "test-functions.pl";

if (can_svn()) {
    plan tests => 13;
}
else {
    plan skip_all => 'Cannot find or use svn commands.';
}

my $t = reset_repo();

set_hook(<<'EOS');
use SVN::Hooks::Generic;
EOS

set_conf(<<'EOS');
GENERIC(1);
EOS

my $wc   = catdir($t, 'wc');
my $file = catfile($wc, 'file.txt');

work_nok('odd' => 'odd number of arguments', <<"EOS");
echo txt >$file
svn add -q --no-auto-props $file
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('non_hook' => sub {});
EOS

work_nok('non hook' => 'invalid hook name', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('start-commit' => 'non ref');
EOS

work_nok('non ref' => 'should be mapped to a CODE-ref or to an ARRAY-ref', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('start-commit' => {});
EOS

work_nok('non array' => 'should be mapped to a CODE-ref or to an ARRAY-ref', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('start-commit' => ['non code']);
EOS

work_nok('non code' => 'should be mapped to CODE-refs', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('start-commit' => sub { die "died from within"; });
EOS

work_nok('died from within' => 'died from within', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC('start-commit' => sub { return 1; });
EOS

work_ok('ok', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC(
    'start-commit' => sub { die join(',',@_), "\n"; },
);
EOS

my $repo = catdir($t, 'repo');

work_nok('cry start-commit' => "$repo,", <<"EOS");
echo asdf >>$file
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC(
    'pre-commit' => sub { die join(',',@_), "\n"; },
);
EOS

work_nok('cry pre-commit' => 'SVN::Look=HASH', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
GENERIC(
    'pre-revprop-change' => sub { die join(',',@_), "\n"; },
);
EOS

work_nok('cry pre-revprop-change' => 'SVN::Look=HASH', <<"EOS");
svn ps svn:log --revprop -r 1 'changed' $t/wc
EOS

SKIP: {
    skip 'SVN 1.9.x has a bug on the pre-lock/pre-unlock hooks', 2 if svn_version() =~ /^1\.9\./;

    set_conf(<<'EOS');
GENERIC(
    'pre-lock' => sub { die join(',',@_), "\n"; },
);
EOS

    work_nok('cry pre-lock' => qr:\Q$repo\E,/?file.txt,:, <<"EOS");
svn lock -mx $file
EOS

    set_conf(<<'EOS');
GENERIC(
    'pre-unlock' => sub { die join(',',@_), "\n"; },
);
EOS

    work_nok('cry pre-unlock' => qr:\Q$repo\E,/?file.txt,:, <<"EOS");
svn lock $file
svn unlock $file
EOS
}

set_conf(<<"EOS");
sub truncate {
    open FILE, '>', '$file' or die 'Cannot open $file: \$!';
    close FILE;
}

sub mark {
    my (\$mark) = \@_;
    return sub {
        open FILE, '>>', '$file' or die \"Cannot open $file: \$!\";
        print FILE \$mark;
        close FILE;
    };
}

GENERIC('pre-commit' => \\&truncate);
GENERIC('pre-commit' => mark(1));
GENERIC('pre-commit' => mark(2));
GENERIC('pre-commit' => mark(3));
GENERIC('pre-commit' => mark(4));
EOS

do_script(newdir(), <<"EOS");
svn ci -mx $file
EOS

open FILE, '<', $file or die "Cannot open $file: $!";
my $marks = <FILE>;
close FILE;
ok($marks eq '1234', 'hook order');