]>
git.proxmox.com Git - perlmod.git/blob - test.pl
18 # Let's combine stderr and stdout:
19 POSIX
::dup2
(fileno(STDOUT
), fileno(STDERR
));
21 my $v = RSPM
::Bless-
>new("Hello");
23 $v->something_nonraw();
24 my ($a, $b, $c) = $v->multi_return();
25 say "Got ($a, $b, $c)";
26 my @ret = $v->multi_return();
27 say "Got: ".scalar(@ret)." values: @ret";
31 my $param = { a
=> 1 };
33 print "These should be called with a valid substr:\n";
34 RSPM
::Foo142
::test
(substr($s, 3, 3));
35 RSPM
::Foo142
::teststr
(substr($s, 3, 3));
36 print "Parameter exists: " . (exists($param->{x
}) ?
"YES" : "NO") . "\n";
37 RSPM
::Foo142
::test
($param->{x
});
38 print "Was auto-vivified: " . (exists($param->{x
}) ?
"YES" : "NO") . "\n";
39 RSPM
::Foo142
::teststr
($param->{x
});
41 my $a = "Can I have some coffee please?\n";
43 my $b = RSPM
::Foo142
::test_serde
($a);
45 my $c = RSPM
::Foo142
::test_serde
($b);
49 binmode STDOUT
, ':utf8';
50 my $a = "Can I have some ☕ please?\n";
52 my $b = RSPM
::Foo142
::test_serde
($a);
54 my $c = RSPM
::Foo142
::test_serde
($b);
60 my $state = $param->{tristate
};
61 $state = int($state) if defined($state);
64 if (defined($state)) {
65 $a = $state ?
"Some(true)" : "Some(false)";
70 my $b = RSPM
::Option
::to_string
($state);
71 my $c = RSPM
::Option
::struct_to_string
({ 'tristate' => $state });
78 to_string
({ 'tristate' => '0' });
79 to_string
({ 'tristate' => '1' });
80 to_string
({ 'tristate' => undef });
82 my $ref1 = { x
=> "x was stored" };
83 my $ref2 = RSPM
::Foo142
::test_refs
({ copied
=> "copied string", reference
=> $ref1 });
84 print($ref1->{x
}, "\n");
85 $ref2->{x
} = "x was changed";
86 print($ref1->{x
}, "\n");
88 my $magic = RSPM
::Magic-
>new('magic test');
91 sub test_unsafe_clone
($) {
93 eval { $bad->call() };
95 die "cloned object not properly detected!\n";
96 } elsif ($@ ne "value blessed into RSPM::Magic did not contain its declared magic pointer\n") {
97 die "cloned object error message changed to: [$@]\n";
100 print("unsafe dclone dropped\n");
103 print("Testing unsafe dclone\n");
104 test_unsafe_clone
(Storable
::dclone
($magic));
106 print("Testing unsafe clone\n");
107 test_unsafe_clone
(Clone
::clone
($magic));
110 print("Testing enum deserialization\n");
111 my $ra = RSPM
::Foo142
::test_enums
("something");
112 die "unexpected result from test_enums: $ra\n" if $ra ne 'result-a';
114 print("Testing optional parameters\n");
115 RSPM
::Foo142
::test_trailing_optional
(1, 99);
116 RSPM
::Foo142
::test_trailing_optional
(2, undef);
117 RSPM
::Foo142
::test_trailing_optional
(3);
119 print("Substring test\n");
120 my $orig = "OneTwoThree";
121 my $sub = RSPM
::Foo142
::test_substr_return
($orig);
122 print("[$orig] [$sub]\n");