Skip to content

Commit

Permalink
TestPlan: check for bad/orphaned tiny-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Aug 28, 2024
1 parent 18f95c5 commit 676d67c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cassandane/Cassandane/Unit/TestPlan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ sub add_pass
}

package Cassandane::Unit::TestPlan;
use File::Find;
use File::Temp qw(tempfile);
use File::Path qw(mkpath);
use Data::Dumper;
Expand Down Expand Up @@ -690,6 +691,60 @@ sub schedule
}
}

sub check_sanity
{
my ($self) = @_;

# collect tiny-tests directories that are used by test modules
my %used_tt_dirs;
find({
no_chdir => 1,
wanted => sub {
return if not -f $_;
return if not m/\.pm$/;

open my $fh, '<', $_ or die "open $_: $!";
while (<$fh>) {
if (m{^\s*use\s+Cassandane::Tiny::Loader\s*
(['"])
(.*?)
\1
\s*;\s*$
}x)
{
push @{$used_tt_dirs{$2}}, $File::Find::name;
}
}
close $fh;
},
}, @test_roots);

# collect tiny-tests directories that exist on disk
my %real_tt_dirs;
if (opendir my $dh, 'tiny-tests') {
while (readdir $dh) {
next if m/^\./;
my $path = "tiny-tests/$_";
next if not -d $path;
$real_tt_dirs{$path} = 1;
}
closedir $dh;
}

# whinge about bad test modules
while (my ($tt, $modules) = each %used_tt_dirs) {
die "@{$modules} uses nonexistent tiny-tests directory $tt"
if not $real_tt_dirs{$tt};
die "@{$modules} share tiny-tests directory $tt"
if scalar @{$modules} > 1;
}

# whinge about orphaned directories
foreach my $tt (keys %real_tt_dirs) {
die "$tt directory is not used by any tests"
if not $used_tt_dirs{$tt};
}
}

#
# Get the entire expanded schedule as specific {suite,testname} tuples,
Expand Down
1 change: 1 addition & 0 deletions cassandane/testrunner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ sub usage
{
# Build the schedule per commandline
$plan->schedule(@names);
$plan->check_sanity();
# Run the schedule
open my $fh, '>&', \*STDOUT
or die "Cannot save STDOUT as a runner print stream: $!";
Expand Down

0 comments on commit 676d67c

Please sign in to comment.