perl 5.003_07: Configure
[p5sagit/p5-mst-13.2.git] / t / lib / getopt.t
CommitLineData
1a3850a5 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8print "1..11\n";
9
10use Getopt::Std;
11
12# First we test the getopt function
13@ARGV = qw(-xo -f foo -y file);
14getopt('f');
15
16print "not " if "@ARGV" ne 'file';
17print "ok 1\n";
18
19print "not " unless $opt_x && $opt_o && opt_y;
20print "ok 2\n";
21
22print "not " unless $opt_f eq 'foo';
23print "ok 3\n";
24
25
26# Then we try the getopts
27$opt_o = $opt_i = $opt_f = undef;
28@ARGV = qw(-foi -i file);
29getopts('oif:') or print "not ";
30print "ok 4\n";
31
32print "not " unless "@ARGV" eq 'file';
33print "ok 5\n";
34
35print "not " unless $opt_i and $opt_f eq 'oi';
36print "ok 6\n";
37
38print "not " if $opt_o;
39print "ok 7\n";
40
41# Try illegal options, but avoid printing of the error message
42
43open(STDERR, ">stderr") || die;
44unlink "stderr";
45
46@ARGV = qw(-h help);
47
48!getopts("xf:y") or print "not ";
49print "ok 8\n";
50
51
52# Then try the Getopt::Long module
53
54use Getopt::Long;
55
56@ARGV = qw(--help --file foo --foo --nobar --num=5 -- file);
57
58GetOptions(
59 'help' => \$HELP,
60 'file:s' => \$FILE,
61 'foo!' => \$FOO,
62 'bar!' => \$BAR,
63 'num:i' => \$NO,
64) || print "not ";
65print "ok 9\n";
66
67print "not " unless $HELP && $FOO && !$BAR && $FILE eq 'foo' && $NO == 5;
68print "ok 10\n";
69
70print "not " unless "@ARGV" eq "file";
71print "ok 11\n";