xref: /openbsd-src/gnu/usr.bin/perl/t/op/upgrade.t (revision 9f11ffb7133c203312a01e4b986886bc88c7d74b)
143003dfeSmillert#!./perl -w
243003dfeSmillert
343003dfeSmillert# Check that we can "upgrade" from anything to anything else.
443003dfeSmillert# Curiously, before this, lib/Math/Trig.t was the only code anywhere in the
543003dfeSmillert# build or testsuite that upgraded an NV to an RV
643003dfeSmillert
743003dfeSmillertBEGIN {
8b8851fccSafresh1    chdir 't' if -d 't';
943003dfeSmillert    require './test.pl';
10*9f11ffb7Safresh1    set_up_inc('../lib');
1143003dfeSmillert}
1243003dfeSmillert
1343003dfeSmillertuse strict;
1443003dfeSmillert
1543003dfeSmillertmy $null;
1643003dfeSmillert
1743003dfeSmillert$! = 1;
1843003dfeSmillertmy %types = (
1943003dfeSmillert    null => $null,
2043003dfeSmillert    iv => 3,
2143003dfeSmillert    nv => .5,
2243003dfeSmillert    rv => [],
2343003dfeSmillert    pv => "Perl rules",
2443003dfeSmillert    pviv => 3,
2543003dfeSmillert    pvnv => 1==1,
2643003dfeSmillert    pvmg => $^,
2743003dfeSmillert);
2843003dfeSmillert
2943003dfeSmillert# This is somewhat cheating but I can't think of anything built in that I can
3043003dfeSmillert# copy that already has type PVIV
3143003dfeSmillert$types{pviv} = "Perl rules!";
3243003dfeSmillert
3343003dfeSmillert# use Devel::Peek; Dump $pvmg;
3443003dfeSmillert
3543003dfeSmillertmy @keys = keys %types;
3643003dfeSmillertplan tests => @keys * @keys;
3743003dfeSmillert
3843003dfeSmillertforeach my $source_type (@keys) {
3943003dfeSmillert    foreach my $dest_type (@keys) {
4043003dfeSmillert	# Pads re-using variables might contaminate this
4143003dfeSmillert	my $vars = {};
4243003dfeSmillert	$vars->{dest} = $types{$dest_type};
4343003dfeSmillert	$vars->{source} = $types{$source_type};
4443003dfeSmillert	# The assignment can potentially trigger assertion failures, so it's
4543003dfeSmillert	# useful to have the diagnostics about what was attempted printed first
4643003dfeSmillert	print "# Assigning $source_type to $dest_type\n";
4743003dfeSmillert	$vars->{dest} = $vars->{source};
4843003dfeSmillert	is ($vars->{dest}, $vars->{source});
4943003dfeSmillert    }
5043003dfeSmillert}
51