#!/www/server/bin/php -qC true]); return is($got, $exp, $name); } foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $testarg) { $exp = ['args' => [], 'positional' => $testarg, 'argument' => $testarg, 'default' => 'defäult']; getopt_ok([$testarg, '-a', $testarg], $exp, "Short version" . $variant); getopt_ok([$testarg, '--argument', $testarg], $exp, "Long version with space" . $variant); getopt_ok([$testarg, "--argument=$testarg"], $exp, "Long version with equal" . $variant); } getopt_ok(['posargs', '-c'], ['args' => [], 'positional' => 'posargs', 'comma' => true, 'default' => 'defäult'], "comma and minus in description doesn't break shortopt"); $exp = ['args' => [], 'positional' => 'posarg', 'zero' => true, 'default' => 'defäult']; 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(['posargs', '-m'], false, "comma and minus in description doesn't break shortopt 2"); 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"); $GLOBALS['usage'] = it::replace(['\s*\[VARARGS\]' => ''], $GLOBALS['usage']); getopt_ok(['posargs', 'vararg'], false, "Extra positional argument fails"); getopt_ok(['posargs', '--zero', 'vararg'], false, "Extra positional argument fails after long argument"); getopt_ok(['posargs', '-0', 'vararg'], false, "Extra positional argument fails after short argument"); getopt_ok(['posargs', '--argument', 'value', 'vararg'], false, "Extra positional argument fails after long argument with value"); getopt_ok(['posargs', '-a', 'value', 'vararg'], false, "Extra positional argument fails after short argument with value");