summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/getopt.t17
1 files changed, 13 insertions, 4 deletions
diff --git a/test/getopt.t b/test/getopt.t
index 87f7550..e4c98ed 100755
--- a/test/getopt.t
+++ b/test/getopt.t
@@ -13,7 +13,7 @@ $GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS] POSITIONAL
function getopt_ok($argv, $exp, $name)
{
$_SERVER['argv'] = array_merge(['doesnotexist.php'], $argv);
- $got = it::getopt($GLOBALS['usage']);
+ $got = it::getopt($GLOBALS['usage'], ['noexit' => true]);
return is($got, $exp, $name);
}
@@ -24,6 +24,15 @@ foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $t
getopt_ok([$testarg, "--argument=$testarg"], $exp, "Long version with equal" . $variant);
}
-$_SERVER['argv'] = ['doesnotexist.php', 'posarg', '-0'];
-$zero_opts = it::getopt($GLOBALS['usage']);
-ok($zero_opts['zero'], '-0');
+$exp = ['args' => [], 'positional' => 'posarg', 'zero' => true];
+getopt_ok(['posarg', '-0'], $exp, 'short argument -0 without value');
+getopt_ok(['posarg', '--zero'], $exp, 'long argument --zero without value');
+getopt_ok(['posarg', '-0', 'vararg'], ['args' => ['vararg']] + $exp, "additional value after short argument -0");
+getopt_ok(['posarg', '--zero', 'vararg'], ['args' => ['vararg']] + $exp, "additional value after long argument --zero");
+
+fclose(STDERR);
+getopt_ok(['posarg', '--unknown'], false, "Unknown long named argument fails");
+getopt_ok(['posarg', '-u'], false, "Unknown short named argument fails");
+getopt_ok([], false, "Missing positional argument fails");
+getopt_ok(['posarg', '--argument'], false, "Missing long named argument fails");
+getopt_ok(['posarg', '-a'], false, "Missing short named argument fails");