#!/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<< >> =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 :