videosite-test: Add debug flag, remove unused config variable
[videosite.git] / videosite-test.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5 use File::Spec;
6 use File::Basename;
7 use Module::Load;
8 use Cwd qw(realpath);
9 use Carp;
10
11 $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
12
13 my $debug = 0;
14 my $success = 0;
15 my $fail = 0;
16 my $notest = 0;
17
18 GetOptions("d" => \$debug);
19
20 push(@INC, dirname(realpath($0)));
21 load 'libvideosite';
22
23 unless(libvideosite::register_api({
24     _debug => sub { return $debug },
25 })) {
26     die("Error registering API: $libvideosite::error");
27 }
28
29 unless(libvideosite::init()) {
30     die("Could not init libvideosite: $libvideosite::error");
31 }
32
33 select(STDOUT);
34 $| = 1;
35 printf("Doing self tests:\n");
36 foreach my $g (libvideosite::_grabbers()) {
37     my $r;
38
39     if (@ARGV) {
40         my $found;
41
42         # If there are grabber names given on the command line check
43         # the current name against that list and skip if not present
44         $found = grep { $_ eq $g->{'NAME'} } @ARGV;
45
46         if ($found == 0) {
47             next;
48         }
49     }
50
51     printf("  %s...", $g->{'NAME'});
52     $r = $g->_selftest();
53     if(defined($r)) {
54         if ($r == 1) {
55             printf(" OK\n");
56             $success++;
57         } else {
58             printf(" no self test\n");
59             $notest++;
60         }
61     } else {
62         $fail++;
63     }
64 }
65
66 printf("\n\n%d succeeded\n%d failed\n%d not testable\n", $success, $fail, $notest);