Use safe new $conn->check() instead of old private _check().
[irspy-moved-to-github.git] / bin / irspy.pl
1 #!/usr/bin/perl -w
2
3 # $Id: irspy.pl,v 1.23 2007-02-24 01:26:32 mike Exp $
4 #
5 # Run like this:
6 #       YAZ_LOG=irspy,irspy_test IRSPY_SAVE_XML=1 perl -I../lib irspy.pl -t Quick localhost:8018/IR-Explain---1 z3950.loc.gov:7090/Voyager bagel.indexdata.dk/gils bagel.indexdata.dk:210/marc
7 # Available log-levels are as follows:
8 #       irspy -- high-level application logging
9 #       irspy_debug -- low-level debugging (not very interesting)
10 #       irspy_event -- invocations of ZOOM_event() and individual events
11 #       irspy_unhandled -- unhandled events (not very interesting)
12 #       irspy_test -- adding, queueing and running tests
13 #       irspy_task -- adding, queueing and running tasks
14
15 use strict;
16 use warnings;
17 use Getopt::Std;
18 use ZOOM::IRSpy::Web;
19 use Carp;
20
21 local $SIG{__DIE__} = sub {
22     my($msg) = @_;
23     confess($msg);
24 };
25
26 my %opts;
27 if (!getopts('wt:af:', \%opts) || @ARGV < 1) {
28     print STDERR "\
29 Usage $0: [options] <IRSpy-database> [<target> ...]
30         -w              Use ZOOM::IRSpy::Web subclass
31         -t <test>       Run the specified <test> [default: all tests]
32         -a              Test all targets (slow!)
33         -f <query>      Test targets found by the specified query
34 ";
35     exit 1;
36 }
37
38 my($dbname, @targets) = @ARGV;
39 my $class = "ZOOM::IRSpy";
40 $class .= "::Web" if $opts{w};
41
42 my $spy = $class->new($dbname, "admin", "fruitbat");
43 if (@targets) {
44     $spy->targets(@targets);
45 } elsif ($opts{f}) {
46     $spy->find_targets($opts{f});
47 } elsif (!$opts{a}) {
48     print STDERR "$0: specify -a, -f <query> or list of targets\n";
49     exit 1;
50 }
51
52 $spy->initialise();
53 my $res = $spy->check($opts{t});
54 if ($res == 0) {
55     print "All tests were attempted\n";
56 } else {
57     print "$res tests were skipped\n";
58 }
59
60
61 # Fake the HTML::Mason class that ZOOM::IRSpy::Web uses
62 package HTML::Mason::Commands;
63 BEGIN { our $m = bless {}, "HTML::Mason::Commands" }
64 sub flush_buffer { print shift(), " flushing\n" if 0 }