Permalink
Browse files

[Utilities] Update test_template and test_all_lib utilities to use th…

…e new CommandLine api
  • Loading branch information...
1 parent 0f6b180 commit 097151c25f26b7c03b6d2f792df1527cd9c55a12 @Whiteknight committed Sep 5, 2012
View
10 src/commandline/Arguments.winxed
@@ -169,6 +169,16 @@ class Rosella.CommandLine.Arguments
return false;
}
+ function get_positionals(int start = -1)
+ {
+ if (start == -1)
+ return self.pos_cache;
+ string pos_from[] = [];
+ for (int i = start; i < elements(self.pos_cache); i++)
+ push(pos_from, string(self.pos_cache[i]));
+ return pos_from;
+ }
+
/* VTABLEs
*/
View
1 src/commandline/ModeCondition.winxed
@@ -194,6 +194,7 @@ class Rosella.CommandLine.ModeCondition.NumPositionals : Rosella.CommandLine.Mod
function get_description(var sb)
{
+ // TODO: This!
//push(sb, " ...");
}
}
View
15 src/commandline/ProgramMode.winxed
@@ -116,6 +116,16 @@ class Rosella.CommandLine.ProgramMode
push(self.conditions, condition);
return self;
}
+
+ // Require that a scalar value be provided with any value
+ function require_positionals(int min, int max = min)
+ {
+ if (self.conditions == null)
+ self.conditions = [];
+ var condition = new Rosella.CommandLine.ModeCondition.NumPositionals(min, max);
+ push(self.conditions, condition);
+ return self;
+ }
}
// Default program mode, similar to a normal mode but with no preconditions
@@ -159,6 +169,11 @@ class Rosella.CommandLine.ProgramMode.Default : Rosella.CommandLine.ProgramMode
Rosella.Error.error("May not add prerequisite conditions to the default program mode");
}
+ function require_positionals(int a, int b = a)
+ {
+ Rosella.Error.error("May not add prerequisite conditions to the default program mode");
+ }
+
function can_accept(var args)
{
return true;
View
18 src/utilities/test_all_lib.winxed
@@ -5,24 +5,30 @@ function main[main](var args)
var p = new Rosella.CommandLine.Program(args.shift());
p
.define_arguments({
- "help|h" : "Show the help message"
+ "help|h" : "Show the help message",
+ "lang=s0" : "The language to use",
+ "library=s1" : "The library to read",
+ "folder=s2" : "Folder to generate tests in"
})
.set_description("Create tests for all classes and namespaces in <library>. Output all tests\n" +
"to <folder>. Tests will be in language <lang>. <lang> is probably one of\n" +
"'winxed' or 'nqp' or others if you have suitable templates installed.");
- p.default_mode()
+ p.default_mode().set_function(function(var a) { say(a.program.get_help_text()); });
+ p.add_mode("test_all")
.set_function(test_all_main)
- .require_positionals(false, "lang", "library", "folder");
- p.add_mode("help").require_flag("help").set_function(function(var args) { say(p.get_help_message()); });
+ .require_positionals(3, 3);
+ p.add_mode("help")
+ .require_flag("help")
+ .set_function(function(var args) { say(p.get_help_text()); });
p.run(args);
}
// Main handler. Pull out the arguments by name and run the program.
function test_all_main(var args)
{
string libpath = args[1];
- string lang = args[0];
- string folder = args[2];
+ string lang = args[0];
+ string folder = args[2];
var module = Rosella.Reflect.Module.load(libpath);
var engine = new Rosella.Template.Engine();
View
36 src/utilities/test_template.winxed
@@ -5,16 +5,30 @@ function main[main](var args)
{
Rosella.Query.install_to_parrot_types();
var program = new Rosella.CommandLine.Program(args.shift());
- program.add_mode("help").set_flag("--help").set_function(show_help);
- program.add_mode("version").set_flag("--version").set_function(show_version);
- program.add_mode("harness").set_flag("harness").set_function(harness_main)
- .require_positional("language", 1)
- .require_args({ "dirs" : "*" });
- program.add_mode("test").set_flag("test").set_function(test_main)
- .require_positional("language", 1)
- .require_positional("libname", 2)
- .require_positional("classname", 3);
- program.on_error(show_help);
+ program
+ .define_arguments({
+ "help" : "Show the help message",
+ "version" : "Display version information",
+ "harness" : "Generate a test harness",
+ "test" : "Generate test classes",
+ "language=s0" : "Language to use",
+ "libname=s1" : ".pbc library to read",
+ "classname=s3" : "Class to generate tests for"
+ });
+
+ program.add_mode("help").require_flag("help").set_function(show_help);
+ program.add_mode("version").require_flag("version").set_function(show_version);
+
+ program.add_mode("harness")
+ .require_flag("harness")
+ .require_positionals(1)
+ .set_function(harness_main);
+
+ program.add_mode("test")
+ .require_flag("test")
+ .require_positionals(3)
+ .set_function(test_main);
+
program.run(args);
}
@@ -36,7 +50,7 @@ function harness_main(var args)
{
string mode = args["mode"];
string language = args["language"];
- var dirs = args["dirs"];
+ var dirs = args.get_positionals(3);
string template = get_template_text("test_harness", language);
var context = harness_template_context(template, dirs);
var engine = new Rosella.Template.Engine();

0 comments on commit 097151c

Please sign in to comment.