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

Last change on this file was 19733, checked in by westram, 2 months ago
  • fix perl compatibility script:
    • close database from script.
    • fix indentation.
    • previously script failed in DEBUG mode under OSX
      • assertion fails: assertion 'openedDBs == closedDBs' failed in arbdb.cxx #435
    • did not happen under Linux
  • 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  ARB::close($gb_main);
34}
35
36sub die_usage($) {
37  my ($err) = @_;
38  print "Purpose: test if the perl interface of ARB is working\n";
39  print "Usage: automatic.pl [-db <DBNAME>] -client <CLIENT_NAME>\n";
40  print "       -db        optional ARB database name to open,\n";
41  print "                  if omitted runnig ARB instance is used.\n";
42  print "                  Script must be from within ARB to access\n";
43  print "                  the running instance.\n";
44  print "       -client    test client. Must be either arb or homebrew.\n";
45  print "\n";
46  die "Error: $err\n";
47}
48
49sub main() {
50  my $args = scalar(@ARGV);
51  if ($args<2) { die_usage('Missing arguments'); }
52
53  my $dbname;
54  my $client;
55
56  while ($ARGV[0] && substr($ARGV[0],0,1) eq '-') {
57    my $arg = shift @ARGV;
58    if ($arg eq '-db') { $dbname = shift @ARGV; }
59    elsif ($arg eq '-client') { $client = shift @ARGV; }
60    else { die_usage("Unknown switch '$arg'"); }
61  }
62
63  if (not defined $client) {
64    die_usage('Client must be given.');
65  }
66  elsif ($client ne 'arb' && $client ne 'homebrew') {
67    die_usage("Client must be either arb or homebrew but is '$client'");
68  }
69
70  # use running ARB if no database name is given
71  if (not defined $dbname) {
72    $dbname = ':';
73  }
74
75  run_test($client, $dbname);
76}
77
78main();
Note: See TracBrowser for help on using the repository browser.