2 #****h* ROBODoc/ROBOTestFrame
4 # A Perl module with a set of handy functions to create
18 package ROBOTestFrame;
28 ); # symbols to export on request
32 # TODO Try to get this to work without IPC::Run
38 #****f* ROBOTestFrame/robo_win, robo_unix
40 # Location of the ROBODoc executable.
43 my $robo_win = "../robodoc.exe";
44 my $robo_unix = "../robodoc";
47 #****f* ROBOTestFrame/source_directory
49 # Name of the source directory used to test ROBODoc.
52 my $source_directory = "Src";
55 #****f* ROBOTestFrame/documentation_directory
57 # Name of the documentation directory used to test ROBODoc.
59 my $documentation_directory = "Doc";
62 #****f* ROBOTestFrame/configuration_directory
64 # Name of the documentation directory used to test ROBODoc.
66 my $configuration_directory = "Config";
69 #****f* ROBOTestFrame/runrobo
71 # Run robodoc with the given set of
72 # arguments and capture all output to
75 # A list of options for robodoc.exr
83 if ( $^O eq 'linux' ) {
88 run( [ $robo, @_ ], \my( $in, $out, $err ) );
94 #****f* ROBOTestFrame/add_configuration
96 # Add a configuration file somewhere in Config/
98 # - filepath -- path to a file.
99 # - configuration -- the content for this file
100 # - binary -- write the raw bytes. [optional]
103 sub add_configuration
105 my $filepath = shift;
106 my $configuration = shift;
108 add_file( $configuration_directory, $filepath, $configuration, $binary )
113 #****f* ROBOTestFrame/add_source
115 # Add a single source file somewhere in Src/
117 # - filepath -- path to a file.
118 # - source_code -- the source code to go into this file
119 # - binary -- write the raw bytes. [optional]
124 my $filepath = shift;
125 my $source_code = shift;
128 add_file( $source_directory, $filepath, $source_code, $binary )
133 #****f* ROBOTestFrame/add_file
135 # Add a single file somewhere in base_path.
137 # - base_path -- base path
138 # - filepath -- relative path to a file.
139 # - content -- the content to go into this file
140 # - binary -- write the raw bytes. [optional]
146 my $base_path = shift;
147 my $filepath = shift;
151 my $path = $base_path . dirname( $filepath );
153 $path =~ s/\.$//; # Fix for Perl 5.8.0 under Linux.
155 if ( ! -e "$path" ) {
156 mkpath $path or die "can't create $path";
159 my $full_filepath = "$base_path/$filepath";
160 my $file = IO::File->new(">$full_filepath") or
161 die "Can't open $full_filepath";
162 if ( $binary and ( $binary eq 'binary' ) ) {
165 print $file $content;
171 #****f* ROBOTestFrame/clean
173 # Clean source and documentation directories.
178 if ( -e $source_directory ) {
179 rmtree( $source_directory ) or die;
181 if ( -e $documentation_directory ) {
182 rmtree( $documentation_directory ) or die;
184 if ( -e $configuration_directory ) {
185 rmtree( $configuration_directory ) or die;
191 #****f* ROBOTestFrame/mkdocdir
193 # Create a empty documentation directory.
194 # This is handy for tests that use --singledoc.
198 if ( ! -e $documentation_directory ) {
199 mkpath( $documentation_directory );
205 #****f* ROBOTestFrame/is_latex_balanced
207 # Test the balance of a latex file.
208 # A latex file is balanced if every
213 # * path - path to a latex file.
215 # * 0 -- file is not balanced
216 # * 1 -- file is balanced
219 sub is_latex_balanced {
223 my $file = IO::File->new("<$path") or die "$path : $!";
224 my $string = <$file>;
227 while ( $string =~ m/(begin|end)\{([^}]+)\}/g ) {
228 my $b_e = $1; # begin or end
229 my $kind = $2; # document, or equation, or ...
230 if ( $b_e eq "begin" ) {
231 push( @stack, $kind );
233 if ( pop( @stack ) eq $kind ) {
234 # OK. begin and end matches.
239 # end{ something else }
245 if ( scalar( @stack ) ) {
246 # there are items left!
254 #****f* ROBOTestFrame/read_hexdump
256 # Reads a hexdump made with xxd (part of vim http://www.vim.org/)
257 # This makes it possible to add files with all kinds of
258 # different formats and characters.
260 # Storing it in hexdump format makes sure that these files are
261 # not changed when they are checked into cvs or unzipped.
263 # This makes is possible to test cr/lf problems and internationalization
267 # * path - path to a hexdump file.
269 # The decoded content of the file as a single string.
274 my $file = IO::File->new("<$path") or die "$path : $!";
278 while ( my $line = <$file> ) {
279 $line =~ s/^\S+:\s//; # remove address
280 $line =~ s/\s\s+.*$//; # remove ascii
281 $line =~ s/(\S\S)(\S\S)/$1 $2/g;
282 # Now only the words are left.
283 my @data = split( /\s/, $line );
284 my @bytes = map { chr hex } @data;
285 push( @all_bytes, @bytes );
287 # TODO try a join() here.
288 foreach my $c ( @all_bytes ) {