View | Details | Raw Unified | Return to bug 10539
Collapse All | Expand All

(-)a/Makefile.PL (-23 lines)
Lines 1602-1630 sub postamble { Link Here
1602
		$env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1602
		$env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1603
	}
1603
	}
1604
1604
1605
    if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
1606
        if ( open( my $confhandle, '>', 't/test-config.txt' ) ) {
1607
            print $confhandle "# This configuration file lets the t/Makefile prepare a test koha-conf.xml file.\n";
1608
            print $confhandle "# It is generated by the top-level Makefile.PL.\n";
1609
            print $confhandle "# It is separate from the standard koha-conf.xml so that you can edit this by hand and test with different configurations.\n";
1610
1611
            # these directories will be relocated to the 't' directory
1612
            foreach my $dirname ( keys %$target_directories ) {
1613
                my $dir = main::_strip_destdir( $target_directories->{$dirname} );
1614
                if ( exists $test_suite_override_dirs{$dirname} ) {
1615
                    $dir = main::get_test_dir($dirname);
1616
                }
1617
                print $confhandle "$dirname = $dir\n"
1618
            }
1619
            print $confhandle "\n";
1620
1621
            print $confhandle join( "\n", map { "$_ = $config{$_}" } keys( %config ) ), "\n";
1622
            close( $confhandle );
1623
        } else {
1624
            warn 'unable to open conf file for database dependent tests: $!';
1625
        }
1626
1627
    }
1628
    return "$env\n";
1605
    return "$env\n";
1629
}
1606
}
1630
1607
(-)a/t/Makefile (-111 lines)
Lines 1-111 Link Here
1
2
SHELL = /bin/sh
3
NOOP = $(SHELL) -c true
4
NOECHO = @
5
ECHO = echo
6
MKDIR = /bin/mkdir
7
CP = cp
8
SED = /bin/sed
9
CHMOD = chmod
10
RM = /bin/rm
11
12
# some of these are pretty questionable.
13
PERL = /usr/bin/perl
14
# TEST_FILES = *.t
15
TEST_FILES = database_dependent.pl
16
TEST_CLASS =
17
RUN_EXPENSIVE_TESTS = 0
18
PROVE = /usr/bin/prove
19
PROVE_FLAGS = -v
20
PERL5LIB = ..
21
KOHA_CONF_DIR = ../etc
22
CONF_FILE_TEMPLATE = $(KOHA_CONF_DIR)/koha-conf.xml 
23
TEST_CONF_FILE = run/etc/koha-conf.xml
24
MKPATH = $(PERL) "-MExtUtils::Command" -e mkpath
25
26
TEST_REWRITE_SCRIPT = rewrite-config-test.PL
27
REAL_REWRITE_SCRIPT = ../rewrite-config.PL
28
29
ZEBRA_CONF_DIR = run/etc/zebradb
30
ZEBRA_CONF_FILES = $(ZEBRA_CONF_DIR)/etc/passwd $(ZEBRA_CONF_DIR)/zebra-biblios.cfg $(ZEBRA_CONF_DIR)/zebra-authorities.cfg $(ZEBRA_CONF_DIR)/zebra-authorities-dom.cfg $(ZEBRA_CONF_DIR)/explain-authorities.xml $(ZEBRA_CONF_DIR)/explain-biblios.xml $(ZEBRA_CONF_DIR)/retrieval-info-auth-grs1.xml $(ZEBRA_CONF_DIR)/retrieval-info-auth-dom.xml $(ZEBRA_CONF_DIR)/ccl.properties $(ZEBRA_CONF_DIR)/cql.properties $(ZEBRA_CONF_DIR)/pqf.properties
31
32
SCRIPTS = koha-zebra-ctl.sh koha-pazpar2-ctl.sh koha-index-daemon-ctl.sh
33
SRC_SCRIPT_DIR = ../misc/bin
34
TEST_SCRIPT_DIR = run/bin
35
36
SMOLDER_SERVER = 72.232.235.42:8000
37
SMOLDER_REPORT_FILENAME = kohatests.txt
38
SMOLDER_REPORT_TARBALL = kohatests.tar.gz
39
SMOLDER_PROJECT_NAME = Koha
40
SMOLDER_SMOKE_SIGNAL = ./smolder_smoke_signal
41
42
all ::
43
	$(NOECHO) $(ECHO) RUNNING THIS MAKEFILE MAY CAUSE LOSS OF DATA
44
	$(NOECHO) $(ECHO) 
45
	$(NOECHO) $(ECHO) This makefile is completely beta.
46
	$(NOECHO) $(ECHO) Please read it first and edit the variables at the top.
47
	$(NOECHO) $(ECHO) Then, you can run \'make test\'
