I am trying to find a creative way to define dependencies so that I can run the test regression in the correct sequence.
For instance:
a: d, e, f
b: c, d
c: f
d: e
This means that the test "a" depends on the completion of the tests "d, e and f", etc.
I have the following code that will print the "leaf" nodes "e" and "f", however I am stuck with how to go about crawling and print the parent nodes. Any advice would be greatly appreciated.
Thank!
my @input = ("a:d,e,f", "b:c,d", "c:f", "d:e");
my %Tests = ();
my %Built = ();
foreach my $elem (@input) {
my $depends = [];
my $target;
($target,$depends) = parseData($elem);
$Tests{$target} = $depends;
}
sub parseData {
my $data = shift;
my ($target, $deps) = split(/:/, $data);
my @deps;
@deps = split(/,/, $deps);
return ($target,\@deps);
}
foreach my $key (keys %Tests) {
doIT(\%Tests, \%Built, $key);
}
sub doIT {
my ($testRef, $builtRef, $target) = @_;
my $depends = $testRef->{$target};
if(exists $builtRef->{$target}) {
return;
}
if(!$depends) {
print "RunTest($target)\n";
$builtRef->{$target}++;
return;
}
foreach my $dep (@$depends) {
doIT($testRef, $builtRef, $dep);
}
}
source
share