#!perl use Data::Dumper; my @test_files = split('\s+',`ls generic/t.* xdg-*/t.*`); my $cvs_pre = "http://webcvs.freedesktop.org/portland/portland/xdg-utils/tests/"; my $cvs_post = '?view=markup'; my $assert_doc = "assertions.html"; my $now = scalar localtime; my $style = "\n"; my $root_header = qq{| Tests | Assertions | Overview |
\n}; my $group_header = qq{| Tests | Assertions | Overview |
\n}; my $footer = "
xdg-utils test documentation generated $now\n"; my %fcns; my %group; my %shortdesc; ## Read assertion file open IN, 'include/testassertions.sh' or die "Failed to open assertion file: $!\n"; my $state = 'NULL'; my %assertions; while ( ) { if ( m/(\w+)\s*\(\)/ ) { $state = $1; $assertions{$state} = (); } elsif ( $state ne 'NULL' and m/^#(.*)/ ) { my $txt = $1; chomp $txt; push @{ $assertions{$state} }, $txt; } else { $state = 'NULL'; } } close IN; if ( ! -d 'doc' ) { mkdir 'doc'; } open OUT, ">doc/$assert_doc" or die "Failed to open $assert_doc: $!\n"; print OUT "xdg-utils test assertions$style\n$root_header"; my @s_assert = sort keys %assertions ; print OUT qq{

Defined Assertions in include/testassertions.sh

\n}; for $a ( @s_assert ) { print OUT qq{$a
\n}; } for $a ( @s_assert ) { print OUT qq{

$a

\n}; print OUT "
", join("\n",@{ $assertions{$a} } ), "
\n"; } print OUT "$footer"; ## Read test files for $f ( @test_files ) { open IN, $f or die "Failed to open $f: $!\n"; $f =~ m{(.+)/t\.(.+)}; my $dir = $1; my $test = $2; `mkdir -p doc/$dir`; my $o = "doc/$dir/$test.html"; push @{ $group{$dir} }, $test; open HTM, ">$o" or die "Failed to open '$o': $!\n"; print HTM "xdg-utils test: $f\n"; print HTM $style; print HTM "$group_header

Test: $f


\n"; my $fcn = ''; my $state = 'BEGIN'; while ( ) { #find the test function if ( m/(\w+)\s*\(\)/ ) { $fcn = $1; if (defined $fcns{$fcn} ){ print "WARNING in $f: $fcn already exists in $fcns{$fcn}!\n" } $fcns{$fcn} = $f; $state = 'FUNCTION'; } #find test_start elsif ( m/test_start (.*)/ ) { print HTM "

Purpose of $fcn

"; my $txt = $1; $txt =~ s/\$FUNCNAME:*\s*//; $txt =~ s/\"//g; $shortdesc{ $test } = $txt; print HTM "

$txt

\n"; $state = 'START'; } #find test_purpose elsif ( m/test_purpose (.*)/ ) { print HTM "

Description

"; my $txt = $1; $txt =~ s/\"//g; print HTM "

$txt

\n"; } #find initilization elsif ( m/test_init/ ) { print HTM "

Depencencies

\n"; $state = 'INIT'; next; } elsif ( m/test_procedure/ ) { print HTM "

Test Procedure

\n"; $state = 'TEST'; next; } elsif ( m/test_note (.*)/ ) { print HTM "

Note

$1

\n"; next; } elsif ( m/test_result/ ) { $state = 'DONE'; } if ( m/^#/ ) { next; } if ( $state eq 'INIT' or $state eq 'TEST' ) { $line = $_; $line =~ s/^\s*(\w+)/$1<\/a>/; if ( $assertions{$1} ) { print HTM "

$line

\n"; #print "$f:\t'$1' found\n"; } else { #print "$f:\t'$1' not found\n"; print HTM "

$_

\n"; } #print HTM "

$_

\n"; } } print HTM "$footer\n"; close HTM; close IN; } open INDEX, ">doc/index.html" or die "Could not open index: $!"; print INDEX "xdg-utils test suite\n"; print INDEX $style; print INDEX "$root_header

xdg-utils test documentation

"; my @s_groups = sort keys %group; for $g ( @s_groups ) { print INDEX qq{
$g \n}; } print INDEX "\n"; for $k ( @s_groups ) { print INDEX qq{\n}; for $i ( @{ $group{$k} } ) { print INDEX "\n"; } } print INDEX "

$k

$i$shortdesc{$i}
$footer\n"; close INDEX; #print Dumper keys %assertions;