summaryrefslogtreecommitdiff
path: root/utils/h2xs.PL
diff options
context:
space:
mode:
authorJonathan Stowe <gellyfish@gellyfish.com>2001-07-16 19:31:21 +0100
committerNick Ing-Simmons <nik@tiuk.ti.com>2001-07-17 07:34:28 +0000
commit11946041b5e3fb6ece0f34961bb0290ea36d7d61 (patch)
treeb92b10b626db173366e0fc6553613f0ae89b1172 /utils/h2xs.PL
parent7efe98a674232612e623f7ff1b0bf033662f21d3 (diff)
downloadperl-11946041b5e3fb6ece0f34961bb0290ea36d7d61.tar.gz
Re: [PATCH h2xs.PL ] use Test::More where appropriate (was Re:
Message-Id: <Pine.LNX.4.33.0107161827570.15520-100000@orpheus.gellyfish.com> p4raw-id: //depot/perl@11391
Diffstat (limited to 'utils/h2xs.PL')
-rw-r--r--utils/h2xs.PL131
1 files changed, 114 insertions, 17 deletions
diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index 292a46169c..c27d24bcd2 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -43,9 +43,9 @@ h2xs - convert .h C header files to Perl extensions
=head1 SYNOPSIS
-B<h2xs> [B<-ACOPXacdfkmx>] [B<-F> addflags] [B<-M> fmask] [B<-n> module_name] [B<-o> tmask] [B<-p> prefix] [B<-s> subs] [B<-v> version] [B<-b> compat_version] [headerfile ... [extra_libraries]]
+B<h2xs> [B<OPTIONS> ...] [headerfile ... [extra_libraries]]
-B<h2xs> B<-h>
+B<h2xs> B<-h>|B<-?>|B<--help>
=head1 DESCRIPTION
@@ -197,6 +197,17 @@ The default is IV (signed integer). Currently all macros found during the
header scanning process will be assumed to have this type. Future versions
of C<h2xs> may gain the ability to make educated guesses.
+=item B<--use-new-tests>
+
+When B<--compat-version> (B<-b>) is present the generated tests will use
+C<Test::More> rather then C<Test> which is the default for versions before
+5.7.2 . C<Test::More> will be added to PREREQ_PM in the generated
+C<Makefile.PL>.
+
+=item B<--use-old-tests>
+
+Will force the generation of test code that uses the older C<Test> module.
+
=item B<-v>, B<--version>=I<version>
Specify a version number for this extension. This version number is added
@@ -462,6 +473,8 @@ OPTIONS:
Perl function names.
-s, --const-subs Create subroutines for specified macros.
-t, --default-type Default type for autoloaded constants
+ --use-new-tests Use Test::More in backward compatible modules
+ --use-old-tests Use the module Test rather than Test::More
-v, --version Specify a version number for this extension.
-x, --autogen-xsubs Autogenerate XSUBs using C::Scan.
@@ -492,7 +505,9 @@ my ($opt_A,
$opt_v,
$opt_x,
$opt_b,
- $opt_t
+ $opt_t,
+ $new_test,
+ $old_test
);
Getopt::Long::Configure('bundling');
@@ -519,7 +534,9 @@ my %options = (
'const-subs|s=s' => \$opt_s,
'default-type|t=s' => \$opt_t,
'version|v=s' => \$opt_v,
- 'autogen-xsubs|x=s' => \$opt_x
+ 'autogen-xsubs|x=s' => \$opt_x,
+ 'use-new-tests' => \$new_test,
+ 'use-old-tests' => \$old_test
);
GetOptions(%options) || usage;
@@ -529,8 +546,8 @@ usage if $opt_h;
if( $opt_b ){
usage "You cannot use -b and -m at the same time.\n" if ($opt_b && $opt_m);
$opt_b =~ /^\d+\.\d+\.\d+/ ||
- usage "You must provide the backwards compatibility version in X.Y.Z form. " .
- "(i.e. 5.5.0)\n";
+ usage "You must provide the backwards compatibility version in X.Y.Z form. "
+ . "(i.e. 5.5.0)\n";
my ($maj,$min,$sub) = split(/\./,$opt_b,3);
$compat_version = sprintf("%d.%03d%02d",$maj,$min,$sub);
}
@@ -1104,6 +1121,13 @@ my $pod = <<"END" unless $opt_P;
# use $module;
# blah blah blah
#
+#=head1 ABSTRACT
+#
+# This should be the abstract for $module.
+# The abstract is used when making PPD (Perl Package Description) files.
+# If you don't want an ABSTRACT you should also edit Makefile.PL to
+# remove the ABSTRACT_FROM option.
+#
#=head1 DESCRIPTION
#
#Stub documentation for $module, created by h2xs. It looks like the
@@ -1623,6 +1647,17 @@ EOP
warn "Writing $ext$modpname/Makefile.PL\n";
open(PL, ">Makefile.PL") || die "Can't create $ext$modpname/Makefile.PL: $!\n";
+my $prereq_pm;
+
+if ( $compat_version < 5.00702 and $new_test )
+{
+ $prereq_pm = q%'Test::More' => 0%;
+}
+else
+{
+ $prereq_pm = '';
+}
+
print PL <<END;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
@@ -1630,7 +1665,7 @@ use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => '$module',
'VERSION_FROM' => '$modfname.pm', # finds \$VERSION
- 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1
+ 'PREREQ_PM' => {$prereq_pm}, # e.g., Module::Name => 1.1
(\$] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => '$modfname.pm', # retrieve abstract from module
AUTHOR => '$author <$email>') : ()),
@@ -1669,6 +1704,18 @@ open(RM, ">README") || die "Can't create $ext$modpname/README:$!\n";
my $thisyear = (gmtime)[5] + 1900;
my $rmhead = "$modpname version $TEMPLATE_VERSION";
my $rmheadeq = "=" x length($rmhead);
+
+my $rm_prereq;
+
+if ( $compat_version < 5.00702 and $new_test )
+{
+ $rm_prereq = 'Test::More';
+}
+else
+{
+ $rm_prereq = 'blah blah blah';
+}
+
print RM <<_RMEND_;
$rmhead
$rmheadeq
@@ -1697,7 +1744,7 @@ DEPENDENCIES
This module requires these other modules and libraries:
- blah blah blah
+ $rm_prereq
COPYRIGHT AND LICENCE
@@ -1720,6 +1767,7 @@ warn "Writing $ext$modpname/$testfile\n";
my $tests = @const_names ? 2 : 1;
open EX, ">$testfile" or die "Can't create $ext$modpname/$testfile: $!\n";
+
print EX <<_END_;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
@@ -1728,22 +1776,34 @@ print EX <<_END_;
# change 'tests => $tests' to 'tests => last_test_to_print';
+_END_
+
+my $test_mod = 'Test::More';
+
+if ( $old_test or ($compat_version < 5.007 and not $new_test ))
+{
+ my $test_mod = 'Test';
+
+ print EX <<_END_;
use Test;
BEGIN { plan tests => $tests };
use $module;
ok(1); # If we made it this far, we're ok.
_END_
-if (@const_names) {
- my $const_names = join " ", @const_names;
- print EX <<'_END_';
+
+ if (@const_names) {
+ my $const_names = join " ", @const_names;
+ print EX <<'_END_';
my $fail;
foreach my $constname (qw(
_END_
- print EX wrap ("\t", "\t", $const_names);
- print EX (")) {\n");
- print EX <<_END_;
+
+ print EX wrap ("\t", "\t", $const_names);
+ print EX (")) {\n");
+
+ print EX <<_END_;
next if (eval "my \\\$a = \$constname; 1");
if (\$\@ =~ /^Your vendor has not defined $module macro \$constname/) {
print "# pass: \$\@";
@@ -1759,14 +1819,51 @@ if (\$fail) {
}
_END_
+ }
+}
+else
+{
+ print EX <<_END_;
+use Test::More tests => $tests;
+BEGIN { use_ok('$module') };
+
+_END_
+
+ if (@const_names) {
+ my $const_names = join " ", @const_names;
+ print EX <<'_END_';
+
+my $fail = 0;
+foreach my $constname (qw(
+_END_
+
+ print EX wrap ("\t", "\t", $const_names);
+ print EX (")) {\n");
+
+ print EX <<_END_;
+ next if (eval "my \\\$a = \$constname; 1");
+ if (\$\@ =~ /^Your vendor has not defined $module macro \$constname/) {
+ print "# pass: \$\@";
+ } else {
+ print "# fail: \$\@";
+ \$fail = 1;
+ }
+
+}
+
+ok( \$fail == 0 , 'Constants' );
+_END_
+ }
}
-print EX <<'_END_';
+
+print EX <<_END_;
#########################
-# Insert your test code below, the Test module is use()ed here so read
-# its man page ( perldoc Test ) for help writing this test script.
+# Insert your test code below, the $test_mod module is use()ed here so read
+# its man page ( perldoc $test_mod ) for help writing this test script.
_END_
+
close(EX) || die "Can't close $ext$modpname/$testfile: $!\n";
unless ($opt_C) {