package ATR::Tests;

# $Source: /nfs/disk54/badger/cvs/AniTrack/testlib/ATR/Tests.pm,v $
# $Revision: 1.11 $ $Date: 2005/08/18 15:54:37 $

=head1 NAME

ATR::Tests - top level test list (plus minor checks)

=head1 DESCRIPTION

This ISA L<Test::Unit::TestSuite> which has a manually configured list
of the test classes that need to be run.  This list could probably be
generated in some cunning and/or devious way.

=cut

use strict;
use base qw(Test::Unit::TestSuite);

sub name { 'Top level AniTrack test container' }

# These need updating when things are added
sub include_tests { qw(
 ATR::GTTest

 ATR::BioTablesTest
 ATR::CheckbarcodeTest
 ATR::MicePE::MouseTest
 ATR::MicePE::MatingPairTest
 ATR::MicePE::WeaningTest
 ATR::UtilTest
 ATR::DatasetTest

 McaTestOverview
 Local::TestUnit::Brokenness
 ATR::Tests::Config
) }

1;


package ATR::Tests::Config;
use base qw(McaTestCase);

sub test_leaks {
    my $self = shift;
    # This is just a reminder test
    $self->fail("DLO leak testing not enabled...") unless $self->DLO_present;
}


package Local::TestUnit::Brokenness; # XXX: Dup with ExoSeq::Tests, and belongs elsewhere
use Test::Unit 0.24;
use base qw(Test::Unit::TestCase);

=head1 SANITY CHECKS

There are some extra tests covering minor bugs in the testing suite,
defined in this file as the class C<Local::TestUnit::Brokenness> and
included in the main suite.

=over 4

=item test_equality

Test for misleading false-negative comparison in C<assert_equals> that
burned me a bit (broken in Test::Unit 0.24).

Locally fixed by hackery, see L<McaTestCase>.

=cut

sub test_equality {
    my $self = shift;

    $self->assert_raises
      ('Test::Unit::Failure',
       sub {
	   $self->assert_equals
	     ("start o:ExoSeq::GuiStates=HASH(0x1404343f0) | any o:ExoSeq::GuiStates=HASH(0x1404343f0) e:start | any o:ExoSeq::GuiStates=HASH(0x1404343f0) e:in",
	      "start o: e: | any o:start e: | any o:in e:")
	 });
}


=item test_numericness

...and the root of the problem shown in C<test_equality>.

NB. the is_numeric function is globally blasted away and replaced with
my own, when L<McaTestCase> is loaded.  This makes these tests pass
and stops me shooting myself in the foot, by reducing the range of
strings that can be considered numeric.

=cut

sub test_numericness {
    my $self = shift;
    my @val =   ("1", "0", "15e7", "not 0", "not 4", "  \n 5E2", "  \t 0E0");
    my @exp = qw( t    t    t       f        f        t           t        );
    my @act = map { Test::Unit::Assert::is_numeric($_) ? 't' : 'f' } @val;

    $self->assert_deep_equals( \@exp, \@act );
}


=item test_deepequals_scalarrefs

Test for misleading message from C<assert_deep_equals> (broken in
Test::Unit 0.24).  The assertion result is correct.

Testcase submitted back to perlunit project, only needed here to
remind me not to rely on the failure message!

=cut

sub test_deepequals_scalarrefs {
    my $self = shift;

    return if $Test::Unit::VERSION eq '0.24'; # I know it's broken and have enough failures

    my ($H, $G) = ("hello", "goodbye");
    my $a = [ \$H, "world" ];
    my $b = [ \$G, "world" ];
    # comparison should fail on list item 0, and tell us what they were
    eval {
	$self->assert_deep_equals($a, $b);
    };
    my $err = $@;
    $self->fail("comparison should fail") unless $err;
    $err =~ s/^/> /mg; # indent for clarity
    $self->assert_matches(qr/hello/, $err);
    $self->assert_matches(qr/goodbye/, $err);
}

=back

=cut

1;
