⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constant.t

📁 source of perl for linux application,
💻 T
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl -wBEGIN {    if( $ENV{PERL_CORE} ) {        chdir 't' if -d 't';        @INC = '../lib';    }    use Config;    unless ($Config{usedl}) {	print "1..0 # no usedl, skipping\n";	exit 0;    }}# use warnings;use strict;use ExtUtils::MakeMaker;use ExtUtils::Constant qw (C_constant autoload);use File::Spec;use Cwd;my $do_utf_tests = $] > 5.006;my $better_than_56 = $] > 5.007;# For debugging set this to 1.my $keep_files = 0;$| = 1;# Because were are going to be changing directory before running Makefile.PLmy $perl = $^X;# 5.005 doesn't have new enough File::Spec to have rel2abs. But actually we# only need it when $^X isn't absolute, which is going to be 5.8.0 or later# (where ExtUtils::Constant is in the core, and tests against the uninstalled# perl)$perl = File::Spec->rel2abs ($perl) unless $] < 5.006;# ExtUtils::Constant::C_constant uses $^X inside a comment, and we want to# compare output to ensure that it is the same. We were probably run as ./perl# whereas we will run the child with the full path in $perl. So make $^X for# us the same as our child will see.$^X = $perl;my $lib = $ENV{PERL_CORE} ? '../../../lib' : '../../blib/lib';my $runperl = "$perl \"-I$lib\"";print "# perl=$perl\n";my $make = $Config{make};$make = $ENV{MAKE} if exists $ENV{MAKE};if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }# VMS may be using something other than MMS/MMKmy $mms_or_mmk = 0;if ($^O eq 'VMS') {   $mms_or_mmk = 1 if (($make eq 'MMK') || ($make eq 'MMS'));}# Renamed by make cleanmy $makefile = ($mms_or_mmk ? 'descrip' : 'Makefile');my $makefile_ext = ($mms_or_mmk ? '.mms' : '');my $makefile_rename = $makefile . ($mms_or_mmk ? '.mms_old' : '.old');my $output = "output";my $package = "ExtTest";my $dir = "ext-$$";my $subdir = 0;# The real test counter.my $realtest = 1;my $orig_cwd = cwd;my $updir = File::Spec->updir;die "Can't get current directory: $!" unless defined $orig_cwd;print "# $dir being created...\n";mkdir $dir, 0777 or die "mkdir: $!\n";END {  if (defined $orig_cwd and length $orig_cwd) {    chdir $orig_cwd or die "Can't chdir back to '$orig_cwd': $!";    use File::Path;    print "# $dir being removed...\n";    rmtree($dir) unless $keep_files;  } else {    # Can't get here.    die "cwd at start was empty, but directory '$dir' was created" if $dir;  }}chdir $dir or die $!;push @INC, '../../lib', '../../../lib';package TieOut;sub TIEHANDLE {    my $class = shift;    bless(\( my $ref = ''), $class);}sub PRINT {    my $self = shift;    $$self .= join('', @_);}sub PRINTF {    my $self = shift;    $$self .= sprintf shift, @_;}sub read {    my $self = shift;    return substr($$self, 0, length($$self), '');}package main;sub check_for_bonus_files {  my $dir = shift;  my %expect = map {($^O eq 'VMS' ? lc($_) : $_), 1} @_;  my $fail;  opendir DIR, $dir or die "opendir '$dir': $!";  while (defined (my $entry = readdir DIR)) {    $entry =~ s/\.$// if $^O eq 'VMS';  # delete trailing dot that indicates no extension    next if $expect{$entry};    print "# Extra file '$entry'\n";    $fail = 1;  }  closedir DIR or warn "closedir '.': $!";  if ($fail) {    print "not ok $realtest\n";  } else {    print "ok $realtest\n";  }  $realtest++;}sub build_and_run {  my ($tests, $expect, $files) = @_;  my $core = $ENV{PERL_CORE} ? ' PERL_CORE=1' : '';  my @perlout = `$runperl Makefile.PL $core`;  if ($?) {    print "not ok $realtest # $runperl Makefile.PL failed: $?\n";    print "# $_" foreach @perlout;    exit($?);  } else {    print "ok $realtest\n";  }  $realtest++;  if (-f "$makefile$makefile_ext") {    print "ok $realtest\n";  } else {    print "not ok $realtest\n";  }  $realtest++;  my @makeout;  if ($^O eq 'VMS') { $make .= ' all'; }  # Sometimes it seems that timestamps can get confused  # make failed: 256  # Makefile out-of-date with respect to Makefile.PL  # Cleaning current config before rebuilding Makefile...  # make -f Makefile.old clean > /dev/null 2>&1 || /bin/sh -c true  # ../../perl "-I../../../lib" "-I../../../lib" Makefile.PL "PERL_CORE=1"  # Checking if your kit is complete...                           # Looks good  # Writing Makefile for ExtTest  # ==> Your Makefile has been rebuilt. <==  # ==> Please rerun the make command.  <==  # false  my $timewarp = (-M "Makefile.PL") - (-M "$makefile$makefile_ext");  # Convert from days to seconds  $timewarp *= 86400;  print "# Makefile.PL is $timewarp second(s) older than $makefile$makefile_ext\n";  if ($timewarp < 0) {      # Sleep for a while to catch up.      $timewarp = -$timewarp;      $timewarp+=2;      $timewarp = 10 if $timewarp > 10;      print "# Sleeping for $timewarp second(s) to try to resolve this\n";      sleep $timewarp;  }  print "# make = '$make'\n";  @makeout = `$make`;  if ($?) {    print "not ok $realtest # $make failed: $?\n";    print "# $_" foreach @makeout;    exit($?);  } else {    print "ok $realtest\n";  }  $realtest++;  if ($^O eq 'VMS') { $make =~ s{ all}{}; }  if ($Config{usedl}) {    print "ok $realtest # This is dynamic linking, so no need to make perl\n";  } else {    my $makeperl = "$make perl";    print "# make = '$makeperl'\n";    @makeout = `$makeperl`;    if ($?) {      print "not ok $realtest # $makeperl failed: $?\n";      print "# $_" foreach @makeout;      exit($?);    } else {      print "ok $realtest\n";    }  }  $realtest++;  my $maketest = "$make test";  print "# make = '$maketest'\n";  @makeout = `$maketest`;  if (open OUTPUT, "<$output") {    local $/; # Slurp it - faster.    print <OUTPUT>;    close OUTPUT or print "# Close $output failed: $!\n";  } else {    # Harness will report missing test results at this point.    print "# Open <$output failed: $!\n";  }  $realtest += $tests;  if ($?) {    print "not ok $realtest # $maketest failed: $?\n";    print "# $_" foreach @makeout;  } else {    print "ok $realtest - maketest\n";  }  $realtest++;  if (defined $expect) {      # -x is busted on Win32 < 5.6.1, so we emulate it.      my $regen;      if( $^O eq 'MSWin32' && $] <= 5.006001 ) {	  open(REGENTMP, ">regentmp") or die $!;	  open(XS, "$package.xs")     or die $!;	  my $saw_shebang;	  while(<XS>) {	      $saw_shebang++ if /^#!.*/i ;	      print REGENTMP $_ if $saw_shebang;	  }	  close XS;  close REGENTMP;	  $regen = `$runperl regentmp`;	  unlink 'regentmp';      }      else {	  $regen = `$runperl -x $package.xs`;      }      if ($?) {	  print "not ok $realtest # $runperl -x $package.xs failed: $?\n";	  } else {	      print "ok $realtest - regen\n";	  }      $realtest++;      if ($expect eq $regen) {	  print "ok $realtest - regen worked\n";      } else {	  print "not ok $realtest - regen worked\n";	  # open FOO, ">expect"; print FOO $expect;	  # open FOO, ">regen"; print FOO $regen; close FOO;      }      $realtest++;  } else {    for (0..1) {      print "ok $realtest # skip no regen or expect for this set of tests\n";      $realtest++;    }  }  my $makeclean = "$make clean";  print "# make = '$makeclean'\n";  @makeout = `$makeclean`;  if ($?) {    print "not ok $realtest # $make failed: $?\n";    print "# $_" foreach @makeout;  } else {    print "ok $realtest\n";  }  $realtest++;  check_for_bonus_files ('.', @$files, $output, $makefile_rename, '.', '..');  rename $makefile_rename, $makefile . $makefile_ext    or die "Can't rename '$makefile_rename' to '$makefile$makefile_ext': $!";  unlink $output or warn "Can't unlink '$output': $!";  # Need to make distclean to remove ../../lib/ExtTest.pm  my $makedistclean = "$make distclean";  print "# make = '$makedistclean'\n";  @makeout = `$makedistclean`;  if ($?) {    print "not ok $realtest # $make failed: $?\n";    print "# $_" foreach @makeout;  } else {    print "ok $realtest\n";  }  $realtest++;  check_for_bonus_files ('.', @$files, '.', '..');  unless ($keep_files) {    foreach (@$files) {      unlink $_ or warn "unlink $_: $!";    }  }  check_for_bonus_files ('.', '.', '..');}sub Makefile_PL {  my $package = shift;  ################ Makefile.PL  # We really need a Makefile.PL because make test for a no dynamic linking perl  # will run Makefile.PL again as part of the "make perl" target.  my $makefilePL = "Makefile.PL";  open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";  print FH <<"EOT";#!$perl -wuse ExtUtils::MakeMaker;WriteMakefile(              'NAME'		=> "$package",              'VERSION_FROM'	=> "$package.pm", # finds \$VERSION              (\$] >= 5.005 ?               (#ABSTRACT_FROM => "$package.pm", # XXX add this                AUTHOR     => "$0") : ())             );EOT  close FH or die "close $makefilePL: $!\n";  return $makefilePL;}sub MANIFEST {  my (@files) = @_;  ################ MANIFEST  # We really need a MANIFEST because make distclean checks it.  my $manifest = "MANIFEST";  push @files, $manifest;  open FH, ">$manifest" or die "open >$manifest: $!\n";  print FH "$_\n" foreach @files;  close FH or die "close $manifest: $!\n";  return @files;}sub write_and_run_extension {  my ($name, $items, $export_names, $package, $header, $testfile, $num_tests,      $wc_args) = @_;  my $c = tie *C, 'TieOut';  my $xs = tie *XS, 'TieOut';  ExtUtils::Constant::WriteConstants(C_FH => \*C,				     XS_FH => \*XS,				     NAME => $package,				     NAMES => $items,				     @$wc_args,				     );  my $C_code = $c->read();  my $XS_code = $xs->read();  undef $c;  undef $xs;  untie *C;  untie *XS;  # Don't check the regeneration code if we specify extra arguments to  # WriteConstants. (Fix this to give finer grained control if needed)  my $expect;  $expect = $C_code . "\n#### XS Section:\n" . $XS_code unless $wc_args;  print "# $name\n# $dir/$subdir being created...\n";  mkdir $subdir, 0777 or die "mkdir: $!\n";  chdir $subdir or die $!;  my @files;  ################ Header  my $header_name = "test.h";  push @files, $header_name;  open FH, ">$header_name" or die "open >$header_name: $!\n";  print FH $header or die $!;  close FH or die "close $header_name: $!\n";  ################ XS  my $xs_name = "$package.xs";  push @files, $xs_name;  open FH, ">$xs_name" or die "open >$xs_name: $!\n";  print FH <<"EOT";#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include "$header_name"$C_codeMODULE = $package		PACKAGE = $packagePROTOTYPES: ENABLE$XS_code;EOT  close FH or die "close $xs: $!\n";  ################ PM  my $pm = "$package.pm";  push @files, $pm;  open FH, ">$pm" or die "open >$pm: $!\n";  print FH "package $package;\n";  print FH "use $];\n";  print FH <<'EOT';use strict;EOT  printf FH "use warnings;\n" unless $] < 5.006;  print FH <<'EOT';use Carp;require Exporter;require DynaLoader;use vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD);$VERSION = '0.01';@ISA = qw(Exporter DynaLoader);EOT  # Having this qw( in the here doc confuses cperl mode far too much to be  # helpful. And I'm using cperl mode to edit this, even if you're not :-)  print FH "\@EXPORT_OK = qw(\n";  # Print the names of all our autoloaded constants  print FH "\t$_\n" foreach (@$export_names);  print FH ");\n";  # Print the AUTOLOAD subroutine ExtUtils::Constant generated for us  print FH autoload ($package, $]);  print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";  close FH or die "close $pm: $!\n";  ################ test.pl  my $testpl = "test.pl";  push @files, $testpl;  open FH, ">$testpl" or die "open >$testpl: $!\n";  # Standard test header (need an option to suppress this?)  print FH <<"EOT" or die $!;use strict;use $package qw(@$export_names);print "1..2\n";if (open OUTPUT, ">$output") {  print "ok 1\n";  select OUTPUT;} else {  print "not ok 1 # Failed to open '$output': \$!\n";  exit 1;}EOT  print FH $testfile or die $!;  print FH <<"EOT" or die $!;select STDOUT;if (close OUTPUT) {  print "ok 2\n";} else {  print "not ok 2 # Failed to close '$output': \$!\n";}EOT  close FH or die "close $testpl: $!\n";  push @files, Makefile_PL($package);  @files = MANIFEST (@files);  build_and_run ($num_tests, $expect, \@files);  chdir $updir or die "chdir '$updir': $!";  ++$subdir;}# Tests are arrayrefs of the form# $name, [items], [export_names], $package, $header, $testfile, $num_testsmy @tests;my $before_tests = 4; # Number of "ok"s emitted to build extensionmy $after_tests = 8; # Number of "ok"s emitted after make test runmy $dummytest = 1;my $here;sub start_tests {  $dummytest += $before_tests;  $here = $dummytest;}sub end_tests {  my ($name, $items, $export_names, $header, $testfile, $args) = @_;  push @tests, [$name, $items, $export_names, $package, $header, $testfile,               $dummytest - $here, $args];  $dummytest += $after_tests;}my $pound;if (ord('A') == 193) {  # EBCDIC platform  $pound = chr 177; # A pound sign. (Currency)} else { # ASCII platform  $pound = chr 163; # A pound sign. (Currency)}my @common_items = (                    {name=>"perl", type=>"PV",},                    {name=>"*/", type=>"PV", value=>'"CLOSE"', macro=>1},                    {name=>"/*", type=>"PV", value=>'"OPEN"', macro=>1},                    {name=>$pound, type=>"PV", value=>'"Sterling"', macro=>1},                   );my @args = undef;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -