ASNMTAP

 view release on metacpan or  search on metacpan

lib/ASNMTAP/Asnmtap/Plugins/NPTest.pm  view on Meta::CPAN


  if ( ! $fileHandle->open( "> ${CACHEFILENAME}" ) )
  {
    print STDERR "NPTest::LoadCache() : Problem saving ${CACHEFILENAME} : $!\n";
    return;
  }

  my( $dataDumper ) = new Data::Dumper( [ \%CACHE ] );

  $dataDumper->Terse(1);

  print $fileHandle $dataDumper->Dump();

  $fileHandle->close();

  $CACHE{'_cache_loaded_'} = 1;
}

#
# (Questionable) Public Cache Management Functions
#

sub SetCacheFilename
{
  my( $filename ) = @_;

  # Unfortunately we can not validate the filename
  # in any meaningful way, as it may not yet exist
  $CACHEFILENAME = $filename;
}


#
# Test Harness Wrapper Functions
#

sub DetermineTestHarnessDirectory
{
  my( $userSupplied ) = @_;

  # User Supplied
  if ( defined( $userSupplied ) && $userSupplied )
  {
    if ( -d $userSupplied )
    {
      return $userSupplied;
    }
    else
    {
      return undef; # userSupplied is invalid -> FAIL
    }
  }

  # Simple Case : "t" is a subdirectory of the current directory
  if ( -d "./t" )
  {
    return "./t";
  }

  # To be honest I don't understand which case satisfies the
  # original code in test.pl : when $tstdir == `pwd` w.r.t.
  # $tstdir =~ s|^(.*)/([^/]+)/?$|$1/$2|; and if (-d "../../$2/t")
  # Assuming pwd is "/a/b/c/d/e" then we are testing for "/a/b/c/e/t"
  # if I understand the code correctly (a big assumption)

  # Simple Case : the current directory is "t"
  my $pwd = cwd();

  if ( $pwd =~ m|/t$| )
  {
    return $pwd;

    # The alternate that might work better is
    # chdir( ".." );
    # return "./t";
    # As the current test harnesses assume the application
    # to be tested is in the current directory (ie "./check_disk ....")
  }

  return undef;
}

sub TestsFrom
{
  my( $directory, $excludeIfAppMissing ) = @_;

  $excludeIfAppMissing = 0 unless defined( $excludeIfAppMissing );

  if ( ! opendir( DIR, $directory ) )
  {
    print STDERR "NPTest::TestsFrom() - Failed to open ${directory} : $!\n";
    return ();
  }

  my( @tests ) = ();

  my $filename;
  my $application;

  while ( $filename = readdir( DIR ) )
  {
    if ( $filename =~ m/\.t$/ )
    {
      if ( $excludeIfAppMissing )
      {
	$application = basename( $filename, ".t" );
	if ( ! -e $application )
	{
	  print STDERR "No application (${application}) found for test harness (${filename})\n";
	  next;
	}
      }
      push @tests, "${directory}/${filename}";
    }
  }

  closedir( DIR );

  return sort @tests;
}



( run in 0.764 second using v1.01-cache-2.11-cpan-39bf76dae61 )