root/trunk/postprocessors/usr_bin_env_test

Revision 1386, 1.5 kB (checked in by max, 8 months ago)

usr_bin_env test: A temporary test component to see how painful it will be to modify shepherd from #!/usr/bin/perl to #!/usr/bin/env perl.

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3# A little test to see if users' systems can handle the more
4# portable '#!/usr/bin/env perl' shebang line rather than the
5# current '#!/usr/bin/perl'.
6
7use warnings;
8use strict;
9
10use IO::File;
11use Getopt::Long;
12
13my $progname = "usr_bin_env_test";
14my $version = "0.1";
15
16printf "%s v%s\n",$progname,$version;
17
18my $opt;
19GetOptions(
20        'version'               => \$opt->{version},
21);
22
23exit if ($opt->{version});
24
25print "\nThis is a test component, designed to see whether your\n".
26      "system can happily migrate from '#!/usr/bin/perl' to\n".
27      "'#!/usr/bin/env perl'.\n\n";
28
29my $test_file = 'test_file.pl';
30
31print "Creating test file...\n";
32
33my $fh = new IO::File(">$test_file") || die "can't open $test_file for writing: $!";
34
35print $fh <<EOF
36#!/usr/bin/env perl
37
38use strict;
39use warnings;
40
41print "*** Output from test file: Success! ***";
42
43EOF
44;
45$fh->close;
46
47print "Setting test file as executable...\n";
48system "chmod a+x $test_file" || die "Couldn't set test file as executable: $!";
49
50print "Running test file...\n\n";
51
52local *TF;
53unless (open(TF, './' . $test_file . ' 2>&1|')) 
54{
55    print "Couldn't open test file: $!\n";
56    exit 1;
57}
58
59my $msg = '';
60while (<TF>) 
61{
62    print ": $_";
63    $msg .= $_;
64}
65close (TF);
66
67print "\n";
68
69if ($@)
70{
71    print "Some kind of error: $@\n";
72    exit 2;
73}
74
75if ($msg)
76{
77    chomp $msg;
78    $msg =~ s/(.*) at .*\/(.*)/$1 at $2/g;
79}
80if ($?) 
81{
82    printf "Test file exited with %d, output: >>>$msg<<<\n", $? >> 8;
83    exit 3;
84}
85
86print "It worked!\n";
87
88print "Deleting test file...\n";
89unlink $test_file;
90
91print "Finished.\n";
92
93exit 0;
Note: See TracBrowser for help on using the browser.