File: generate_without_optional_dependencies_wrappers.PL

package info (click to toggle)
libperl-critic-perl 1.088-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,792 kB
  • ctags: 1,556
  • sloc: perl: 17,417; lisp: 340; makefile: 2
file content (156 lines) | stat: -rw-r--r-- 4,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env perl

##############################################################################
#      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/generate_without_optional_dependencies_wrappers.PL $
#     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
#   $Author: clonezone $
# $Revision: 2489 $
##############################################################################

use 5.006001;
use strict;
use warnings;

use lib 'inc';

use English qw{-no_match_vars};
use Readonly;
use Carp qw{ confess };
use Fatal qw{ open close };

use Perl::Critic::BuildUtilities qw{ recommended_module_versions };

our $VERSION = '1.088';

Readonly::Scalar my $GENERATED_DIRECTORY => 'xt/author/generated/';

if ( not -d $GENERATED_DIRECTORY ) {
    print
        "\n\nSkipping generating tests because it doesn't ",
        "look like we're in an author environment.\n\n";
    exit 0;
}

print "\n\nGenerating tests that hide modules and then run other tests.\n";

my $this_program = __FILE__;

my @modules_to_hide = sort keys %{ { recommended_module_versions } };
my $modules_to_hide = join "\n" . q< > x 4, @modules_to_hide;

foreach my $test_program_name (@ARGV) {
    my ($wrapped_test_name) =
        $test_program_name =~ m<
            \A
            $GENERATED_DIRECTORY
            ( (?: t | xt/author ) / [\w.]+ \.t ) # test to be wrapped
            _without_optional_dependencies\.t   # suffix the new test will have
            \z
        >xmso;
    if (not $wrapped_test_name) {
        confess
              'Could not figure out the name of the test to wrap from "'
            . $test_program_name
            . q{".};
    }

    print "Generating $test_program_name.\n";
    open my $test_program, '>', $test_program_name
        or die "Could not open $test_program_name: $ERRNO";

    print {$test_program} <<"END_TEST_PROGRAM";
#!/usr/bin/env perl

# Do not edit!!!  This program generated by $this_program.

use strict;
use warnings;

use English qw{-no_match_vars};

use lib 't/tlib';

use Perl::Critic::TestUtilitiesWithMinimalDependencies qw{
    get_skip_all_tests_tap
};

our \$VERSION = $VERSION;

#-----------------------------------------------------------------------------

eval <<'END_HIDE_MODULES';
use Test::Without::Module qw{
    $modules_to_hide
};
END_HIDE_MODULES

if ( \$EVAL_ERROR ) {
    print
        get_skip_all_tests_tap(),
        'Test::Without::Module required to test with the ',
        "absence of optional modules\\n";
    exit 0;
}


require '$wrapped_test_name';
END_TEST_PROGRAM

    close $test_program;
}

print "Done.\n\n";

__END__

#-----------------------------------------------------------------------------

=pod

=for stopwords 

=head1 NAME

generate_without_additional_dependencies_wrappers.PL - generate tests that are wrappers around other tests but which hide the existence of modules first.


=head1 SYNOPSIS

  generate_without_additional_dependencies_wrappers.PL \
      t/00_modules.t_without_optional_dependencies.t \
      t/01_config.t_without_optional_dependencies.t \
      t/13_bundled_policies.t_without_optional_dependencies.t


=head1 DESCRIPTION

Release 1.07 of Perl::Critic was an embarrassment because there were no tests
of core without the presence of optional modules.  This program generates
wrappers for other tests that hide those optional modules.


=head1 AUTHOR

Elliot Shank C<< <perl@galumph.org> >>


=head1 COPYRIGHT

Copyright (c) 2007-2008 Elliot Shank.  All rights reserved.

This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.  The full text of this license can be found in
the LICENSE file included with this module.


=cut

##############################################################################
# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 78
#   indent-tabs-mode: nil
#   c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :