File: arg_error.t

package info (click to toggle)
libhash-sharedmem-perl 0.005-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: perl: 463; makefile: 3
file content (236 lines) | stat: -r--r--r-- 6,886 bytes parent folder | download
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
use warnings;
use strict;

use File::Temp 0.22 qw(tempdir);
use Scalar::String 0.000 qw(sclstr_downgraded sclstr_upgraded);
use Test::More tests => 816;

BEGIN { use_ok "Hash::SharedMem", qw(
	is_shash check_shash
	shash_open
	shash_is_readable shash_is_writable shash_mode
	shash_exists shash_getd shash_length shash_get
	shash_set shash_gset shash_cset
	shash_occupied shash_count shash_size
	shash_key_min shash_key_max
	shash_key_ge shash_key_gt shash_key_le shash_key_lt
	shash_keys_array shash_keys_hash
	shash_group_get_hash
	shash_snapshot shash_is_snapshot
	shash_idle shash_tidy
	shash_tally_get shash_tally_zero shash_tally_gzero
); }

foreach(
	undef,
	1,
	sclstr_downgraded("foo"),
	sclstr_upgraded("foo"),
	sclstr_downgraded("\x{e9}foo"),
	sclstr_upgraded("\x{e9}foo"),
	sclstr_upgraded("\x{2603}foo"),
	${qr/foo/},
	*foo,
	\1,
	[],
	{},
	sub{},
	qr/foo/,
	\*foo,
	bless({}),
) {
	ok !is_shash($_);
	eval { check_shash($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_is_readable($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_is_writable($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_mode($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_exists($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_getd($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_length($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_get($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_set($_, "x", "y") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_gset($_, "x", "y") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_cset($_, "x", "y", "z") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_occupied($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_count($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_size($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_min($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_max($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_ge($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_gt($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_le($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_key_lt($_, "x") };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_keys_array($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_keys_hash($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_group_get_hash($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_snapshot($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_is_snapshot($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_idle($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_tidy($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_tally_get($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_tally_zero($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
	eval { shash_tally_gzero($_) };
	like $@, qr/\Ahandle is not a shared hash handle /;
}

my $tmpdir = tempdir(CLEANUP => 1);
my $sh = shash_open("$tmpdir/t0", "rwc");
ok $sh;
ok is_shash($sh);
eval { check_shash($sh) };
is $@, "";
require_ok "Hash::SharedMem::Handle";
my %sh;
tie %sh, "Hash::SharedMem::Handle", $sh;
ok is_shash(tied(%sh));

foreach(
	undef,
	sclstr_upgraded("\x{2603}foo"),
	${qr/foo/},
	*foo,
	\1,
	[],
	{},
	sub{},
	qr/foo/,
	\*foo,
	bless({}),
) {
	eval { shash_exists($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_getd($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_length($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_get($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_set($sh, $_, "y") };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_gset($sh, $_, "y") };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_cset($sh, $_, "y", "z") };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_key_ge($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_key_gt($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_key_le($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	eval { shash_key_lt($sh, $_) };
	like $@, qr/\Akey is not an octet string at /;
	SKIP: {
		skip "copying mangles regexps on this Perl", 4
			if "$]" >= 5.011000 && "$]" < 5.011002 &&
			ref(\$_) eq "Regexp";
		no warnings "uninitialized";
		eval { my $e = exists $sh{$_} };
		like $@, qr/\Akey is not an octet string at /;
		eval { my $v = $sh{$_} };
		like $@, qr/\Akey is not an octet string at /;
		eval { $sh{$_} = "y" };
		like $@, qr/\Akey is not an octet string at /;
		eval { delete $sh{$_} };
		like $@, qr/\Akey is not an octet string at /;
	}
}

foreach(
	sclstr_upgraded("\x{2603}foo"),
	defined(${qr/foo/}) ? ${qr/foo/} : \1,
	*foo,
	\1,
	[],
	{},
	sub{},
	qr/foo/,
	\*foo,
	bless({}),
) {
	eval { shash_set($sh, "x", $_) };
	like $@, qr/\Anew value is neither an octet string nor undef at /;
	eval { shash_gset($sh, "x", $_) };
	like $@, qr/\Anew value is neither an octet string nor undef at /;
	eval { shash_cset($sh, "x", $_, "z") };
	like $@, qr/\Acheck value is neither an octet string nor undef at /;
	eval { shash_cset($sh, "x", "y", $_) };
	like $@, qr/\Anew value is neither an octet string nor undef at /;
}

foreach(
	# These tests for tied hash values must omit the glob and regexp
	# test values that were used above, because per [perl #121477]
	# such values get mangled by the tying infrastructure.
	undef,
	sclstr_upgraded("\x{2603}foo"),
	\1,
	[],
	{},
	sub{},
	qr/foo/,
	\*foo,
	bless({}),
) {
	eval { $sh{x} = $_ };
	like $@, qr/\Anew value is not an octet string at /;
}

my $i = 1;

foreach(
	undef,
	${qr/foo/},
	*foo,
	\1,
	[],
	{},
	sub{},
	qr/foo/,
	\*foo,
	bless({}),
) {
	is eval { shash_open($_, "r") }, undef;
	like $@, qr/\Afilename is not a string at /;
	is eval { shash_open("$tmpdir/t".$i++, $_) }, undef;
	like $@, qr/\Amode is not a string at /;
	is eval { Hash::SharedMem::Handle->open($_, "r") }, undef;
	like $@, qr/\Afilename is not a string at /;
	is eval { Hash::SharedMem::Handle->open("$tmpdir/t".$i++, $_) }, undef;
	like $@, qr/\Amode is not a string at /;
	my %h;
	eval { tie %h, "Hash::SharedMem::Handle", $_, "r" };
	like $@, qr/\Afilename is not a string at /;
	eval { tie %h, "Hash::SharedMem::Handle", "$tmpdir/t".$i++, $_ };
	like $@, qr/\Amode is not a string at /;
}

1;