Checking in changes prior to tagging of version 0.6. Changelog diff is:
[catagits/Test-NoTabs.git] / t / 12-fail.t
1 use strict;
2
3 use Test::More qw(no_plan);
4
5 use File::Temp qw( tempdir tempfile );
6
7 my $perl  = $^X || 'perl';
8 my $inc = join(' -I ', @INC) || '';
9 $inc = "-I $inc" if $inc;
10
11 {
12     my $dir = make_bad_file_1();
13     my ($fh, $outfile) = tempfile();
14     ok( `$perl $inc -MTest::NoTabs -e "all_perl_files_ok( '$dir' )" 2>&1 > $outfile` );
15     local $/ = undef;
16     my $content = <$fh>;
17     like( $content, qr/^not ok 1 - Found tabs in '[^']*' on line 4/m, 'tabs found in tmp file 1' );
18 }
19
20 {
21     my $dir = make_bad_file_2();
22     my ($fh, $outfile) = tempfile();
23     ok( `$perl $inc -MTest::NoTabs -e "all_perl_files_ok( '$dir' )" 2>&1 > $outfile` );
24     local $/ = undef;
25     my $content = <$fh>;
26     like( $content, qr/^not ok 1 - Found tabs in '[^']*' on line 12/m, 'tabs found in tmp file2 ' );
27 }
28
29 {
30     my $file = make_bad_file_3();
31     my ($fh, $outfile) = tempfile();
32     ok( `$perl $inc -MTest::NoTabs -e "all_perl_files_ok( '$file' )" 2>&1 > $outfile` );
33     local $/ = undef;
34     my $content = <$fh>;
35     like( $content, qr/^not ok 1 - Found tabs in '[^']*' on line 6/m, 'tabs found in tmp file 3' );
36 }
37
38 sub make_bad_file_1 {
39   my $tmpdir = tempdir();
40   my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pL' );
41   print $fh <<"DUMMY";
42 #!perl
43
44 sub main {
45 \tprint "Hello!\n";
46 }
47 DUMMY
48   return $tmpdir;
49 }
50
51 sub make_bad_file_2 {
52   my $tmpdir = tempdir();
53   my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pL' );
54   print $fh <<"DUMMY";
55 #!perl
56
57 =pod
58
59 =head1 NAME
60
61 test.pL -       A test script
62
63 =cut
64
65 sub main {
66 \tprint "Hello!\n";
67 }
68 DUMMY
69   return $tmpdir;
70 }
71
72 sub make_bad_file_3 {
73   my $tmpdir = tempdir();
74   my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pm' );
75   print $fh <<"DUMMY";
76 use strict;
77
78 package My::Test;
79
80 sub new {
81 \tmy (\$class) = @_;
82 \tmy \$self = bless { }, \$class;
83 \treturn \$self;
84 }
85
86 1;
87 __DATA__
88 nick    gerakines       software engineer       22
89 DUMMY
90   return $filename;
91 }
92