Author: jkeenan
Date: Sat Jan 27 12:17:49 2007
New Revision: 16820

Modified:
   branches/buildtools/t/tools/ops2pmutils/02-usage.t

Log:
Wrote tests for options processing using
Parrot::Ops2pm::Auxiliary::getoptions().
Conforming to Parrot coding standards, placing 'use strict' and 'use warnings'
before BEGIN block.  Accordingly, first mention of $topdir => our $topdir.


Modified: branches/buildtools/t/tools/ops2pmutils/02-usage.t
==============================================================================
--- branches/buildtools/t/tools/ops2pmutils/02-usage.t  (original)
+++ branches/buildtools/t/tools/ops2pmutils/02-usage.t  Sat Jan 27 12:17:49 2007
@@ -3,32 +3,13 @@
 # $Id$
 # 02-usage.t
 
-package Capture;
-# Adapted from IO::Capture::Tie_STDx.
-# Thanks as always to Mark Reynolds and Jon Morgan!
-
-sub TIEHANDLE {
-    my $class = shift;
-    bless [], $class;
-}
-
-sub PRINT {
-     my $self = shift;
-     push @$self, join '',@_;
-}
-
-sub READLINE {
-    my $self = shift;
-    return wantarray ? @$self : shift @$self;
-}
-
-package main;
-
+use strict;
+use warnings;
 BEGIN {
     use FindBin qw($Bin);
     use Cwd qw(cwd realpath);
     realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
-    $topdir = $1;
+    our $topdir = $1;
     if (defined $topdir) {
         print "\nOK:  Parrot top directory located\n";
     } else {
@@ -36,22 +17,50 @@
     }
     unshift @INC, qq{$topdir/lib};
 }
-use strict;
-use warnings;
-use Test::More tests =>  4;
+use Test::More tests =>  14;
 use Carp;
+use Cwd;
+use lib ("$main::topdir/t/tools/ops2pmutils/testlib");
+use_ok( "Capture" );
 
-use_ok( 'Parrot::Ops2pm::Auxiliary', qw| Usage | );
+use_ok( 'Parrot::Ops2pm::Auxiliary', qw| Usage getoptions | );
 
 ok(chdir $main::topdir, "Positioned at top-level Parrot directory");
-my $msg;
-my $tie = tie *STDERR, "Capture" or croak "Unable to tie";
-Usage();
-$msg = $tie->READLINE;
-untie *STDERR or croak "Unable to untie";
-like($msg,
-    qr|^usage: tools/build/ops2pm\.pl \[--help\] \[--no-lines\] input\.ops 
\[input2\.ops \.\.\.\]|,
-    "Got expected usage message");
+my $cwd = cwd();
+my ($msg, $tie, @lines);
+{
+    $tie = tie *STDERR, "Capture" or croak "Unable to tie";
+    Usage();
+    $msg = $tie->READLINE;
+    untie *STDERR or croak "Unable to untie";
+    like($msg,
+        qr|^usage: tools/build/ops2pm\.pl \[--help\] \[--no-lines\] input\.ops 
\[input2\.ops \.\.\.\]|,
+        "Got expected usage message");
+}
+
+{
+    local @ARGV = qw( --no-lines );
+    my $flagsref = getoptions();
+    ok($flagsref->{nolines}, "no-lines option detected");
+    ok(! defined $flagsref->{help}, "help option not defined");
+    ok(! defined $flagsref->{renum}, "renum option not defined");
+}
+
+{
+    local @ARGV = ();
+    my $flagsref = getoptions();
+    ok(! defined $flagsref->{nolines}, "no-lines option not defined");
+    ok(! defined $flagsref->{help}, "help option not defined");
+    ok(! defined $flagsref->{renum}, "renum option not defined");
+}
+
+{
+    local @ARGV = qw( --no-lines --help --renum );
+    my $flagsref = getoptions();
+    ok($flagsref->{nolines}, "no-lines option detected");
+    ok($flagsref->{help}, "help option detected");
+    ok($flagsref->{renum}, "renum option detected");
+}
 
 pass("Completed all tests in $0");
 
@@ -83,4 +92,3 @@
 Parrot::Ops2pm::Utils, F<ops2pm.pl>.
 
 =cut
-

Reply via email to