#!/usr/bin/env perl

open(NOTEST,"BUGS_NOT_NEEDING_TEST_CASES") or warn "WARNING:  Cannot open BUGS_NOT_NEEDING_TEST_CASES";
$numoldbugs = 0;
while ($line = <NOTEST>)
{
  chomp($line);
  if ($line =~ m/^\s*bug/i)
  {
    $bug = $line;
    $bug =~ s/^\s*bug[:]*\s+([\d]+)[:\s]+.*/$1/i;
    #print "Found Bug #$bug in BUGS_NOT_NEEDING_TEST_CASES\n";
    $line =~ s/^\s*bug[:]*\s+[\d]+[:\s]+//i;
    $notest{$bug} = "$line";
    $numoldbugs++;
  }
}
close(NOTEST);

$filels = `ls 2>/dev/null`;
@filelist = split(' ',$filels);
$numbugs = 0;
foreach $dir (@filelist)
{
  if ( $dir eq 'CVS' ) { next; }
  if ( -d "$dir" ) 
  {
    chdir "$dir";
    $dirlist = `ls *.cir 2>/dev/null`;
    @ckt1 = split(' ',$dirlist);
    if ( $#ckt1 < 0 )
    {
      $number = $dir;
      $number =~ s/[_\D]//g;
      #print "$dir has no cir files and should be bug #$number\n";
      if (defined ($notest{$number}))
      {
        print "Bug #$number still has a directory listing but has the following description\n";
        print "in BUGS_NOT_NEEDING_TEST_CASES:\n";
        print "     $notest{$number}\n\n";
        push(@obsoletetests,$number);
      }
      else { 
        print "Directory \"$dir\" is not listed in BUGS_NOT_NEEDING_TEST_CASES and has no test\n\n";
        push(@needstest,$dir);
        $numbugs++;
      }
    }
    else
    {
      $numbugs++;
    }
    chdir "..";
  }
}

print "--REPORT--\n";
printf ("Out of a total of %4d bugs:\n",$numoldbugs+$numbugs);
printf ("                  %4d are in BUGS_NOT_NEEDING_TEST_CASES\n",$numoldbugs); 
printf ("                  %4d have directory listings here.\n",$numbugs);
printf ("Found %d presumably obsolete tests still in the directory listings",$#obsoletetests+1);
if ($#obsoletetests > 0)
{
  print ": ";
  foreach $test (@obsoletetests)
  {
    print " $test";
  }
}
print ".\n\n";
printf ("Found %d bugs that may need tests",$#needstest+1);
if ($#needstest > 0)
{
  print ": ";
  foreach $test (@needstest)
  {
    print " $test";
  }
}
print ".\n";