48
49
config_file :: $(CONF_FILE_TEMPLATE) test_run_dirs
50
	$(CP) $(CONF_FILE_TEMPLATE)  $(TEST_CONF_FILE)
51
	$(PERL) $(TEST_REWRITE_SCRIPT) --file $(TEST_CONF_FILE)
52
	$(PERL) $(REAL_REWRITE_SCRIPT)  $(TEST_CONF_FILE)
53
54
zebra_conf_files :: test_run_dirs $(ZEBRA_CONF_FILES)
55
56
57
$(ZEBRA_CONF_FILES) ::
58
	$(PERL) $(TEST_REWRITE_SCRIPT) --file $@
59
	$(PERL) $(REAL_REWRITE_SCRIPT)  $@
60
61
$(SCRIPTS) ::
62
	$(SED) s/--user=\$$USER.\$$GROUP// $(SRC_SCRIPT_DIR)/$@ > $(TEST_SCRIPT_DIR)/$@
63
	$(PERL) $(TEST_REWRITE_SCRIPT) --file $(TEST_SCRIPT_DIR)/$@
64
	$(PERL) $(REAL_REWRITE_SCRIPT)  $(TEST_SCRIPT_DIR)/$@
65
	$(CHMOD) 755 $(TEST_SCRIPT_DIR)/$@
66
67
test :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
68
	KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) TEST_CLASS=$(TEST_CLASS) RUN_EXPENSIVE_TESTS=$(RUN_EXPENSIVE_TESTS) \
69
		$(PROVE) $(PROVE_FLAGS) $(TEST_FILES) 
70
71
test-single :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
72
	KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) RUN_EXPENSIVE_TESTS=1 SINGLE_TEST=1 \
73
		$(PROVE) $(PROVE_FLAGS) -Ilib $(TEST_FILES)
74
75
fulltest :: RUN_EXPENSIVE_TESTS = 1
76
fulltest :: test
77
78
test_run_dirs ::
79
	$(MKPATH) run/etc
80
	$(CP) -a ../etc/zebradb run/etc
81
	$(MKPATH) run/etc/zebradb/etc
82
	$(MKPATH) run/var/lib/zebradb/biblios/key
83
	$(MKPATH) run/var/lib/zebradb/biblios/register
84
	$(MKPATH) run/var/lib/zebradb/biblios/shadow
85
	$(MKPATH) run/var/lib/zebradb/biblios/tmp
86
	$(MKPATH) run/var/lib/zebradb/authorities/key
87
	$(MKPATH) run/var/lib/zebradb/authorities/register
88
	$(MKPATH) run/var/lib/zebradb/authorities/shadow
89
	$(MKPATH) run/var/lib/zebradb/authorities/tmp
90
	$(MKPATH) run/var/lock/zebradb/biblios
91
	$(MKPATH) run/var/lock/zebradb/authorities
92
	$(MKPATH) run/var/run/zebradb
93
	$(MKPATH) run/var/log/zebradb
94
	$(MKPATH) run/bin
95
96
submit_report :: $(SMOLDER_REPORT_TARBALL)
97
	$(SMOLDER_SMOKE_SIGNAL) --server $(SMOLDER_SERVER) --file $(SMOLDER_REPORT_TARBALL) --project $(SMOLDER_PROJECT_NAME) --anonymous
98
#	$(RM) $(SMOLDER_REPORT_TARBALL)
99
100
submit :: submit_report
101
102
$(SMOLDER_REPORT_TARBALL) :: $(SMOLDER_REPORT_FILENAME)
103
	tar zcvf $(SMOLDER_REPORT_TARBALL) kohatests.txt
104
	$(RM) $(SMOLDER_REPORT_FILENAME)
105
106
$(SMOLDER_REPORT_FILENAME) :: report
107
108
report :: config_file $(ZEBRA_CONF_FILES) $(SCRIPTS)
109
	-KOHA_CONF=$(TEST_CONF_FILE) PERL5LIB=$(PERL5LIB) TEST_CLASS=$(TEST_CLASS) RUN_EXPENSIVE_TESTS=$(RUN_EXPENSIVE_TESTS) \
110
		$(PERL) $(TEST_FILES) > $(SMOLDER_REPORT_FILENAME)
