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