source: branches/help/PERL_SCRIPTS/ARBTOOLS/TESTS/automatic.pl

Last change on this file was 18326, checked in by westram, 5 years ago
  • script to test perl functionality.
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#! /usr/bin/perl
2
3use strict;
4use warnings;
5
6BEGIN {
7  if (not exists $ENV{'ARBHOME'}) { die "Environment variable \$ARBHOME has to be defined"; }
8  my $arbhome = $ENV{'ARBHOME'};
9  push @INC, "$arbhome/lib";
10  push @INC, "$arbhome/PERL_SCRIPTS/lib";
11  1;
12}
13
14use ARB;
15use tools;
16
17sub run_test($$) {
18    my ($client, $dbname) = @_;
19    my $gb_main = ARB::open($dbname, "r");
20    if (!$gb_main) {
21        die "Could not open ARB database. '$dbname'"
22    }
23
24    my $species_count = 0;
25    for (my $gb_species = BIO::first_species($gb_main);
26       $gb_species;
27       $gb_species = BIO::next_species($gb_species)) {
28           $species_count++;
29    }
30
31    print "Number of species in database: $species_count\n";
32}
33
34sub die_usage($) {
35  my ($err) = @_;
36  print "Purpose: test if the perl interface of ARB is working\n";
37  print "Usage: automatic.pl [-db <DBNAME>] -client <CLIENT_NAME>\n";
38  print "       -db        optional ARB database name to open,\n";
39  print "                  if omitted runnig ARB instance is used.\n";
40  print "                  Script must be from within ARB to access\n";
41  print "                  the running instance.\n";
42  print "       -client    test client. Must be either arb or homebrew.\n";
43  print "\n";
44  die "Error: $err\n";
45}
46
47sub main() {
48  my $args = scalar(@ARGV);
49  if ($args<2) { die_usage('Missing arguments'); }
50
51  my $dbname;
52  my $client;
53
54  while ($ARGV[0] && substr($ARGV[0],0,1) eq '-') {
55    my $arg = shift @ARGV;
56    if ($arg eq '-db') { $dbname = shift @ARGV; }
57    elsif ($arg eq '-client') { $client = shift @ARGV; }
58    else { die_usage("Unknown switch '$arg'"); }
59  }
60
61  if (not defined $client) {
62      die_usage('Client must be given.');
63  } elsif ($client ne 'arb' && $client ne 'homebrew') {
64      die_usage("Client must be either arb or homebrew but is '$client'");
65  }
66
67  # use running ARB if no database name is given
68  if (not defined $dbname) {
69      $dbname = ':';
70  }
71
72  run_test($client, $dbname);
73}
74
75main();
Note: See TracBrowser for help on using the repository browser.