Startup: Include-Pfade mittels FindBin ermitteln
[kivitendo-erp.git] / t / test.pl
1 #!/usr/bin/perl -X
2
3 use strict;
4
5 use Data::Dumper;
6 use File::Find ();
7 use Test::Harness qw(runtests execute_tests);
8 use Getopt::Long;
9
10 BEGIN {
11   use FindBin;
12
13   unshift(@INC, $FindBin::Bin . '/../modules/override'); # Use our own versions of various modules (e.g. YAML).
14   push   (@INC, $FindBin::Bin . '/..');                  # '.' will be removed from @INC soon.
15   push   (@INC, $FindBin::Bin . '/../modules/fallback'); # Only use our own versions of modules if there's no system version.
16
17   $ENV{HARNESS_OPTIONS} = 'c';
18
19   chdir($FindBin::Bin . '/..');
20 }
21
22 my @exclude_for_fast = (
23   't/001compile.t',
24   't/003safesys.t',
25 );
26
27 sub find_files_to_test {
28   my @files;
29   File::Find::find(sub { push @files, $File::Find::name if (-f $_) && m/\.t$/ }, 't');
30   return @files;
31 }
32
33 my (@tests_to_run, @tests_to_run_first);
34
35 GetOptions(
36   'f|fast' => \ my $fast,
37 );
38
39 if (@ARGV) {
40   @tests_to_run       = @ARGV;
41
42 } else {
43   @tests_to_run_first = qw(t/000setup_database.t);
44   my %exclude         = map  { ($_ => 1)     } @tests_to_run_first, (@exclude_for_fast)x!!$fast;
45   @tests_to_run       = grep { !$exclude{$_} } sort(find_files_to_test());
46 }
47
48 if (@tests_to_run_first) {
49   my ($total, $failed) = execute_tests(tests => \@tests_to_run_first);
50   exit(1) unless !$total->{bad} && (0 < $total->{max});
51 }
52
53 runtests(@tests_to_run);