Reformat Lib/std/markdown
[sunny256-utils.git] / tests / perlmodules.t
bloba7e8f97cbb1deea0370ad3171984f128d3c1e1bd
1 #!/usr/bin/env perl
3 #=======================================================================
4 # perlmodules.t
5 # File ID: a2e25ad4-56fe-11e0-8c2f-00023faf1383
7 # Find missing Perl modules.
9 # Character set: UTF-8
10 # ©opyleft 2011– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
18 BEGIN {
19 use Test::More qw{no_plan};
20 # use_ok() goes here
22 use lib "$ENV{HOME}/bin/Lib/perllib";
23 use lib "$ENV{HOME}/bin/src/fldb";
24 use lib "$ENV{HOME}/bin/src/gpstools";
28 use Getopt::Long;
30 local $| = 1;
32 our $CMDB = "";
33 our $CMD = "../$CMDB";
35 our %Opt = (
37 'all' => 0,
38 'help' => 0,
39 'quiet' => 0,
40 'todo' => 0,
41 'verbose' => 0,
42 'version' => 0,
46 our $progname = $0;
47 $progname =~ s/^.*\/(.*?)$/$1/;
48 our $VERSION = '0.0.0';
50 my %descriptions = ();
52 Getopt::Long::Configure('bundling');
53 GetOptions(
55 'all|a' => \$Opt{'all'},
56 'help|h' => \$Opt{'help'},
57 'quiet|q+' => \$Opt{'quiet'},
58 'todo|t' => \$Opt{'todo'},
59 'verbose|v+' => \$Opt{'verbose'},
60 'version' => \$Opt{'version'},
62 ) || die("$progname: Option error. Use -h for help.\n");
64 $Opt{'verbose'} -= $Opt{'quiet'};
65 $Opt{'help'} && usage(0);
66 if ($Opt{'version'}) {
67 print_version();
68 exit(0);
71 exit(main());
73 sub main {
74 # {{{
75 my $Retval = 0;
77 diag(sprintf('========== Executing %s v%s ==========',
78 $progname, $VERSION));
80 if ($Opt{'todo'} && !$Opt{'all'}) {
81 goto todo_section;
84 =pod
86 testcmd("$CMD command", # {{{
87 <<'END',
88 [expected stdout]
89 END
90 '',
92 'description',
95 # }}}
97 =cut
99 my %Modules = (
101 'Authen::SASL' => 'libauthen-sasl-perl',
102 'CGI' => '',
103 'Cwd' => '',
104 'DBI' => 'libdbi-perl',
105 'Data::Dumper' => '',
106 'Date::Manip' => 'libdate-manip-perl',
107 'Devel::GDB' => 'libdevel-gdb-perl',
108 'Devel::NYTProf' => 'libdevel-nytprof-perl',
109 'Devel::ptkdb' => 'libdevel-ptkdb-perl',
110 'Digest::CRC' => 'libdigest-crc-perl',
111 'Digest::MD5' => 'libdigest-md5-file-perl',
112 'Digest::SHA' => 'libdigest-sha-perl',
113 'Env' => '',
114 'Exporter' => '',
115 'FLDBdebug' => '', # mine
116 'FLDBpg' => '', # mine
117 'FLDBsum' => '', # mine
118 'FLDButf' => '', # mine
119 'Fcntl' => '',
120 'File::Basename' => '',
121 'File::Copy' => '',
122 'File::Find' => '',
123 'File::Glob' => '',
124 'File::Path' => '',
125 'File::Spec' => '',
126 'File::Temp' => '',
127 'FileHandle' => '',
128 'GPST' => '', # mine
129 'GPSTdate' => '', # mine
130 'GPSTdebug' => '', # mine
131 'GPSTgeo' => '', # mine
132 'GPSTxml' => '', # mine
133 'Getopt::Long' => '',
134 'Getopt::Std' => '',
135 'GraphViz' => 'libgraphviz-perl',
136 'HTML::Template' => 'libhtml-template-perl',
137 'HTML::TreeBuilder' => 'libxml-treebuilder-perl libhtml-treebuilder-xpath-perl',
138 'HTML::WikiConverter' => 'libhtml-wikiconverter-mediawiki-perl',
139 'IO::Handle' => '',
140 'IPC::Open3' => '',
141 'Image::ExifTool' => 'libimage-exiftool-perl',
142 'JSON::XS' => 'libjson-xs-perl',
143 'MIME::Base64' => 'libmime-base64-urlsafe-perl',
144 'Math::Round' => 'libmath-round-perl',
145 'Module::Starter' => 'libmodule-starter-perl',
146 'Module::Starter::Plugin::CGIApp' => 'libmodule-starter-plugin-cgiapp-perl',
147 'Net::SMTP::SSL' => 'libnet-smtp-ssl-perl',
148 'Number::Bytes::Human' => 'libnumber-bytes-human-perl',
149 'OSSP::uuid' => 'libossp-uuid-perl',
150 'POSIX' => '',
151 'Perl::Critic' => 'libtest-perl-critic-perl',
152 'Socket' => '',
153 'Term::ReadLine' => '',
154 'Term::ReadLine::Gnu' => 'libterm-readline-gnu-perl',
155 'Term::ReadLine::Perl' => 'libterm-readline-perl-perl',
156 'Test::More' => '',
157 'Test::Perl::Critic' => 'libtest-perl-critic-perl',
158 'Text::Diff' => 'libtext-diff-perl',
159 'Time::HiRes' => '',
160 'Time::Local' => '',
161 'XML::Parser' => 'libxml-parser-perl',
162 'bigint' => '',
163 'constant' => '',
164 'strict' => '',
165 'utf8' => '',
166 'vars' => '',
170 my @missing = ();
171 my $outfile = './install-modules';
173 unlink $outfile;
174 for my $mod (sort keys %Modules) {
175 my $package = $Modules{$mod};
176 use_ok($mod) || length($package) && push(@missing, $package);
178 -e "nytprof.out" && ok(unlink("nytprof.out"), "Remove nytprof.out");
180 if (scalar(@missing)) {
181 open(my $fp, '>', $outfile) || die("$progname: $outfile: Cannot create file: $!\n");
182 print($fp
183 join("\n",
184 '#!/bin/sh',
186 '# Created by perlmodules.t',
188 "sudo apt-get update\n",
191 for my $m (@missing) {
192 print($fp "sudo apt-get --assume-yes install $m\n");
194 ok(close($fp), "Close $outfile");
195 ok(chmod(0755, $outfile), "Make $outfile executable");
196 diag("\nExecute $outfile to install missing modules.\n\n");
197 diag("Contents of $outfile:\n==== BEGIN ====\n", file_data($outfile), "==== END ====\n\n");
200 todo_section:
203 if ($Opt{'all'} || $Opt{'todo'}) {
204 diag('Running TODO tests...'); # {{{
206 TODO: {
208 local $TODO = '';
209 # Insert TODO tests here.
212 # TODO tests }}}
215 diag('Testing finished.');
216 return $Retval;
217 # }}}
218 } # main()
220 sub testcmd {
221 # {{{
222 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
223 defined($descriptions{$Desc}) &&
224 BAIL_OUT("testcmd(): '$Desc' description is used twice");
225 $descriptions{$Desc} = 1;
226 my $stderr_cmd = '';
227 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
228 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
229 my $TMP_STDERR = "$CMDB-stderr.tmp";
230 my $retval = 1;
232 if (defined($Exp_stderr)) {
233 $stderr_cmd = " 2>$TMP_STDERR";
235 $retval &= is(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
236 my $ret_val = $?;
237 if (defined($Exp_stderr)) {
238 $retval &= is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
239 unlink($TMP_STDERR);
240 } else {
241 diag("Warning: stderr not defined for '$Txt'");
243 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
245 return $retval;
246 # }}}
247 } # testcmd()
249 sub likecmd {
250 # {{{
251 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
252 defined($descriptions{$Desc}) &&
253 BAIL_OUT("likecmd(): '$Desc' description is used twice");
254 $descriptions{$Desc} = 1;
255 my $stderr_cmd = '';
256 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
257 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
258 my $TMP_STDERR = "$CMDB-stderr.tmp";
259 my $retval = 1;
261 if (defined($Exp_stderr)) {
262 $stderr_cmd = " 2>$TMP_STDERR";
264 $retval &= like(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
265 my $ret_val = $?;
266 if (defined($Exp_stderr)) {
267 $retval &= like(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
268 unlink($TMP_STDERR);
269 } else {
270 diag("Warning: stderr not defined for '$Txt'");
272 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
274 return $retval;
275 # }}}
276 } # likecmd()
278 sub file_data {
279 # Return file content as a string {{{
280 my $File = shift;
281 my $Txt;
283 open(my $fp, '<', $File) or return undef;
284 local $/ = undef;
285 $Txt = <$fp>;
286 close($fp);
287 return $Txt;
288 # }}}
289 } # file_data()
291 sub print_version {
292 # Print program version {{{
293 print("$progname $VERSION\n");
294 return;
295 # }}}
296 } # print_version()
298 sub usage {
299 # Send the help message to stdout {{{
300 my $Retval = shift;
302 if ($Opt{'verbose'}) {
303 print("\n");
304 print_version();
306 print(<<"END");
308 Usage: $progname [options]
310 Find missing Perl modules.
312 Options:
314 -a, --all
315 Run all tests, also TODOs.
316 -h, --help
317 Show this help.
318 -q, --quiet
319 Be more quiet. Can be repeated to increase silence.
320 -t, --todo
321 Run only the TODO tests.
322 -v, --verbose
323 Increase level of verbosity. Can be repeated.
324 --version
325 Print version information.
328 exit($Retval);
329 # }}}
330 } # usage()
332 sub msg {
333 # Print a status message to stderr based on verbosity level {{{
334 my ($verbose_level, $Txt) = @_;
336 $verbose_level > $Opt{'verbose'} && return;
337 print(STDERR "$progname: $Txt\n");
338 return;
339 # }}}
340 } # msg()
342 __END__
344 # This program is free software; you can redistribute it and/or modify
345 # it under the terms of the GNU General Public License as published by
346 # the Free Software Foundation; either version 2 of the License, or (at
347 # your option) any later version.
349 # This program is distributed in the hope that it will be useful, but
350 # WITHOUT ANY WARRANTY; without even the implied warranty of
351 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
352 # See the GNU General Public License for more details.
354 # You should have received a copy of the GNU General Public License
355 # along with this program.
356 # If not, see L<http://www.gnu.org/licenses/>.
358 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :