This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
09fc71dfc64d770712a29985fa35019ea2f21d72
[perl5.git] / cpan / Devel-PPPort / mktests.PL
1 ################################################################################
2 #
3 #  mktests.PL -- generate test files for Devel::PPPort
4 #
5 ################################################################################
6 #
7 #  $Revision: 33 $
8 #  $Author: mhx $
9 #  $Date: 2010/03/07 13:15:41 +0100 $
10 #
11 ################################################################################
12 #
13 #  Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
14 #  Version 2.x, Copyright (C) 2001, Paul Marquess.
15 #  Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
16 #
17 #  This program is free software; you can redistribute it and/or
18 #  modify it under the same terms as Perl itself.
19 #
20 ################################################################################
21
22 use strict;
23 $^W = 1;
24 require "parts/ppptools.pl";
25
26 my $template = do { local $/; <DATA> };
27
28 generate_tests();
29
30 sub generate_tests
31 {
32   my @tests;
33   my $file;
34
35   for $file (all_files_in_dir('parts/inc')) {
36     my($testfile) = $file =~ /(\w+)\.?$/;  # VMS has a trailing dot
37     $testfile = "t/$testfile.t";
38   
39     my $spec = parse_partspec($file);
40     my $plan = 0;
41   
42     if (exists $spec->{tests}) {
43       exists $spec->{OPTIONS}{tests} &&
44       exists $spec->{OPTIONS}{tests}{plan}
45           or die "No plan for tests in $file\n";
46   
47       print "generating $testfile\n";
48   
49       my $tmpl = $template;
50       $tmpl =~ s/__SOURCE__/$file/mg;
51       $tmpl =~ s/__PLAN__/$spec->{OPTIONS}{tests}{plan}/mg;
52       $tmpl =~ s/^__TESTS__$/$spec->{tests}/mg;
53   
54       open FH, ">$testfile" or die "$testfile: $!\n";
55       print FH $tmpl;
56       close FH;
57   
58       push @tests, $testfile;
59     }
60   }
61   
62   return @tests;
63 }
64
65 __DATA__
66 ################################################################################
67 #
68 #            !!!!!   Do NOT edit this file directly!   !!!!!
69 #
70 #            Edit mktests.PL and/or __SOURCE__ instead.
71 #
72 #  This file was automatically generated from the definition files in the
73 #  parts/inc/ subdirectory by mktests.PL. To learn more about how all this
74 #  works, please read the F<HACKERS> file that came with this distribution.
75 #
76 ################################################################################
77
78 BEGIN {
79   if ($ENV{'PERL_CORE'}) {
80     chdir 't' if -d 't';
81     @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
82     require Config; import Config;
83     use vars '%Config';
84     if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
85       print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
86       exit 0;
87     }
88   }
89   else {
90     unshift @INC, 't';
91   }
92
93   sub load {
94     eval "use Test";
95     require 'testutil.pl' if $@;
96   }
97
98   if (__PLAN__) {
99     load();
100     plan(tests => __PLAN__);
101   }
102 }
103
104 use Devel::PPPort;
105 use strict;
106 $^W = 1;
107
108 package Devel::PPPort;
109 use vars '@ISA';
110 require DynaLoader;
111 @ISA = qw(DynaLoader);
112 bootstrap Devel::PPPort;
113
114 package main;
115
116 __TESTS__