Somewhat working test running

This commit is contained in:
Nathan McCarty 2024-12-31 19:11:46 +00:00
parent 49c118eef4
commit 9bd0cc323f
3 changed files with 82 additions and 7 deletions

View file

@ -3,8 +3,29 @@ unit module IUtils;
need IUtils::IDEMode;
use IUtils::Regexes;
use paths;
#| Structure representing the tests in a module
class ModuleTests {
#| The name of this module
has Str:D $.name is required;
#| The source file of this module
has IO::Path:D $.source is required;
#| A list of the associated tests this module has
has Str:D @.tests is required;
}
#| Structure representing all of the runables assocated with a project
class PackageRunables {
#| The ipkg for this project
has IO::Path:D $.ipkg is required;
# TODO: Add benchmarks
#| A map from the name of the module to a list of tests
has ModuleTests:D %.tests is required;
}
#| Structure representing the root of what idris considers a package directory,
#| with the associated ipkg and source files. These can and will overlap within
#| the same directory.
@ -12,6 +33,29 @@ class PackageInfo {
has IO::Path:D $.ipkg is required;
has IO::Path:D $.root is required;
has IO::Path:D @.sources is required;
method runnables {
# Locate the tests
my %tests = Hash.new;
for @.sources -> $source {
my $contents = $source.slurp;
if $contents ~~ &module-name {
my $module-name = $<name>.Str;
my @tests;
for $contents.match(&flagged-expression, :g) -> $match {
@tests.push($match<test-name>.Str);
}
if @tests.elems > 0 {
%tests{$module-name} =
ModuleTests.new(name => $module-name,
source => $source,
tests => @tests);
}
}
}
# Build and return the runnables
PackageRunables.new(ipkg => self.ipkg, tests => %tests)
}
}
#| Scan a particular ipkg for its associated sources

View file

@ -12,3 +12,7 @@ my regex flagged-expression is export {
[<&comment-start> \V* \v]*
<expression-name=&name> \h+ \: \V* \v
}
my regex module-name is export {
'module' \h* $<name>=(\S+)
}