Commits

Anonymous committed 0c474e7

1. Added the unit test for Getopt.pm

2. Added a "make check" command to the top makefile.

3. Fixed a bug in Getopt.pm.

  • Participants
  • Parent commits ca93506

Comments (0)

Files changed (4)

installer/Makefile.am

 
 EXTRA_DIST += quad-pres.spec quad-pres.spec.in
 
+check: prepare_check purecheck
+
+prepare_check:
+	@rm -fr tests/installation
+	@mkdir tests/installation
+	@make clean
+	@make install prefix=`pwd`/tests/installation
+
+purecheck:
+	@PATH=`pwd`/tests/installation:$$PATH ; \
+	export PERL5LIB=`pwd`/tests/installation/share/quad-pres/perl5/ ; \
+	make -C tests
+

installer/perl5/Shlomif/Quad/Pres/Getopt.pm

 #
 # It's a kludge, but it works.
 
-require Getopt::Long '2.24';
+use Getopt::Long '2.24';
 
 sub new
 {
     my $self = shift;
 
     my (@params) = (@_);
+    my (@ret);
 
     my $getopt = $self->get_getopt();
 
     {
         local @ARGV = @{$self->{'args'}};
-        return $getopt->getoptions(@params);
+        @ret = $getopt->getoptions(@params);
         @{$self->{'args'}} = @ARGV;
     }
+
+    return @ret;
 }
 
 1;

installer/tests/Makefile

+all: check
+
+check: stop-error perl test-lang-settings 
+
+test-lang-settings: 
+	bash test-lang-settings.bash
+
+stop-error:
+	cd stop-on-error && bash test1.bash
+
+perl: perl-getopt
+
+perl-getopt:
+	perl perl/Getopt.pl
+	

installer/tests/perl/Getopt.pl

+#!/usr/bin/perl -w
+
+use strict;
+
+use Shlomif::Quad::Pres::Getopt;
+
+my @args = ("-w", "--option", "hello", "yes", "there", "-t");
+my $parser = 
+    Shlomif::Quad::Pres::Getopt->new(
+        \@args,
+    );
+
+$parser->configure("require_order");
+
+my $is_w = 0;
+my $option_val = "";
+$parser->getoptions(
+    'w' => \$is_w,
+    'option=s' => \$option_val,
+);
+
+if ((! $is_w) || ($option_val ne "hello"))
+{
+    die "Arguments were not processed correctly!";
+}
+
+if (join("|", @args) ne "yes|there|-t")
+{
+    die "Arguments left are incorrect! Arguments are:\n" . 
+        join("", map { "$_: $args[$_]\n" } (0 .. $#args));
+}
+