summaryrefslogtreecommitdiff
path: root/lib/Getopt
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
commitb695f709e8a342e35e482b0437eb6cdacdc58b6b (patch)
tree2d16192636e6ba806ff7a907f682c74f7705a920 /lib/Getopt
parentd780cd7a0195e946e636d3ee546f6ef4f21d6acc (diff)
downloadperl-b695f709e8a342e35e482b0437eb6cdacdc58b6b.tar.gz
The Grand Trek: move the *.t files from t/ to lib/ and ext/.
No doubt I made some mistakes like missed some files or misnamed some files. The naming rules were more or less: (1) if the module is from CPAN, follows its ways, be it t/*.t or test.pl. (2) otherwise if there are multiple tests for a module put them in a t/ (3) otherwise if there's only one test put it in Module.t (4) helper files go to module/ (locale, strict, warnings) (5) use longer filenames now that we can (but e.g. the compat-0.6.t and the Text::Balanced test files still were renamed to be more civil against the 8.3 people) installperl was updated appropriately not to install the *.t files or the help files from under lib. TODO: some helper files still remain under t/ that could follow their 'masters'. UPDATE: On second thoughts, why should they. They can continue to live under t/lib, and in fact the locale/strict/warnings helpers that were moved could be moved back. This way the amount of non-installable stuff under lib/ stays smaller. p4raw-id: //depot/perl@10676
Diffstat (limited to 'lib/Getopt')
-rwxr-xr-xlib/Getopt/Long/basic.t26
-rwxr-xr-xlib/Getopt/Long/compat.t25
-rwxr-xr-xlib/Getopt/Long/linkage.t37
-rw-r--r--lib/Getopt/Long/oo.t26
-rwxr-xr-xlib/Getopt/Std.t73
5 files changed, 187 insertions, 0 deletions
diff --git a/lib/Getopt/Long/basic.t b/lib/Getopt/Long/basic.t
new file mode 100755
index 0000000000..c5d857d5b8
--- /dev/null
+++ b/lib/Getopt/Long/basic.t
@@ -0,0 +1,26 @@
+#!./perl -w
+
+BEGIN {
+ chdir('t') if -d 't';
+ @INC = '../lib';
+}
+
+use Getopt::Long qw(:config no_ignore_case);
+die("Getopt::Long version 2.24 required--this is only version ".
+ $Getopt::Long::VERSION)
+ unless $Getopt::Long::VERSION >= 2.24;
+
+print "1..9\n";
+
+@ARGV = qw(-Foo -baR --foo bar);
+undef $opt_baR;
+undef $opt_bar;
+print "ok 1\n" if GetOptions ("foo", "Foo=s");
+print ((defined $opt_foo) ? "" : "not ", "ok 2\n");
+print (($opt_foo == 1) ? "" : "not ", "ok 3\n");
+print ((defined $opt_Foo) ? "" : "not ", "ok 4\n");
+print (($opt_Foo eq "-baR") ? "" : "not ", "ok 5\n");
+print ((@ARGV == 1) ? "" : "not ", "ok 6\n");
+print (($ARGV[0] eq "bar") ? "" : "not ", "ok 7\n");
+print (!(defined $opt_baR) ? "" : "not ", "ok 8\n");
+print (!(defined $opt_bar) ? "" : "not ", "ok 9\n");
diff --git a/lib/Getopt/Long/compat.t b/lib/Getopt/Long/compat.t
new file mode 100755
index 0000000000..0bbe386846
--- /dev/null
+++ b/lib/Getopt/Long/compat.t
@@ -0,0 +1,25 @@
+#!./perl -w
+
+BEGIN {
+ chdir('t') if -d 't';
+ @INC = '../lib';
+}
+
+require "newgetopt.pl";
+
+print "1..9\n";
+
+@ARGV = qw(-Foo -baR --foo bar);
+$newgetopt::ignorecase = 0;
+$newgetopt::ignorecase = 0;
+undef $opt_baR;
+undef $opt_bar;
+print "ok 1\n" if NGetOpt ("foo", "Foo=s");
+print ((defined $opt_foo) ? "" : "not ", "ok 2\n");
+print (($opt_foo == 1) ? "" : "not ", "ok 3\n");
+print ((defined $opt_Foo) ? "" : "not ", "ok 4\n");
+print (($opt_Foo eq "-baR") ? "" : "not ", "ok 5\n");
+print ((@ARGV == 1) ? "" : "not ", "ok 6\n");
+print (($ARGV[0] eq "bar") ? "" : "not ", "ok 7\n");
+print (!(defined $opt_baR) ? "" : "not ", "ok 8\n");
+print (!(defined $opt_bar) ? "" : "not ", "ok 9\n");
diff --git a/lib/Getopt/Long/linkage.t b/lib/Getopt/Long/linkage.t
new file mode 100755
index 0000000000..3bd81a3552
--- /dev/null
+++ b/lib/Getopt/Long/linkage.t
@@ -0,0 +1,37 @@
+#!./perl -w
+
+BEGIN {
+ chdir('t') if -d 't';
+ @INC = '../lib';
+}
+
+use Getopt::Long;
+
+print "1..18\n";
+
+@ARGV = qw(-Foo -baR --foo bar);
+Getopt::Long::Configure ("no_ignore_case");
+%lnk = ();
+print "ok 1\n" if GetOptions (\%lnk, "foo", "Foo=s");
+print ((defined $lnk{foo}) ? "" : "not ", "ok 2\n");
+print (($lnk{foo} == 1) ? "" : "not ", "ok 3\n");
+print ((defined $lnk{Foo}) ? "" : "not ", "ok 4\n");
+print (($lnk{Foo} eq "-baR") ? "" : "not ", "ok 5\n");
+print ((@ARGV == 1) ? "" : "not ", "ok 6\n");
+print (($ARGV[0] eq "bar") ? "" : "not ", "ok 7\n");
+print (!(exists $lnk{baR}) ? "" : "not ", "ok 8\n");
+
+@ARGV = qw(-Foo -baR --foo bar);
+Getopt::Long::Configure ("default","no_ignore_case");
+%lnk = ();
+my $foo;
+print "ok 9\n" if GetOptions (\%lnk, "foo" => \$foo, "Foo=s");
+print ((defined $foo) ? "" : "not ", "ok 10\n");
+print (($foo == 1) ? "" : "not ", "ok 11\n");
+print ((defined $lnk{Foo}) ? "" : "not ", "ok 12\n");
+print (($lnk{Foo} eq "-baR") ? "" : "not ", "ok 13\n");
+print ((@ARGV == 1) ? "" : "not ", "ok 14\n");
+print (($ARGV[0] eq "bar") ? "" : "not ", "ok 15\n");
+print (!(exists $lnk{foo}) ? "" : "not ", "ok 16\n");
+print (!(exists $lnk{baR}) ? "" : "not ", "ok 17\n");
+print (!(exists $lnk{bar}) ? "" : "not ", "ok 18\n");
diff --git a/lib/Getopt/Long/oo.t b/lib/Getopt/Long/oo.t
new file mode 100644
index 0000000000..98f3eaadb9
--- /dev/null
+++ b/lib/Getopt/Long/oo.t
@@ -0,0 +1,26 @@
+#!./perl -w
+
+BEGIN {
+ chdir('t') if -d 't';
+ @INC = '../lib';
+}
+
+use Getopt::Long;
+die("Getopt::Long version 2.24 required--this is only version ".
+ $Getopt::Long::VERSION)
+ unless $Getopt::Long::VERSION >= 2.24;
+print "1..9\n";
+
+@ARGV = qw(-Foo -baR --foo bar);
+my $p = new Getopt::Long::Parser (config => ["no_ignore_case"]);
+undef $opt_baR;
+undef $opt_bar;
+print "ok 1\n" if $p->getoptions ("foo", "Foo=s");
+print ((defined $opt_foo) ? "" : "not ", "ok 2\n");
+print (($opt_foo == 1) ? "" : "not ", "ok 3\n");
+print ((defined $opt_Foo) ? "" : "not ", "ok 4\n");
+print (($opt_Foo eq "-baR") ? "" : "not ", "ok 5\n");
+print ((@ARGV == 1) ? "" : "not ", "ok 6\n");
+print (($ARGV[0] eq "bar") ? "" : "not ", "ok 7\n");
+print (!(defined $opt_baR) ? "" : "not ", "ok 8\n");
+print (!(defined $opt_bar) ? "" : "not ", "ok 9\n");
diff --git a/lib/Getopt/Std.t b/lib/Getopt/Std.t
new file mode 100755
index 0000000000..fb70f10aae
--- /dev/null
+++ b/lib/Getopt/Std.t
@@ -0,0 +1,73 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+print "1..11\n";
+
+use Getopt::Std;
+
+# First we test the getopt function
+@ARGV = qw(-xo -f foo -y file);
+getopt('f');
+
+print "not " if "@ARGV" ne 'file';
+print "ok 1\n";
+
+print "not " unless $opt_x && $opt_o && opt_y;
+print "ok 2\n";
+
+print "not " unless $opt_f eq 'foo';
+print "ok 3\n";
+
+
+# Then we try the getopts
+$opt_o = $opt_i = $opt_f = undef;
+@ARGV = qw(-foi -i file);
+getopts('oif:') or print "not ";
+print "ok 4\n";
+
+print "not " unless "@ARGV" eq 'file';
+print "ok 5\n";
+
+print "not " unless $opt_i and $opt_f eq 'oi';
+print "ok 6\n";
+
+print "not " if $opt_o;
+print "ok 7\n";
+
+# Try illegal options, but avoid printing of the error message
+
+open(STDERR, ">stderr") || die;
+
+@ARGV = qw(-h help);
+
+!getopts("xf:y") or print "not ";
+print "ok 8\n";
+
+
+# Then try the Getopt::Long module
+
+use Getopt::Long;
+
+@ARGV = qw(--help --file foo --foo --nobar --num=5 -- file);
+
+GetOptions(
+ 'help' => \$HELP,
+ 'file:s' => \$FILE,
+ 'foo!' => \$FOO,
+ 'bar!' => \$BAR,
+ 'num:i' => \$NO,
+) || print "not ";
+print "ok 9\n";
+
+print "not " unless $HELP && $FOO && !$BAR && $FILE eq 'foo' && $NO == 5;
+print "ok 10\n";
+
+print "not " unless "@ARGV" eq "file";
+print "ok 11\n";
+
+close STDERR;
+unlink "stderr";