]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/table.t
bug report
[git.ikiwiki.info.git] / t / table.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Cwd qw(getcwd);
5 use Test::More;
6 use IkiWiki;
8 my $installed = $ENV{INSTALLED_TESTS};
10 my @command;
11 if ($installed) {
12         @command = qw(ikiwiki);
13 }
14 else {
15         ok(! system("make -s ikiwiki.out"));
16         @command = ("perl", "-I".getcwd, qw(./ikiwiki.out
17                 --underlaydir=underlays/basewiki
18                 --set underlaydirbase=underlays
19                 --templatedir=templates));
20 }
22 push @command, qw(--set usedirs=0 --plugin table
23         --url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi
24         t/tmp/in t/tmp/out --verbose);
26 my $blob;
28 ok(! system("rm -rf t/tmp"));
29 ok(! system("mkdir t/tmp"));
31 sub write_old_file {
32         my $name = shift;
33         my $content = shift;
35         writefile($name, "t/tmp/in", $content);
36         ok(utime(333333333, 333333333, "t/tmp/in/$name"));
37 }
39 write_old_file("csv.mdwn",
40 '[[!table format="csv" data="""
41 Key,Value
42 "ASCII","hello"
43 "Not ASCII","¬"
44 """]]');
45 write_old_file("dsv.mdwn",
46 '[[!table format="dsv" data="""
47 Key       | Value
48 ASCII     | hello
49 Not ASCII | ¬
50 """]]');
52 ok(! system(@command));
53 ok(! system(@command, "--refresh"));
55 $blob = readfile("t/tmp/out/dsv.html");
56 like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
57 like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
58 like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);
60 SKIP: {
61         skip "Text::CSV unavailable", 0 unless eval q{use Text::CSV; 1};
63         $blob = readfile("t/tmp/out/csv.html");
64         like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
65         like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
66         like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);
67 }
69 done_testing;