hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f27664d115053f4f325050e4d53bfa4c8110ddff
parent e740ad87e1d2305fe67852c184cf856b67aebfc3
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 28 Mar 2021 12:38:18 -0400

hare test: stub out functionality

This is not going to work correctly until hare::module has sorting and
preference handling.

Diffstat:
Mcmd/hare/subcmds.ha | 65++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -218,7 +218,70 @@ fn test(args: []str) void = { let cmd = getopt::parse(args, help...); defer getopt::finish(&cmd); - abort(); // TODO + let verbose = false; + let defines: []str = []; + for (let i = 0z; i < len(cmd.opts); i += 1) { + let opt = cmd.opts[i]; + switch (opt.0) { + 'v' => verbose = true, + 'D' => append(defines, opt.1), + 'j' => abort(), // TODO + 'l' => abort(), // TODO + 't' => abort(), // TODO + 'T' => abort(), // TODO + 'X' => abort(), // TODO + * => abort(), + }; + }; + + let input = ""; + let runargs: []str = []; + if (len(cmd.args) == 0) { + input = os::getcwd(); + } else { + input = cmd.args[0]; + runargs = cmd.args[1..]; + }; + + let tags = default_tags(); + defer free(tags); + append(tags, module::tag { + name = "test", + mode = module::tag_mode::INCLUSIVE, + }); + + let ctx = module::context_init(tags, defines, HAREPATH); + defer module::context_finish(&ctx); + + let plan = mkplan(&ctx); + defer plan_finish(&plan); + + let ver = match (module::scan(&ctx, input)) { + ver: module::version => ver, + err: module::error => fmt::fatal( + "Error scanning input module: {}", + module::errstr(err)), + }; + + let depends: []*task = []; + + // Always add rt (TODO: maybe a flag to turn this off?) + sched_module(&plan, ["rt"], &depends); + + for (let i = 0z; i < len(ver.depends); i += 1z) { + const dep = ver.depends[i]; + sched_module(&plan, dep, &depends); + }; + + let output = mkfile(&plan, "out"); + sched_hare_exe(&plan, ver, output, depends...); + plan_execute(&plan, verbose); + let cmd = match (exec::cmd(output, runargs...)) { + err: exec::error => fmt::fatal("exec: {}", exec::errstr(err)), + cmd: exec::command => cmd, + }; + exec::setname(&cmd, input); + exec::exec(&cmd); }; fn version(args: []str) void = {