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 %config = (
15     mode => 'download',
16     getter => 'filegetter',
17 );
18 my $success = 0;
19 my $fail = 0;
20 my $notest = 0;
21
22 GetOptions("d" => \$debug);
23
24 push(@INC, dirname(realpath($0)));
25 load 'libvideosite';
26
27 unless(libvideosite::register_api({
28     _debug => sub { return $debug },
29 })) {
30     die("Error registering API: $libvideosite::error");
31 }
32
33 unless(libvideosite::init()) {
34     die("Could not init libvideosite: $libvideosite::error");
35 }
36
37 select(STDOUT);
38 $| = 1;
39 printf("Doing self tests:\n");
40 foreach my $g (libvideosite::_grabbers()) {
41     my $r;
42
43     if (@ARGV) {
44         my $found;
45
46         # If there are grabber names given on the command line check
47         # the current name against that list and skip if not present
48         $found = grep { $_ eq $g->{'NAME'} } @ARGV;
49
50         if ($found == 0) {
51             next;
52         }
53     }
54
55     printf("  %s...", $g->{'NAME'});
56     $r = $g->_selftest();
57     if(defined($r)) {
58         if ($r == 1) {
59             printf(" OK\n");
60             $success++;
61         } else {
62             printf(" no self test\n");
63             $notest++;
64         }
65     } else {
66         $fail++;
67     }
68 }
69
70 printf("\n\n%d succeeded\n%d failed\n%d not testable\n", $success, $fail, $notest);