111
(-)a/t/db_dependent/XISBN.t (-3 lines)
Lines 21-29 BEGIN { Link Here
21
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
21
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
22
*C4::Search::SimpleSearch = \&Mock_SimpleSearch;
22
*C4::Search::SimpleSearch = \&Mock_SimpleSearch;
23
23
24
# KohaTest::clear_test_database();
25
# KohaTest::create_test_database();
26
27
my $context = C4::Context->new;
24
my $context = C4::Context->new;
28
25
29
my ( $biblionumber_tag, $biblionumber_subfield ) =
26
my ( $biblionumber_tag, $biblionumber_subfield ) =
(-)a/t/rewrite-config-test.PL (-180 lines)
Lines 1-179 Link Here
1
# Copyright 2008 LibLime
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
19
use strict;
20
use warnings;
21
22
use Sys::Hostname;
23
use Socket;
24
use Getopt::Long;
25
use Pod::Usage;
26
use Data::Dumper;
27
28
# These variables get set from command line options
29
my ( $fname );
30
GetOptions( 'file=s', \$fname )
31
  or pod2usage();
32
33
34
=head1 NAME
35
36
rewrite-test-config.PL - helper for the Koha packager and installer
37
38
=head1 SYNOPSIS
39
40
	perl rewrite-test-config.PL configurationfile
41
42
=head1 DESCRIPTION
43
44
This helper script replaces keywords in the
45
configuration file with value either supplied through
46
the environment
47
48
I intend to make this part of hte normal make process eventually.
49
50
=head2 KEYWORDS
51
52
The following configuration keywords are available:
53
54
=head1 EXAMPLES
55
56
=cut
57
58
my $configfile = 'test-config.txt';
59
my $configuration = read_config_file( $configfile );
60
61
# Override configuration from the environment
62
foreach my $key (keys %$configuration) {
63
  if (defined($ENV{$key})) {
64
    $configuration->{$key} = $ENV{$key};
65
  }
66
}
67
68
$configuration = add_underscores( $configuration );
69
my %configuration = replace_test_params( $configuration );
70
71
my $file = read_file($fname);
72
$file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg;
73
74
# At this point, file is in 'blib' and by default
75
# has mode a-w.  Therefore, must change permission
76
# to make it writable.  Note that stat and chmod
77
# (the Perl functions) should work on Win32
78
my $old_perm;
79
$old_perm = (stat $fname)[2] & 07777;
80
my $new_perm = $old_perm | 0200;
81
chmod $new_perm, $fname;
82
83
open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
84
print OUTPUT $file;
85
close(OUTPUT);
86
87
chmod $old_perm, $fname;
88
89
=head2 read_config_file
90
91
  takes the filename pointing to the configuration file that the
92
  top-level Makefile wrote
93
94
  returns a hashref that contains the configuration determined by
95
  that file.
96
97
=cut
98
99
sub read_config_file {
100
    my $config_file = shift;
101
    if ( not -e $config_file ) {
102
        die "unable to find configuration file: $config_file";
103
    }
104
    my $config;
105
    if ( open( my $confighandle, '<', $config_file ) ) {
106
        while ( my $line = <$confighandle> ) {
107
            chomp $line;
108
            next if ( $line eq '' );
109
            next if ( $line =~ /^\s*#/ );
110
            my ( $var, $value ) = split( /\s*=\s*/, $line );
111
            $config->{ $var } = $value;
112
        }
113
    } else {
114
        warn "unable to open configuration file: $config_file";
115
        return;
116
    }
117
    return $config;
118
}
119
120
=head2 add_underscores
121
122
=cut
123
124
sub add_underscores {
125
    my $config = shift;
126
    
127
    my $newconfig;
128
    foreach my $key ( keys %$config ) {
129
        $newconfig->{ '__' . $key . '__' } = $config->{ $key };
130
    }
131
    return $newconfig;
132
}
133
134
135
=head2 replace_test_params
136
137
=cut
138
139
sub replace_test_params {
140
    my $config = shift;
141
142
    my $testconfig;
143
    foreach my $key ( keys %$config ) {
144
        if ( $key =~ /^__TEST_/ ) {
145
            my $newkey = $key;
146
            $newkey =~ s/^__TEST_/__/;
147
            $testconfig->{ $newkey } = $config->{ $key };
148
        }
149
    }
150
    # override variables with the "TEST_" variety.
151
    my %newconfig = ( %$config, %$testconfig );
152
    return %newconfig;
153
}
154
155
# Idea taken from perlfaq5
156
sub read_file {
157
  local(*INPUT,$/);
158
  open(INPUT,$_[0]) || die "Can't open $_[0] for read";
159
  my $file = <INPUT>;
160
  return $file;
161
}
162
163
__END__
164
165
166
=head1 SEE ALSO
167
168
Makefile.PL, ExtUtils::MakeMaker(3)
169
170
=head1 ACKNOWLEDGEMENTS
171
172
based on rewrite-config.PL by MJ Ray.
173
174
=head1 AUTHOR
175
176
Andrew Moore <andrew.moore@liblime.com>
177
178
=cut
179
180
- 

Return to bug 10539