Permalink
Browse files

[CommandLine] Add in tests for the remaining CommandLine classes. Som…

…e tests are stubbish.
  • Loading branch information...
1 parent 097151c commit 98fd0a984e122d98189ea64b34900d5faffd041e @Whiteknight committed Sep 5, 2012
View
3 src/commandline/ArgumentDef.winxed
@@ -22,6 +22,9 @@ namespace Rosella.CommandLine.ArgumentDef
*/
class Rosella.CommandLine.ArgumentDef
{
+ // TODO: Give a way to slurp up all positionals after position X with a
+ // single alias name.
+
var raw_defs; // The raw argument definitions from the user
var prepared_defs; // The prepared/processed argument definitions
var aliases; // Map of aliased argument names
View
50 t/commandline/ArgumentDef.t
@@ -0,0 +1,50 @@
+// Automatically generated test for Class Rosella.CommandLine.ArgumentDef
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ArgumentDef.NewStyleHash(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ArgumentDef
+{
+ function set_definitions()
+ {
+ self.status.verify("Test Rosella.CommandLine.ArgumentDef.set_definitions()");
+ var obj = create_new();
+
+ var arg_0 = {};
+ var result = obj.set_definitions(arg_0);
+ }
+
+ function get_positional_aliases()
+ {
+ self.status.verify("Test Rosella.CommandLine.ArgumentDef.get_positional_aliases()");
+ var obj = create_new();
+
+ var result = obj.get_positional_aliases();
+ self.assert.equal(elements(result), 0);
+ }
+
+ function get_description()
+ {
+ self.status.verify("Test Rosella.CommandLine.ArgumentDef.get_description()");
+ self.status.unimplemented("Need tests for description generation");
+ var obj = create_new();
+
+ var result = obj.get_description();
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ArgumentDef, initialize_test:[named("initialize")]);
+}
View
36 t/commandline/ArgumentDef/NewStyleHash.t
@@ -0,0 +1,36 @@
+// Automatically generated test for Class Rosella.CommandLine.ArgumentDef.NewStyleHash
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ArgumentDef.NewStyleHash(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ArgumentDef_NewStyleHash
+{
+ function test_sanity()
+ {
+ self.assert.is_true(1);
+ }
+
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ArgumentDef.NewStyleHash();
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ArgumentDef.NewStyleHash);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ArgumentDef_NewStyleHash, initialize_test:[named("initialize")]);
+}
View
36 t/commandline/ArgumentDef/OldStyleArray.t
@@ -0,0 +1,36 @@
+// Automatically generated test for Class Rosella.CommandLine.ArgumentDef.OldStyleArray
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ArgumentDef.OldStyleArray(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ArgumentDef_OldStyleArray
+{
+ function test_sanity()
+ {
+ self.assert.is_true(1);
+ }
+
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ArgumentDef.OldStyleArray();
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ArgumentDef.OldStyleArray);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ArgumentDef_OldStyleArray, initialize_test:[named("initialize")]);
+}
View
32 t/commandline/ArgumentDef/Rosella.CommandLine.ArgumentDef.t
@@ -0,0 +1,32 @@
+// Automatically generated test for NameSpace Rosella.CommandLine.ArgumentDef
+class Test_Rosella_CommandLine_ArgumentDef
+{
+ function get_argument_definition()
+ {
+ self.status.verify("Test Rosella.CommandLine.ArgumentDef.get_argument_definition()");
+ using Rosella.CommandLine.ArgumentDef.get_argument_definition;
+
+ var arg_0 = {};
+ var result = get_argument_definition(arg_0);
+ self.assert.instance_of(result, class Rosella.CommandLine.ArgumentDef.NewStyleHash);
+
+ arg_0 = [];
+ result = get_argument_definition(arg_0);
+ self.assert.instance_of(result, class Rosella.CommandLine.ArgumentDef.OldStyleArray);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Initialize the context, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ArgumentDef, initialize_test:[named("initialize")]);
+}
View
24 t/commandline/ModeCondition.t
@@ -0,0 +1,24 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition
+{
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition, initialize_test:[named("initialize")]);
+}
View
41 t/commandline/ModeCondition/FlagSet.t
@@ -0,0 +1,41 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition.FlagSet
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition.FlagSet(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition_FlagSet
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ModeCondition.FlagSet("foo");
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ModeCondition.FlagSet);
+ }
+
+ function is_satisfied()
+ {
+ self.status.verify("Test Rosella.CommandLine.ModeCondition.FlagSet.is_satisfied()");
+ self.status.unimplemented("Need testing strategy for ModeConditions");
+ var obj = create_new("foo");
+
+ var arg_0 = null;
+ var result = obj.is_satisfied(arg_0);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition_FlagSet, initialize_test:[named("initialize")]);
+}
View
41 t/commandline/ModeCondition/GenericFunc.t
@@ -0,0 +1,41 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition.GenericFunc
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition.GenericFunc(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition_GenericFunc
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ModeCondition.GenericFunc(null, "");
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ModeCondition.GenericFunc);
+ }
+
+ function is_satisfied()
+ {
+ self.status.verify("Test Rosella.CommandLine.ModeCondition.GenericFunc.is_satisfied()");
+ self.status.unimplemented("Need testing strategy for ModeConditions");
+ var obj = create_new();
+
+ var arg_0 = null;
+ var result = obj.is_satisfied(arg_0);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition_GenericFunc, initialize_test:[named("initialize")]);
+}
View
41 t/commandline/ModeCondition/NumPositionals.t
@@ -0,0 +1,41 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition.NumPositionals
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition.NumPositionals(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition_NumPositionals
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ModeCondition.NumPositionals(1, 2);
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ModeCondition.NumPositionals);
+ }
+
+ function is_satisfied()
+ {
+ self.status.verify("Test Rosella.CommandLine.ModeCondition.NumPositionals.is_satisfied()");
+ self.status.unimplemented("Need testing strategy for ModeConditions");
+ var obj = create_new();
+
+ var arg_0 = null;
+ var result = obj.is_satisfied(arg_0);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition_NumPositionals, initialize_test:[named("initialize")]);
+}
View
41 t/commandline/ModeCondition/ScalarExists.t
@@ -0,0 +1,41 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition.ScalarExists
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition.ScalarExists(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition_ScalarExists
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ModeCondition.ScalarExists("foo");
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ModeCondition.ScalarExists);
+ }
+
+ function is_satisfied()
+ {
+ self.status.verify("Test Rosella.CommandLine.ModeCondition.ScalarExists.is_satisfied()");
+ self.status.unimplemented("Need testing strategy for ModeConditions");
+ var obj = create_new();
+
+ var arg_0 = null;
+ var result = obj.is_satisfied(arg_0);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition_ScalarExists, initialize_test:[named("initialize")]);
+}
View
41 t/commandline/ModeCondition/ScalarValue.t
@@ -0,0 +1,41 @@
+// Automatically generated test for Class Rosella.CommandLine.ModeCondition.ScalarValue
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ModeCondition.ScalarValue(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ModeCondition_ScalarValue
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ModeCondition.ScalarValue("foo", "bar");
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ModeCondition.ScalarValue);
+ }
+
+ function is_satisfied()
+ {
+ self.status.verify("Test Rosella.CommandLine.ModeCondition.ScalarValue.is_satisfied()");
+ self.status.unimplemented("Need testing strategy for ModeConditions");
+ var obj = create_new();
+
+ var arg_0 = null;
+ var result = obj.is_satisfied(arg_0);
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ModeCondition_ScalarValue, initialize_test:[named("initialize")]);
+}
View
101 t/commandline/ProgramMode.t
@@ -1,20 +1,21 @@
+function setup_arguments(var defs, var raw_args)
+{
+ var arg_defs = Rosella.CommandLine.ArgumentDef.get_argument_definition(defs);
+ var args = new Rosella.CommandLine.Arguments(null);
+ args.parse(raw_args, arg_defs);
+ return args;
+}
+
// Automatically generated test for Class Rosella.CommandLine.ProgramMode
class Test_Rosella_CommandLine_ProgramMode
{
- function test_new()
- {
- var obj = new Rosella.CommandLine.ProgramMode("");
- self.assert.not_null(obj);
- self.assert.instance_of(obj, class Rosella.CommandLine.ProgramMode);
- }
-
function set_function()
{
self.status.verify("Test Rosella.CommandLine.ProgramMode.set_function()");
var obj = new Rosella.CommandLine.ProgramMode("");
var arg_0 = function(var args) { };
- var result = obj.set_function(arg_0);
+ obj.set_function(arg_0);
}
function set_usage()
@@ -51,23 +52,101 @@ class Test_Rosella_CommandLine_ProgramMode
var result = obj.main_function();
});
- // TODO: test it when we set a function
+ var arg_0 = function(var args) { };
+ obj.set_function(arg_0);
+ var result = obj.main_function();
+ self.assert.same(result, arg_0);
}
function require_flag()
{
- self.status.unimplemented("This");
+ var obj = new Rosella.CommandLine.ProgramMode("");
+ var args = setup_arguments({"foo":"foo","bar":"bar"}, ["--foo"]);
+ obj.require_flag("foo");
+ int result = obj.can_accept(args);
+ self.assert.is_true(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo":"foo", "bar":"bar"}, ["--bar"]);
+ obj.require_flag("foo");
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo":"foo", "bar":"bar"}, ["--bar", "--foo"]);
+ obj.require_flag("foo");
+ result = obj.can_accept(args);
+ self.assert.is_true(result);
}
function require_value()
{
- self.status.unimplemented("This");
+ var obj = new Rosella.CommandLine.ProgramMode("");
+ var args = setup_arguments({"foo=s":"foo","bar=s":"bar"}, ["--foo:baz"]);
+ obj.require_value("foo", "baz");
+ int result = obj.can_accept(args);
+ self.assert.is_true(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s":"foo", "bar=s":"bar"}, ["--foo:fie"]);
+ obj.require_value("foo", "baz");
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s":"foo", "bar=s":"bar"}, ["--bar:baz"]);
+ obj.require_value("foo", "baz");
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
}
function require_condition()
{
self.status.unimplemented("This");
}
+
+ function require_scalar()
+ {
+ var obj = new Rosella.CommandLine.ProgramMode("");
+ var args = setup_arguments({"foo=s":"foo","bar=s":"bar"}, ["--foo:baz"]);
+ obj.require_scalar("foo");
+ int result = obj.can_accept(args);
+ self.assert.is_true(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s":"foo", "bar=s":"bar"}, ["--bar:fie"]);
+ obj.require_scalar("foo");
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
+ }
+
+ function require_positionals()
+ {
+ var obj = new Rosella.CommandLine.ProgramMode("");
+ var args = setup_arguments({"foo=s0":"foo","bar=s1":"bar"}, ["AAA", "BBB"]);
+ obj.require_positionals(2);
+ int result = obj.can_accept(args);
+ self.assert.is_true(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s0":"foo","bar=s1":"bar"}, ["AAA", "BBB"]);
+ obj.require_positionals(2, 2);
+ result = obj.can_accept(args);
+ self.assert.is_true(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s0":"foo","bar=s1":"bar"}, ["AAA"]);
+ obj.require_positionals(2);
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
+
+ obj = new Rosella.CommandLine.ProgramMode("");
+ args = setup_arguments({"foo=s0":"foo","bar=s1":"bar"}, ["AAA", "BBB", "CCC"]);
+ obj.require_positionals(2, 2);
+ result = obj.can_accept(args);
+ self.assert.is_false(result);
+
+ }
}
function main[main]()
View
81 t/commandline/ProgramMode/Default.t
@@ -0,0 +1,81 @@
+// Automatically generated test for Class Rosella.CommandLine.ProgramMode.Default
+function create_new(var p_args [slurpy], var n_args [slurpy,named])
+{
+ return new Rosella.CommandLine.ProgramMode.Default(p_args:[flat], n_args:[flat,named]);
+}
+
+class Test_Rosella_CommandLine_ProgramMode_Default
+{
+ function test_new()
+ {
+ // Test simple constructor. For most individual method tests, use create_new() above
+ var obj = new Rosella.CommandLine.ProgramMode.Default();
+ self.assert.not_null(obj);
+ self.assert.instance_of(obj, class Rosella.CommandLine.ProgramMode.Default);
+ }
+
+ function get_usage()
+ {
+ self.status.verify("Test Rosella.CommandLine.ProgramMode.Default.get_usage()");
+ self.status.unimplemented("Find a strategy for testing usage messages");
+ var obj = create_new();
+
+ var arg_0 = null;
+ var result = obj.get_usage(arg_0);
+ }
+
+ function require_flag()
+ {
+ self.status.verify("Test Rosella.CommandLine.ProgramMode.Default.require_flag()");
+ var obj = create_new();
+
+ self.assert.throws(function() {
+ var result = obj.require_flag("");
+ });
+ }
+
+ function require_value()
+ {
+ self.status.verify("Test Rosella.CommandLine.ProgramMode.Default.require_value()");
+ var obj = create_new();
+
+ self.assert.throws(function() {
+ var result = obj.require_value("A", "B");
+ });
+ }
+
+ function require_condition()
+ {
+ self.status.verify("Test Rosella.CommandLine.ProgramMode.Default.require_condition()");
+ var obj = create_new();
+
+ self.assert.throws(function() {
+ var result = obj.require_condition(null);
+ });
+ }
+
+ function require_positionals()
+ {
+ self.status.verify("Test Rosella.CommandLine.ProgramMode.Default.require_positionals()");
+ var obj = create_new();
+
+ self.assert.throws(function() {
+ var result = obj.require_positionals(2, 2);
+ });
+ }
+}
+
+function initialize_test[anon](var context)
+{
+ // Set up the test suite here. Set options on the Suite, set up matchers
+ // in the matcher factory, load prerequisites, and do other things.
+ var(Rosella.load_bytecode_file)("rosella/commandline.pbc", "load");
+}
+
+function main[main]()
+{
+ var core = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("test");
+ using initialize_test;
+ var(Rosella.Test.test)(class Test_Rosella_CommandLine_ProgramMode_Default, initialize_test:[named("initialize")]);
+}

0 comments on commit 98fd0a9

Please sign in to comment.