1#!./perl -w 2 3no strict; 4 5BEGIN { 6 if ($ENV{PERL_CORE}) { 7 @INC = '../lib'; 8 chdir 't'; 9 } 10} 11 12use Getopt::Long qw(GetOptionsFromString :config no_ignore_case); 13my $want_version="2.3501"; 14die("Getopt::Long version $want_version required--this is only version ". 15 $Getopt::Long::VERSION) 16 unless $Getopt::Long::VERSION ge $want_version; 17 18print "1..14\n"; 19 20my $args = "-Foo -baR --foo"; 21@ARGV = qw(foo bar); 22undef $opt_baR; 23undef $opt_bar; 24print (GetOptionsFromString($args, "foo", "Foo=s") ? "" : "not ", "ok 1\n"); 25print ((defined $opt_foo) ? "" : "not ", "ok 2\n"); 26print (($opt_foo == 1) ? "" : "not ", "ok 3\n"); 27print ((defined $opt_Foo) ? "" : "not ", "ok 4\n"); 28print (($opt_Foo eq "-baR") ? "" : "not ", "ok 5\n"); 29print (!(defined $opt_baR) ? "" : "not ", "ok 6\n"); 30print (!(defined $opt_bar) ? "" : "not ", "ok 7\n"); 31print ("@ARGV" eq "foo bar" ? "" : "not ", "ok 8\n"); 32 33$args = "-Foo -baR blech --foo bar"; 34@ARGV = qw(foo bar); 35undef $opt_baR; 36undef $opt_bar; 37{ my $msg = ""; 38 local $SIG{__WARN__} = sub { $msg .= "@_" }; 39 my $ret = GetOptionsFromString($args, "foo", "Foo=s"); 40 print ($ret ? "not " : "ok 9\n"); 41 print ($msg =~ /^GetOptionsFromString: Excess data / ? "" : "$msg\nnot ", "ok 10\n"); 42} 43print ("@ARGV" eq "foo bar" ? "" : "not ", "ok 11\n"); 44 45$args = "-Foo -baR blech --foo bar"; 46@ARGV = qw(foo bar); 47undef $opt_baR; 48undef $opt_bar; 49{ my $ret; 50 ($ret, $args) = GetOptionsFromString($args, "foo", "Foo=s"); 51 print ($ret ? "" : "not ", "ok 12\n"); 52 print ("@$args" eq "blech bar" ? "" : "@$args\nnot ", "ok 13\n"); 53} 54print ("@ARGV" eq "foo bar" ? "" : "not ", "ok 14\n"); 55