Automatisierte Syntaxtests, Framework für spätere Modultests.
[kivitendo-erp.git] / t / 001compile.t
1 # -*- Mode: perl; indent-tabs-mode: nil -*-
2 #
3 # The contents of this file are subject to the Mozilla Public
4 # License Version 1.1 (the "License"); you may not use this file
5 # except in compliance with the License. You may obtain a copy of
6 # the License at http://www.mozilla.org/MPL/
7 #
8 # Software distributed under the License is distributed on an "AS
9 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 # implied. See the License for the specific language governing
11 # rights and limitations under the License.
12 #
13 # The Original Code are the Bugzilla Tests.
14 #
15 # The Initial Developer of the Original Code is Zach Lipton
16 # Portions created by Zach Lipton are
17 # Copyright (C) 2001 Zach Lipton.  All
18 # Rights Reserved.
19 #
20 # Contributor(s): Zach Lipton <zach@zachlipton.com>
21
22
23 #################
24 #Bugzilla Test 1#
25 ###Compilation###
26
27 use strict;
28
29 use lib 't';
30 use lib '../modules/override';
31 use lib '../modules/fallback';
32
33 use Support::Files;
34
35 use Test::More tests => scalar(@Support::Files::testitems);
36
37 # Need this to get the available driver information
38 use DBI;
39 my @DBI_drivers = DBI->available_drivers;
40
41 # Bugzilla requires Perl 5.8.0 now.  Checksetup will tell you this if you run it, but
42 # it tests it in a polite/passive way that won't make it fail at compile time.  We'll
43 # slip in a compile-time failure if it's missing here so a tinderbox on < 5.8 won't
44 # pass and mistakenly let people think Bugzilla works on any perl below 5.8.
45 require 5.008;
46
47 # Capture the TESTOUT from Test::More or Test::Builder for printing errors.
48 # This will handle verbosity for us automatically.
49 my $fh;
50 {
51     local $^W = 0;  # Don't complain about non-existent filehandles
52     if (-e \*Test::More::TESTOUT) {
53         $fh = \*Test::More::TESTOUT;
54     } elsif (-e \*Test::Builder::TESTOUT) {
55         $fh = \*Test::Builder::TESTOUT;
56     } else {
57         $fh = \*STDOUT;
58     }
59 }
60
61 my @testitems = @Support::Files::testitems;
62 my $perlapp = "\"$^X\"";
63
64 # Test the scripts by compiling them
65
66 foreach my $file (@testitems) {
67     $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
68     next if (!$file); # skip null entries
69
70     # Skip mod_perl.pl in all cases. It doesn't compile correctly from the command line.
71     if ($file eq 'mod_perl.pl') {
72         ok(1, "Skipping mod_perl.pl");
73         next;
74     }
75
76     # Check that we have a DBI module to support the DB, if this is a database
77     # module (but not Schema)
78     if ($file =~ m#Bugzilla/DB/([^/]+)\.pm$# && $file ne "Bugzilla/DB/Schema.pm") {
79         if (!grep(lc($_) =~ /$1/i, @DBI_drivers)) {
80             ok(1,$file." - Skipping, as the DBD module not installed");
81             next;
82         }
83     }
84
85     open (FILE,$file);
86     my $bang = <FILE>;
87     close (FILE);
88     my $T = "";
89     if ($bang =~ m/#!\S*perl\s+-.*T/) {
90         $T = "T";
91     }
92     my $command = "$perlapp -c$T -I modules/fallback -I modules/override $file 2>&1";
93     my $loginfo=`$command`;
94     #print '@@'.$loginfo.'##';
95     if ($loginfo =~ /syntax ok$/im) {
96         if ($loginfo ne "$file syntax OK\n") {
97             ok(0,$file." --WARNING");
98             print $fh $loginfo;
99         } else {
100             ok(1,$file);
101         }
102     } else {
103         ok(0,$file." --ERROR");
104         print $fh $loginfo;
105     }
106 }
107
108 exit 0;