]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/wrapper-environ.t
does not seem possible
[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),
26                 "-I".getcwd, qw(./ikiwiki.out
27                 --underlaydir=underlays/basewiki
28                 --set underlaydirbase=underlays
29                 --templatedir=templates));
30 }
32 ok(! system("rm -rf t/tmp"));
34 writefile("test.setup", "t/tmp", <<EOF
35 # IkiWiki::Setup::Yaml - YAML formatted setup file
36 wikiname: this is the name of my wiki
37 srcdir: t/tmp/in
38 destdir: t/tmp/out
39 url: http://localhost
40 cgiurl: http://localhost/ikiwiki.cgi
41 cgi_wrapper: t/tmp/ikiwiki.cgi
42 cgi_wrappermode: 0754
43 add_plugins:
44 - anonok
45 - excessiveenvironment
46 anonok_pagespec: "*"
47 ENV: { 'PERL5LIB': 't/tmp:blib/lib:blib/arch' }
48 EOF
49         );
51 writefile("index.mdwn", "t/tmp/in", "");
53 writefile("IkiWiki/Plugin/excessiveenvironment.pm", "t/tmp", <<'EOF'
54 #!/usr/bin/perl
55 package IkiWiki::Plugin::excessiveenvironment;
56 use warnings;
57 use strict;
58 use IkiWiki;
60 sub import {
61         hook(type => "getsetup", id => "excessiveenvironment", call => \&getsetup);
62         hook(type => "genwrapper", id => "excessiveenvironment", call => \&genwrapper);
63 }
65 sub getsetup {
66         return plugin => {
67                 safe => 0,
68                 rebuild => undef,
69                 section => "rcs",
70         };
71 }
73 sub genwrapper {
74         my @ret;
75         foreach my $j (1..4096) {
76                 push @ret, qq{addenv("VAR$j", "val$j");\n};
77         }
78         return join '', @ret;
79 }
81 1;
82 EOF
83         );
85 my $stdout;
86 ok(! system(@command, qw(--setup t/tmp/test.setup --rebuild --wrappers)), "run ikiwiki");
87 ok(run(["./t/tmp/ikiwiki.cgi"], '<&-', '>', \$stdout, init => sub {
88         $ENV{HTTP_HOST} = "localhost";
89         $ENV{QUERY_STRING} = "do=prefs";
90         $ENV{REQUEST_METHOD} = "GET";
91         $ENV{SCRIPT_NAME} = "/cgi-bin/ikiwiki.cgi";
92         $ENV{SERVER_PORT} = "80"
93 }), "run CGI");
95 done_testing();