Imported Robodoc.
[robodoc.git] / Source / t / errors.t
1 #!perl
2
3 #****h* ROBODoc System Tests/Handling Errors
4 # FUNCTION
5 #    Test wether calling ROBODoc with wrong options or input leads
6 #    to the correct error messages.
7 #*****
8
9 use strict;
10 use warnings;
11 use ROBOTestFrame;
12 use Test::More 'no_plan';
13
14 # A dummy header to put into dummy source files.
15 #
16 my $source = <<'EOF';
17 /****f* Test/test
18  * NAME
19  *   Test
20  ******
21  */
22 EOF
23
24 #****x* Handling Errors/Error on Non-existing Option
25 # FUNCTION
26 #   ROBODoc should complain about non-existing options.
27 # SOURCE
28 #
29 {
30     my ($out, $err) = runrobo( '--foobar' );
31     like($out, qr/Usage/, 'Unknown option should print usage' );
32     like($err, qr/Invalid/, 'and an error message'   );
33 }
34 #*****
35
36
37 #****x* Handling Errors/Error on Mutual Excluding Options
38 # FUNCTION
39 #   ROBODoc should complain about options that can not be used
40 #   together.
41 # SOURCE
42 #
43 {
44     add_source( "test.c", $source );
45     my ($out, $err) = runrobo( qw(--src Src --doc Doc --multidoc --singledoc --html) );
46     like($out, qr/Usage/, 'Mutual excluding options should print usage' );
47     print $err;
48     like($err, qr/together/, 'and an error message'   );
49     clean();
50 }
51 #*****
52
53 #****x* Handling Errors/Error on Mutual Excluding Options II
54 # FUNCTION
55 #   ROBODoc should complain about options that can not be used
56 #   together.
57 # SOURCE
58 #
59 {
60     add_source( "test.c", $source );
61     my ($out, $err) = runrobo( qw(--src Src --doc Doc --multidoc --test --dbxml --html) );
62     like($out, qr/Usage/, 'Mutual excluding options should print usage' );
63     print $err;
64     like($err, qr/together/, 'and an error message'   );
65     clean();
66 }
67 #*****
68
69 #****x* Handling Errors/Error on Duplicate Options
70 # FUNCTION
71 #   ROBODoc should complain about options that are specifed more
72 #   than once.
73 # SOURCE
74 #
75 {
76     add_source( "test.c", $source );
77     my ($out, $err) = runrobo( qw( --src Src --doc Doc --multidoc --test --test --test) );
78     print $out;
79     like($out, qr/Usage/, 'Duplicate options should print usage' );
80     print $err;
81     like($err, qr/than\sonce/, 'and an error message'   );
82     clean();
83 }
84 #*****
85
86 #****x* Handling Errors/Error on Non-existing rc file
87 # FUNCTION
88 #   When given a non-existing .rc file, ROBODc should
89 #   at least report the name of the .rc file.
90 # SOURCE
91 {
92     my ($out, $err) = runrobo( '--rc foobar.rc' );
93     like($err, qr/foobar/, 'should give an error message about foorbar.rc' );
94 }
95 #*****
96
97 #****x* Handling Errors/Impossible output file
98 # FUNCTION
99 #   When given a impossible output filename ROBODoc should
100 #   at least report the filename.
101 # SOURCE
102 {
103     add_source( "test.c", $source );
104     my ($out, $err) = runrobo( qw(--src Src --doc Foo/Bar/document --singledoc --html) );
105     like($err, qr/document/, 'should give an error message about document' );
106 }
107
108 #*****
109
110 #****x* Handling Errors/Non-existing css file
111 # FUNCTION
112 #   When given  a impossible css filename ROBODoc should
113 #   at least report the filename.
114 # SOURCE
115 {
116     add_source( "test.c", $source );
117     my ($out, $err) = runrobo( qw(--src Src --doc Doc --multidoc --html --css Foo/Bar/cascade.css) );
118     like($err, qr/cascade/, 'should give an error message about css file' );
119 }
120
121 #*****
122
123
124
125 #****x* Handling Errors/Header without end marker
126 # FUNCTION
127 #   Test ROBODoc's response on a header without an
128 #   end marker. ROBODoc should detect this.
129 # SOURCE
130 #
131
132 {
133     my $source = <<'EOF';
134 /****f* Test/test
135  * NAME
136  *   Test
137  * FUNCTION
138  *   Test2
139  * SOURCE
140  */
141
142 some source
143
144 and no end of the header  ....
145
146 EOF
147
148     add_source( "test.c", $source );
149     my ($out, $err) = runrobo( qw(--src Src --doc Doc --multidoc --test) );
150     is( $out, '', 'no output' );
151     like( $err, qr/end\smarker/, 'error about end marker' );
152     clean();
153 }
154
155 #****
156
157 #****x* Handling Errors/Headers with duplicate names
158 # FUNCTION
159 #   Test ROBODoc's response to a file with two headers that
160 #   have the same name. This should be reported as an error.
161 # SOURCE
162
163 {
164     my $source = <<'EOF';
165 /****f* Test/test
166  * NAME
167  *   Test
168  * FUNCTION
169  *   Test2
170  *****
171  */
172
173 /****f* Test/test
174  * NAME
175  *   Test
176  * FUNCTION
177  *   Test2
178  *****
179  */
180
181 EOF
182
183     add_source( "test.c", $source );
184     my ($out, $err) = runrobo( qw(--src Src --doc Doc --multidoc --test) );
185     is( $out, '', 'no output' );
186     like( $err, qr/already\sexists/, 'error duplicate header' );
187     clean();
188 }
189
190 #*****
191
192 {
193     my $source = <<'EOF';
194 /****f* Test/test
195  * FOO
196  *   test
197  ******/
198 EOF
199
200     my $rc_file = <<'EOF';
201 items:
202     FOO
203     BAR
204     SNAFU
205 item order:
206     FOO
207     BARRRRRR
208     SNAFU
209 EOF
210
211     add_configuration( "robodoc.rc", $rc_file );
212     add_source( "test.c", $source );
213     mkdocdir();
214
215     my ($out, $err) = runrobo( qw(
216         --src Src 
217         --doc Doc 
218         --multidoc 
219         --rc Config/robodoc.rc --test) );
220     is( $out, '', 'no output' );
221     like( $err, qr/item/, 'An unknown item is reported' );
222
223     clean();
224 }