summaryrefslogtreecommitdiff
path: root/test/getopt.t
blob: cf3d9e8dd81fb07c11f58382373db56bcbaf9193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/www/server/bin/php -qC
<?php

# Tests for getopt in it.class

$GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS]
	Some help to a not existing program
	  -h,--help          the help argument
	  -a,--argument=ARG  the arg argument
	  -0,--zero          testworthy shortarg
";

function getopt_ok($argv, $exp, $name)
{
	$_SERVER['argv'] = array_merge(['doesnotexist.php'], $argv);
	$got = it::getopt($GLOBALS['usage']);
	return is($got['argument'], $exp, $name);
}

foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $testarg) {
	getopt_ok(['-a', $testarg], $testarg, "Short version" . $variant);
	getopt_ok(['--argument', $testarg], $testarg, "Long version with space" . $variant);
	getopt_ok(["--argument=$testarg"], $testarg, "Long version with equal" . $variant);
}

$_SERVER['argv'] = ['doesnotexist.php', '-0'];
$zero_opts = it::getopt($GLOBALS['usage']);
ok($zero_opts['zero'], '-0');