Compare commits
No commits in common. "9bd0cc323f3dc800ab5d0331d8c2746d003596d9" and "9e9903429eb52aabfb247c079fcc29995b4ee51b" have entirely different histories.
9bd0cc323f
...
9e9903429e
5 changed files with 81 additions and 158 deletions
|
@ -12,8 +12,7 @@
|
||||||
"provides": {
|
"provides": {
|
||||||
"IUtils": "lib/IUtils.rakumod",
|
"IUtils": "lib/IUtils.rakumod",
|
||||||
"IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod",
|
"IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod",
|
||||||
"IUtils::Regexs": "lib/IUtils/Regexes.rakumod",
|
"IUtils::Comments": "lib/IUtils/Comments.rakumod"
|
||||||
"IUtils::Compiler": "lib/IUtils/Compiler.rakumod"
|
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"iutils": "bin/iutils"
|
"iutils": "bin/iutils"
|
||||||
|
|
43
bin/iutils
43
bin/iutils
|
@ -1,10 +1,8 @@
|
||||||
#!/usr/bin/env raku
|
#!/usr/bin/env raku
|
||||||
use v6.d;
|
use v6.d;
|
||||||
use IUtils;
|
use IUtils;
|
||||||
use IUtils::Regexes;
|
use IUtils::Comments;
|
||||||
use IUtils::Compiler;
|
|
||||||
|
|
||||||
# TODO: Add filtering for tests based on module/name
|
|
||||||
#| Execute the tests in an idris project
|
#| Execute the tests in an idris project
|
||||||
multi MAIN(
|
multi MAIN(
|
||||||
"test",
|
"test",
|
||||||
|
@ -14,38 +12,13 @@ multi MAIN(
|
||||||
chdir($project-path.IO.resolve: :completely) if $project-path;
|
chdir($project-path.IO.resolve: :completely) if $project-path;
|
||||||
# Scan for our packages
|
# Scan for our packages
|
||||||
my @packages = scan-packages;
|
my @packages = scan-packages;
|
||||||
# Collect runables
|
# Collect tests
|
||||||
my @runables = @packages.map: *.runnables;
|
my @tests;
|
||||||
# Run the tests
|
for @packages -> $package {
|
||||||
my $basedir = $*CWD;
|
# FIXME
|
||||||
for @runables -> $runable {
|
say 'Finding tests for ', $package.ipkg.relative;
|
||||||
# Make sure the package is built
|
for $package.sources -> $source {
|
||||||
pack-build $runable.ipkg.relative;
|
say 'Scanning for tests in ', $source;
|
||||||
# CD to the local directory to make sure idris can exec the expressions
|
|
||||||
indir $runable.ipkg.parent, {
|
|
||||||
next unless $runable.tests.elems > 0;
|
|
||||||
say "** Testing {$runable.ipkg.relative: $basedir}";
|
|
||||||
for $runable.tests.keys -> $module-name {
|
|
||||||
my $module = $runable.tests{$module-name};
|
|
||||||
next unless $module.tests.elems > 0;
|
|
||||||
say "-- Testing $module-name".indent(2);
|
|
||||||
for $module.tests -> $test {
|
|
||||||
try {
|
|
||||||
idris-exec $test, $module.source.relative;
|
|
||||||
}
|
|
||||||
if $! {
|
|
||||||
my $stdout = $1.err.lines.map(*.indent(8)).join("\n");
|
|
||||||
say "+ $test: FAIL".indent(4);
|
|
||||||
say "stdout:".indent(6);
|
|
||||||
$!.err.lines.map(*.indent(8)).join("\n");
|
|
||||||
say "stderr:".indent(6);
|
|
||||||
$!.err.lines.map(*.indent(8)).join("\n");
|
|
||||||
say "exit code: {$!.exit-code}"
|
|
||||||
} else {
|
|
||||||
say "+ $test: Pass".indent(4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,29 +3,8 @@ unit module IUtils;
|
||||||
|
|
||||||
need IUtils::IDEMode;
|
need IUtils::IDEMode;
|
||||||
|
|
||||||
use IUtils::Regexes;
|
|
||||||
|
|
||||||
use paths;
|
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,
|
#| Structure representing the root of what idris considers a package directory,
|
||||||
#| with the associated ipkg and source files. These can and will overlap within
|
#| with the associated ipkg and source files. These can and will overlap within
|
||||||
#| the same directory.
|
#| the same directory.
|
||||||
|
@ -33,29 +12,6 @@ class PackageInfo {
|
||||||
has IO::Path:D $.ipkg is required;
|
has IO::Path:D $.ipkg is required;
|
||||||
has IO::Path:D $.root is required;
|
has IO::Path:D $.root is required;
|
||||||
has IO::Path:D @.sources 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
|
#| Scan a particular ipkg for its associated sources
|
||||||
|
@ -81,3 +37,74 @@ sub scan-packages(--> Array[PackageInfo:D]) is export {
|
||||||
paths(:file(*.ends-with(".ipkg"))).map(*.IO.&scan-ipkg);
|
paths(:file(*.ends-with(".ipkg"))).map(*.IO.&scan-ipkg);
|
||||||
return @ipkgs;
|
return @ipkgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Utility functions for pack
|
||||||
|
|
||||||
|
#| Invoke a pack command
|
||||||
|
sub pack-run(*@cmd) is export {
|
||||||
|
my $proc = run "pack", @cmd, :out, :err;
|
||||||
|
my $out = $proc.out.slurp(:close);
|
||||||
|
my $err = $proc.err.slurp(:close);
|
||||||
|
unless $proc {
|
||||||
|
die qq:to/END/;
|
||||||
|
Pack Failure!
|
||||||
|
Captured Output:
|
||||||
|
$out
|
||||||
|
|
||||||
|
Captured StdErr:
|
||||||
|
$err
|
||||||
|
END
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Build a package with pack
|
||||||
|
sub pack-build($pkg) is export {
|
||||||
|
pack-run 'build', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Test a package with pack
|
||||||
|
sub pack-test($pkg) is export {
|
||||||
|
pack-run 'build', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Clean a package with pack
|
||||||
|
sub pack-clean($pkg) is export {
|
||||||
|
pack-run 'clean', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
# Utility functions for idris
|
||||||
|
|
||||||
|
#| An error coming from the idris compiler
|
||||||
|
class IdrisError is Exception {
|
||||||
|
has Str $.out;
|
||||||
|
has Str $.err;
|
||||||
|
has Int $.exit-code;
|
||||||
|
has Str $.command;
|
||||||
|
|
||||||
|
method message {
|
||||||
|
qq:to/END/;
|
||||||
|
Error running idris command: $.command
|
||||||
|
Command exited with $.exit-code
|
||||||
|
END
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Invoke an idris command
|
||||||
|
sub idris-run(*@cmd) is export {
|
||||||
|
my $proc = run "idris2", @cmd, :out, :err;
|
||||||
|
my $out = $proc.out.slurp(:close);
|
||||||
|
my $err = $proc.err.slurp(:close);
|
||||||
|
unless $proc {
|
||||||
|
IdrisError.new(
|
||||||
|
out => $out, err => $err,
|
||||||
|
exit-code => $proc.exitcode, command => @cmd.Str)
|
||||||
|
.throw;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Exec the expression with the given name in the given file
|
||||||
|
sub idris-exec($expr, $file) is export {
|
||||||
|
idris-run '--find-ipkg', '--exec', $expr, $file
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
unit module IUtils::Regexes;
|
unit module IUtils::Comments;
|
||||||
|
|
||||||
my token comment-start { \- \- }
|
my token comment-start { \- \- }
|
||||||
my token type {
|
my token type {
|
||||||
|
@ -12,7 +12,3 @@ my regex flagged-expression is export {
|
||||||
[<&comment-start> \V* \v]*
|
[<&comment-start> \V* \v]*
|
||||||
<expression-name=&name> \h+ \: \V* \v
|
<expression-name=&name> \h+ \: \V* \v
|
||||||
}
|
}
|
||||||
|
|
||||||
my regex module-name is export {
|
|
||||||
'module' \h* $<name>=(\S+)
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
#| Utilities for interacting with the idris compiler and package manager
|
|
||||||
unit module IUtils::Compiler;
|
|
||||||
|
|
||||||
# Utility functions for pack
|
|
||||||
|
|
||||||
#| Invoke a pack command
|
|
||||||
sub pack-run(*@cmd) is export {
|
|
||||||
my $proc = run "pack", @cmd, :out, :err;
|
|
||||||
my $out = $proc.out.slurp(:close);
|
|
||||||
my $err = $proc.err.slurp(:close);
|
|
||||||
unless $proc {
|
|
||||||
die qq:to/END/;
|
|
||||||
Pack Failure!
|
|
||||||
Captured Output:
|
|
||||||
$out
|
|
||||||
|
|
||||||
Captured StdErr:
|
|
||||||
$err
|
|
||||||
END
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Build a package with pack
|
|
||||||
sub pack-build($pkg) is export {
|
|
||||||
pack-run 'build', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Test a package with pack
|
|
||||||
sub pack-test($pkg) is export {
|
|
||||||
pack-run 'build', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Clean a package with pack
|
|
||||||
sub pack-clean($pkg) is export {
|
|
||||||
pack-run 'clean', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
# Utility functions for idris
|
|
||||||
|
|
||||||
#| An error coming from the idris compiler
|
|
||||||
class IdrisError is Exception {
|
|
||||||
has Str $.out;
|
|
||||||
has Str $.err;
|
|
||||||
has Int $.exit-code;
|
|
||||||
has Str $.command;
|
|
||||||
|
|
||||||
method message {
|
|
||||||
qq:to/END/;
|
|
||||||
Error running idris command: $.command
|
|
||||||
Command exited with $.exit-code
|
|
||||||
END
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Invoke an idris command
|
|
||||||
sub idris-run(*@cmd) is export {
|
|
||||||
my $proc = run "idris2", @cmd, :out, :err;
|
|
||||||
my $out = $proc.out.slurp(:close);
|
|
||||||
my $err = $proc.err.slurp(:close);
|
|
||||||
unless $proc {
|
|
||||||
IdrisError.new(
|
|
||||||
out => $out, err => $err,
|
|
||||||
exit-code => $proc.exitcode, command => @cmd.Str)
|
|
||||||
.throw;
|
|
||||||
}
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Exec the expression with the given name in the given file
|
|
||||||
sub idris-exec($expr, $file) is export {
|
|
||||||
idris-run '--find-ipkg', '--exec', $expr, $file
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue