File: getopt.t

package info (click to toggle)
libappconfig-std-perl 1.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 303; makefile: 2
file content (139 lines) | stat: -rwxr-xr-x 2,778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!./perl
#
# basic.t - tests for getopt() method of AppConfig::Std
#
# the tests all use getscript.pl
#

my @expected;
my $e = '';
my $args = '';
my $output;

while (<DATA>)
{
    if (/^ARGS:(.*)$/) {
        $args = $1;
    }
    elsif (/^####$/) {
        push(@expected, [$args, $e]);
        $args = '';
        $e = '';
    }
    else {
        $e .= $_;
    }
}

print "1..", int(@expected), "\n";


for ($i = 1; $i <= int(@expected); ++$i)
{
    $args = $expected[$i-1]->[0];
    $output = `$^X -Iblib/lib t/getscript.pl $args 2>&1`;
    if ($output eq $expected[$i-1]->[1]) {
        print "ok $i\n";
    }
    else {
        print STDERR "OUTPUT:\n$output\nEXPECTED:\n", $expected[$i-1]->[1], "\n";
        print "not ok $i\n";
    }
}

exit 0;

__DATA__
ARGS:
Start of getscript.pl [AppConfig::Std 1.10]
End of getscript.pl
####
ARGS: -version
Start of getscript.pl [AppConfig::Std 1.10]
1.0
####
ARGS: -verbose
Start of getscript.pl [AppConfig::Std 1.10]
Verbose output enabled
End of getscript.pl
####
ARGS: -debug
Start of getscript.pl [AppConfig::Std 1.10]
Debug output enabled
End of getscript.pl
####
ARGS: -verbose -debug
Start of getscript.pl [AppConfig::Std 1.10]
Verbose output enabled
Debug output enabled
End of getscript.pl
####
ARGS: -foobar
Start of getscript.pl [AppConfig::Std 1.10]
Foobar flag ON
End of getscript.pl
####
ARGS: -foobar -verbose -debug
Start of getscript.pl [AppConfig::Std 1.10]
Verbose output enabled
Debug output enabled
Foobar flag ON
End of getscript.pl
####
ARGS: -color red
Start of getscript.pl [AppConfig::Std 1.10]
A color of red was given
End of getscript.pl
####
ARGS: -color
Start of getscript.pl [AppConfig::Std 1.10]
Option color requires an argument
End of getscript.pl
####
ARGS: -color blue -foobar -verbose -debug
Start of getscript.pl [AppConfig::Std 1.10]
Verbose output enabled
Debug output enabled
Foobar flag ON
A color of blue was given
End of getscript.pl
####
ARGS: -country
Start of getscript.pl [AppConfig::Std 1.10]
Option country requires an argument
End of getscript.pl
####
ARGS: -country Sweden
Start of getscript.pl [AppConfig::Std 1.10]
The country was set to Sweden.
End of getscript.pl
####
ARGS: -help
Start of getscript.pl [AppConfig::Std 1.10]
Usage:
      getscript.pl [ -version | -debug | -verbose | -doc | -help ]
                    [ -color C | -country C | -foobar ]

Options:
    -color C
        Provide a color.

    -country C
        Specify a country.

    -foobar
        Turn on the foobar flag.

    -doc
        Display the full documentation for getscript.pl.

    -verbose or -v
        Display verbose information as getscript.pl runs.

    -version
        Display the version of getscript.pl.

    -debug
        Display debugging information as getscript.pl runs.

####