This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
startkve.t: Refactor setting of $errpat
[perl5.git] / t / op / smartkve.t
CommitLineData
cba5a3b0
DG
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
cba5a3b0 5 require './test.pl';
43ece5b1 6 set_up_inc('../lib');
cba5a3b0
DG
7}
8use strict;
9use warnings;
26230909 10no warnings 'experimental::refaliasing';
7ac5715b 11use vars qw($data $array $values $hash $errpat);
cba5a3b0
DG
12
13plan 'no_plan';
14
26230909 15my $empty;
d8065907 16
f861ba67
FC
17sub set_errpat {
18 $errpat = qr/Experimental $_[0] on scalar is now forbidden/;
19}
20
cba5a3b0 21# Keys -- errors
f861ba67 22set_errpat 'keys';
7ac5715b
FC
23
24eval "keys undef";
26230909 25like($@, $errpat,
7ac5715b
FC
26 'Errors: keys undef throws error'
27);
28
29undef $empty;
30eval q"keys $empty";
26230909 31like($@, $errpat,
7ac5715b
FC
32 'Errors: keys $undef throws error'
33);
34
35is($empty, undef, 'keys $undef does not vivify $undef');
36
cba5a3b0 37eval "keys 3";
26230909 38like($@, qr/Type of arg 1 to keys must be hash/,
cba5a3b0
DG
39 'Errors: keys CONSTANT throws error'
40);
41
42eval "keys qr/foo/";
26230909 43like($@, $errpat,
cba5a3b0
DG
44 'Errors: keys qr/foo/ throws error'
45);
46
feff7485 47eval q"keys $hash qw/fo bar/";
26230909 48like($@, $errpat,
cba5a3b0
DG
49 'Errors: keys $hash, @stuff throws error'
50) or print "# Got: $@";
51
cba5a3b0 52# Values -- errors
f861ba67 53set_errpat 'values';
7ac5715b
FC
54
55eval "values undef";
26230909 56like($@, $errpat,
7ac5715b
FC
57 'Errors: values undef throws error'
58);
59
60undef $empty;
61eval q"values $empty";
26230909 62like($@, $errpat,
7ac5715b
FC
63 'Errors: values $undef throws error'
64);
65
66is($empty, undef, 'values $undef does not vivify $undef');
67
cba5a3b0 68eval "values 3";
26230909 69like($@, qr/Type of arg 1 to values must be hash/,
cba5a3b0
DG
70 'Errors: values CONSTANT throws error'
71);
72
73eval "values qr/foo/";
26230909 74like($@, $errpat,
cba5a3b0
DG
75 'Errors: values qr/foo/ throws error'
76);
77
feff7485 78eval q"values $hash qw/fo bar/";
26230909 79like($@, $errpat,
cba5a3b0
DG
80 'Errors: values $hash, @stuff throws error'
81) or print "# Got: $@";
82
7ac5715b 83# Each -- errors
f861ba67 84set_errpat 'each';
7ac5715b
FC
85
86eval "each undef";
26230909 87like($@, $errpat,
7ac5715b
FC
88 'Errors: each undef throws error'
89);
cba5a3b0
DG
90
91undef $empty;
7ac5715b 92eval q"each $empty";
26230909 93like($@, $errpat,
7ac5715b
FC
94 'Errors: each $undef throws error'
95);
cba5a3b0 96
7ac5715b 97is($empty, undef, 'each $undef does not vivify $undef');
cba5a3b0 98
cba5a3b0 99eval "each 3";
26230909 100like($@, qr/Type of arg 1 to each must be hash/,
cba5a3b0
DG
101 'Errors: each CONSTANT throws error'
102);
103
104eval "each qr/foo/";
26230909 105like($@, $errpat,
cba5a3b0
DG
106 'Errors: each qr/foo/ throws error'
107);
108
feff7485 109eval q"each $hash qw/foo bar/";
26230909 110like($@, $errpat,
cba5a3b0
DG
111 'Errors: each $hash, @stuff throws error'
112) or print "# Got: $@";