tagged release 0.6.4
[parrot.git] / t / tools / ops2pmutils / 02-usage.t
blobca66c16fee5c372014e16b652ce69f5a17e10094
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 02-usage.t
6 use strict;
7 use warnings;
9 BEGIN {
10     use FindBin qw($Bin);
11     use Cwd qw(cwd realpath);
12     realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
13     our $topdir = $1;
14     if ( defined $topdir ) {
15         print "\nOK:  Parrot top directory located\n";
16     }
17     else {
18         $topdir = realpath($Bin) . "/../../..";
19     }
20     unshift @INC, qq{$topdir/lib};
22 use Test::More tests => 13;
23 use Carp;
24 use Cwd;
25 use IO::CaptureOutput qw| capture |;
26 use_ok( 'Parrot::Ops2pm::Auxiliary', qw| Usage getoptions | );
28 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
29 my $cwd = cwd();
31     my ($stdout, $stderr);
32     my $ret = capture(
33         sub { Usage(); },
34         \$stdout,
35         \$stderr
36     );
37     like(
38         $stderr,
39 qr|^usage: tools/build/ops2pm\.pl \[--help\] \[--no-lines\] input\.ops \[input2\.ops \.\.\.\]|,
40         "Got expected usage message"
41     );
45     local @ARGV = qw( --no-lines );
46     my $flagsref = getoptions();
47     ok( $flagsref->{nolines},        "no-lines option detected" );
48     ok( !defined $flagsref->{help},  "help option not defined" );
49     ok( !defined $flagsref->{renum}, "renum option not defined" );
53     local @ARGV = ();
54     my $flagsref = getoptions();
55     ok( !defined $flagsref->{nolines}, "no-lines option not defined" );
56     ok( !defined $flagsref->{help},    "help option not defined" );
57     ok( !defined $flagsref->{renum},   "renum option not defined" );
61     local @ARGV = qw( --no-lines --help --renum );
62     my $flagsref = getoptions();
63     ok( $flagsref->{nolines}, "no-lines option detected" );
64     ok( $flagsref->{help},    "help option detected" );
65     ok( $flagsref->{renum},   "renum option detected" );
68 pass("Completed all tests in $0");
70 ################### DOCUMENTATION ###################
72 =head1 NAME
74 02-usage.t - test C<Parrot::Ops2pm::Utils::Usage()>
76 =head1 SYNOPSIS
78     % prove t/tools/ops2pmutils/02-usage.t
80 =head1 DESCRIPTION
82 The files in this directory test the publicly callable subroutines of
83 F<lib/Parrot/Ops2pm/Utils.pm> and F<lib/Parrot/Ops2pm/Auxiliary.pm>.
84 By doing so, they test the functionality of the F<ops2pm.pl> utility.
85 That functionality has largely been extracted
86 into the methods of F<Utils.pm>.
88 F<02-usage.t> tests whether C<Parrot::Ops2pm::Auxiliary::Usage()>
89 works properly.
91 =head1 AUTHOR
93 James E Keenan
95 =head1 SEE ALSO
97 Parrot::Ops2pm::Auxiliary, F<ops2pm.pl>.
99 =cut
101 # Local Variables:
102 #   mode: cperl
103 #   cperl-indent-level: 4
104 #   fill-column: 100
105 # End:
106 # vim: expandtab shiftwidth=4: