File: 02-checkproperty.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 (162 lines) | stat: -rwxr-xr-x 3,946 bytes parent folder | download | duplicates (5)
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
# -*- cperl -*-

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

require "test-functions.pl";

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

my $t = reset_repo();

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

set_conf(<<'EOS');
CHECK_PROPERTY();
EOS

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

work_nok('conf: no first arg', 'CHECK_PROPERTY: first argument must be a STRING or a qr/Regexp/', <<"EOS");
echo txt >$file
svn add -q --no-auto-props $file
svn ci -mx $file
EOS

set_conf(<<'EOS');
CHECK_PROPERTY(bless({}, 'Nothing'));
EOS

work_nok('conf: wrong first arg', 'CHECK_PROPERTY: first argument must be a STRING or a qr/Regexp/', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
CHECK_PROPERTY('string');
EOS

work_nok('conf: no second arg', 'CHECK_PROPERTY: second argument must be a STRING', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
CHECK_PROPERTY('s', qr/asdf/);
EOS

work_nok('conf: wrong second arg', 'CHECK_PROPERTY: second argument must be a STRING', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
CHECK_PROPERTY('s', 's', bless({}, 'Nothing'));
EOS

work_nok('conf: wrong third arg', 'CHECK_PROPERTY: third argument must be undefined, or a NUMBER, or a STRING, or a qr/Regexp/', <<"EOS");
svn ci -mx $file
EOS

set_conf(<<'EOS');
CHECK_PROPERTY('file1', 'prop');
CHECK_PROPERTY('file2', 'prop', 0);
CHECK_PROPERTY('file3', 'prop', 1);
CHECK_PROPERTY('file4', 'prop', 'value');
CHECK_PROPERTY('file5', 'prop', qr/^value$/);
CHECK_PROPERTY(qr/file6/, 'prop');
EOS

work_nok('check(string, string, undef) fail', 'property prop must be set for: file1', <<"EOS");
echo txt >${file}1
svn add -q --no-auto-props ${file}1
svn ci -mx ${file}1
EOS

work_ok('check(string, string, undef) succeed', <<"EOS");
svn ps prop x ${file}1
svn ci -mx ${file}1
EOS

work_nok('check(string, string, false) fail', 'property prop must not be set for: file2', <<"EOS");
echo txt >${file}2
svn add -q --no-auto-props ${file}2
svn ps prop x ${file}2
svn ci -mx ${file}2
EOS

work_ok('check(string, string, false) succeed', <<"EOS");
svn pd prop ${file}2
svn ci -mx ${file}2
EOS

work_nok('check(string, string, true) fail', 'property prop must be set for: file3', <<"EOS");
echo txt >${file}3
svn add -q --no-auto-props ${file}3
svn ci -mx ${file}3
EOS

work_ok('check(string, string, true) succeed', <<"EOS");
svn ps prop x ${file}3
svn ci -mx ${file}3
EOS

work_nok('check(string, string, string) fail because not set',
	 'property prop must be set to "value" for: file4', <<"EOS");
echo txt >${file}4
svn add -q --no-auto-props ${file}4
svn ci -mx ${file}4
EOS

work_nok('check(string, string, string) fail because of wrong value',
	 'property prop must be set to "value" and not to "x" for: file4', <<"EOS");
svn ps prop x ${file}4
svn ci -mx ${file}4
EOS

work_ok('check(string, string, string) succeed', <<"EOS");
svn ps prop value ${file}4
svn ci -mx ${file}4
EOS

work_nok('check(string, string, regex) fail because not set',
	 qr/property prop must be set and match "\(\?(?:-xism|\^):\^value\$\)" for: file5/, <<"EOS");
echo txt >${file}5
svn add -q --no-auto-props ${file}5
svn ci -mx ${file}5
EOS

work_nok('check(string, string, regex) fail because of wrong value',
	 qr/property prop must match "\(\?(?:-xism|\^):\^value\$\)" but is "x" for: file5/, <<"EOS");
svn ps prop x ${file}5
svn ci -mx ${file}5
EOS

work_ok('check(string, string, regex) succeed', <<"EOS");
svn ps prop value ${file}5
svn ci -mx ${file}5
EOS

work_nok('check(regex, string, undef) fail', 'property prop must be set for: file6', <<"EOS");
echo txt >${file}6
svn add -q --no-auto-props ${file}6
svn ci -mx ${file}6
EOS

work_ok('check(regex, string, undef) succeed', <<"EOS");
svn ps prop x ${file}6
svn ci -mx ${file}6
EOS

work_ok('succeed because dont match file name', <<"EOS");
echo txt >${file}NOMATCH
svn add -q --no-auto-props ${file}NOMATCH
svn ci -mx ${file}NOMATCH
EOS