Imported Robodoc.
[robodoc.git] / Source / t / basics.t
1 #!perl
2 # vi: spell ff=unix
3 #------------------------------------------------------------------------------
4 use strict;
5 use warnings;
6 use ROBOTestFrame;
7 use Test::More 'no_plan';
8 use Test::File;
9 use XML::Simple;
10
11 #****h* ROBODoc System Tests/Basics
12 # FUNCTION
13 #   Tests basic ROBODoc funcionallity.  These are all
14 #   'happy paths'.
15 #
16 #****
17
18 #****v* Basics/Dummy Headers
19 # FUNCTION
20 #   A dummy header to put into dummy source files.
21 # SOURCE
22 #
23 my $source = <<'EOF';
24 /****f* Test/test
25  * NAME
26  *   Test
27  ******
28  */
29 EOF
30 #*****
31
32 #****x* Basics/Option version
33 # FUNCTION
34 #   Test robodoc --version, this should report the current version.
35 # SOURCE
36 {
37     my ( $out, $err ) = runrobo('--version');
38     like( $out, qr/\d+\.\d+.\d+/, '--version should print version number' );
39     is( $err, '', '... and no error' );
40 }
41 #****
42
43 #****x* Basics/Option help
44 # FUNCTION 
45 #   Test the option --help.
46 # SOURCE
47 {
48     my ( $out, $err ) = runrobo('--help');
49     like( $out, qr/ROBODoc Version/, '--help should print version number' );
50     is( $err, '', '... and no error' );
51 }
52 #****
53
54
55 #****x* Basics/Option multidoc
56 # FUNCTION
57 #   Test --multidoc for html output format.
58 #   (Multidoc for other modes does not make much sense).
59 #   We create one source file with a simple header and create multidoc
60 # SOURCE
61 {
62     add_source( "test.c", $source );
63     my ( $out, $err ) = runrobo(qw(--src Src --doc Doc --multidoc --html));
64     # expected results:
65     is( $out, '', 'No ouput' );
66     is( $err, '', '... and no error' );
67     file_exists_ok( "Doc/test_c.html", 'there should be documentation' );
68     file_exists_ok( "Doc/robodoc.css", 'and a stylesheet' );
69
70     clean();
71 }
72 #****
73
74
75 # TODO FS
76 # test --multidoc for --troff
77 #
78
79 # TODO FS
80 # test --css
81 #
82
83 #****x* Basics/Singledoc Outputmode with Different Formats
84 # FUNCTION
85 #   Test singledoc mode  for all supported output formats 
86 #   and see if it creates output in this format.
87 #
88 # SOURCE
89
90 {
91     add_source( "test.c", $source );
92
93     my %output_modes = (
94         '--html'  => 'html',
95         '--rtf'   => 'rtf',
96         '--test'  => 'xml', 
97         '--latex' => 'tex',
98         '--dbxml' => 'xml',
99     );
100
101     foreach my $mode ( keys %output_modes ) {
102         my $file_extension = $output_modes{$mode};
103
104         my @arguments = qw(--src Src --doc testdoc --singledoc);
105         push( @arguments, $mode );
106
107         my ( $out, $err ) = runrobo(@arguments);
108         is( $out, '', 'No ouput' );
109         is( $err, '', '... and no error' );
110         file_exists_ok( "testdoc.$file_extension",
111             'there should be documentation' );
112         if ( $mode eq "--html" ) {
113             file_exists_ok( "testdoc.css", 'and a stylesheet' );
114         }
115
116         unlink("testdoc.$file_extension") if -e "testdoc.$file_extension";
117         unlink('testdoc.css')             if -e 'testdoc.css';
118
119     }
120
121     clean();
122 }
123
124 #****
125
126 #****v* Basics/test_source_2
127 # FUNCTION
128 #   A dummy header to put into dummy source files.
129 #   This one has headers at several levels.
130 # SOURCE
131 #
132 my $test_source_2 = <<'EOF';
133 /****f* Level_1/Level_2
134  * NAME
135  *   Test
136  ******
137  */
138
139 /****f* Level_2/_Level_3
140  * NAME
141  *   Test
142  ******
143  */
144
145 /****f* Level_3/_Level_4
146  * NAME
147  *   Test
148  ******
149  */
150
151 EOF
152 #*****
153
154
155 #****x* Basics/Option first section level
156 # FUNCTION
157 #   Test --first_section_level.
158 #
159 #   The level of the first section should be
160 #   at level 3 instead of 1.
161 #
162 # SOURCE
163 {
164     add_source( "test.c", $test_source_2 );
165     mkdocdir();
166     my ( $out, $err ) = runrobo(
167         qw(--src Src
168            --doc Doc/test
169            --singledoc
170            --sections
171            --test
172            --toc
173            --first_section_level 3));
174     # expected results:
175     is( $out, '', 'No ouput' );
176     is( $err, '', '... and no error' );
177     file_exists_ok( "Doc/test.xml", 'there should be documentation' );
178
179     # Now test the level of the first header.
180     my $documentation = XMLin( 'Doc/test.xml' );
181     my $section = $documentation->{'section'};
182     is ( $section->[0]->{'depth'}, '3', 'First section is at level 3' );
183     my $subsection = $section->[0]->{'section'};
184     is ( $subsection->{'depth'}, '4', 'First subsection is at level 4' );
185     is ( $section->[1]->{'depth'}, '3', 'Second section is at level 3' );
186
187     clean();
188 }
189 #****
190
191
192 1;
193