]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/wrapper-environ.t
(no commit message)
[git.ikiwiki.info.git] / t / wrapper-environ.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
5 use Test::More;
6 plan(skip_all => "IPC::Run not available")
7         unless eval q{
8                 use IPC::Run qw(run);
9                 1;
10         };
12 use IkiWiki;
14 use Cwd qw(getcwd);
15 use Errno qw(ENOENT);
17 my $installed = $ENV{INSTALLED_TESTS};
19 my @command;
20 if ($installed) {
21         @command = qw(env PERL5LIB=t/tmp ikiwiki);
22 }
23 else {
24         ok(! system("make -s ikiwiki.out"));
25         @command = qw(env PERL5LIB=t/tmp:blib/lib:blib/arch perl -I. ./ikiwiki.out
26                 --underlaydir=underlays/basewiki
27                 --set underlaydirbase=underlays
28                 --templatedir=templates);
29 }
31 writefile("test.setup", "t/tmp", <<EOF
32 # IkiWiki::Setup::Yaml - YAML formatted setup file
33 wikiname: this is the name of my wiki
34 srcdir: t/tmp/in
35 destdir: t/tmp/out
36 url: http://localhost
37 cgiurl: http://localhost/ikiwiki.cgi
38 cgi_wrapper: t/tmp/ikiwiki.cgi
39 cgi_wrappermode: 0754
40 add_plugins:
41 - anonok
42 - excessiveenvironment
43 anonok_pagespec: "*"
44 ENV: { 'PERL5LIB': 't/tmp:blib/lib:blib/arch' }
45 EOF
46         );
48 writefile("index.mdwn", "t/tmp/in", "");
50 writefile("IkiWiki/Plugin/excessiveenvironment.pm", "t/tmp", <<'EOF'
51 #!/usr/bin/perl
52 package IkiWiki::Plugin::excessiveenvironment;
53 use warnings;
54 use strict;
55 use IkiWiki;
57 sub import {
58         hook(type => "getsetup", id => "excessiveenvironment", call => \&getsetup);
59         hook(type => "genwrapper", id => "excessiveenvironment", call => \&genwrapper);
60 }
62 sub getsetup {
63         return plugin => {
64                 safe => 0,
65                 rebuild => undef,
66                 section => "rcs",
67         };
68 }
70 sub genwrapper {
71         my @ret;
72         foreach my $j (1..4096) {
73                 push @ret, qq{addenv("VAR$j", "val$j");\n};
74         }
75         return join '', @ret;
76 }
78 1;
79 EOF
80         );
82 my $stdout;
83 ok(! system(@command, qw(--setup t/tmp/test.setup --rebuild --wrappers)), "run ikiwiki");
84 ok(run(["./t/tmp/ikiwiki.cgi"], '<&-', '>', \$stdout, init => sub {
85         $ENV{HTTP_HOST} = "localhost";
86         $ENV{QUERY_STRING} = "do=prefs";
87         $ENV{REQUEST_METHOD} = "GET";
88         $ENV{SCRIPT_NAME} = "/cgi-bin/ikiwiki.cgi";
89         $ENV{SERVER_PORT} = "80"
90 }), "run CGI");
92 done_testing();