Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestPlan: check for bad/orphaned tiny-tests #5011

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 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,77 @@ 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 {
my $fname = $File::Find::name;

return if not -f $fname;
return if $fname !~ m/\.pm$/;

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

# collect tiny-tests directories that exist on disk
my %real_tt_dirs;
find({
no_chdir => 1,
wanted => sub {
my $fname = $File::Find::name;

my ($tt, $suite, $test) = split q{/}, $fname, 3;
return if not $suite;

if (not $test) {
# explicit initialisation to detect directories with no files
$real_tt_dirs{"$tt/$suite"} //= 0;
return;
}

$real_tt_dirs{"$tt/$suite"} ++;
},
}, 'tiny-tests') if -d 'tiny-tests';

# whinge about bad test modules
while (my ($tt, $modules) = each %used_tt_dirs) {
# XXX this one might not be an error if we start doing this
# XXX intentionally, perhaps to run the same group of tests under
# XXX different setups or configurations
die "@{$modules} share tiny-tests directory $tt"
if scalar @{$modules} > 1;

die "$modules->[0] uses nonexistent tiny-tests directory $tt"
if not exists $real_tt_dirs{$tt};
}

# whinge about orphaned directories
while (my ($tt, $ntests) = each %real_tt_dirs) {
die "$tt directory is not used by any tests"
if not $used_tt_dirs{$tt};

die "$tt directory contains no tests"
if not $ntests;
}
}

#
# 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 @@ -355,6 +355,7 @@ sub usage
{
# Build the schedule per commandline
$plan->schedule(@names);
$plan->check_sanity();

# Run the schedule
$want_formats{prettier} = 1 if not scalar keys %want_formats;
Expand Down