Upgrade yt-dlp from version stable@2024.10.07 to stable@2024.12.13
[sunny256-utils.git] / Lib / std / perl-tests-tab
blob78ea648610efc245f530cf96a1e4b6ac11edc002
1 #!/usr/bin/env perl
3 #==============================================================================
4 # STDfilenameDTS
5 # File ID: STDuuidDTS
7 # Test suite for STDprognameDTS(1).
9 # Character set: UTF-8
10 # ©opyleft STDyearDTS– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of file for
12 # legal stuff.
13 #==============================================================================
15 use strict;
16 use warnings;
18 BEGIN {
19 use Test::More qw{no_plan};
20 # use_ok() goes here
23 use Getopt::Long;
25 local $| = 1;
27 our $CMDB = "STDprognameDTS";
28 our $CMD = "../$CMDB";
30 our %Opt = (
32 'all' => 0,
33 'help' => 0,
34 'quiet' => 0,
35 'todo' => 0,
36 'verbose' => 0,
37 'version' => 0,
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0'; # Not used here, $CMD decides
45 my %descriptions = ();
47 Getopt::Long::Configure('bundling');
48 GetOptions(
50 'all|a' => \$Opt{'all'},
51 'help|h' => \$Opt{'help'},
52 'quiet|q+' => \$Opt{'quiet'},
53 'todo|t' => \$Opt{'todo'},
54 'verbose|v+' => \$Opt{'verbose'},
55 'version' => \$Opt{'version'},
57 ) || die("$progname: Option error. Use -h for help.\n");
59 $Opt{'verbose'} -= $Opt{'quiet'};
60 $Opt{'help'} && usage(0);
61 if ($Opt{'version'}) {
62 print_version();
63 exit(0);
66 my $exec_version = `$CMD --version`;
68 exit(main());
70 sub main {
71 my $Retval = 0;
73 diag('========== BEGIN version info ==========');
74 diag($exec_version);
75 diag('=========== END version info ===========');
77 if ($Opt{'todo'} && !$Opt{'all'}) {
78 goto todo_section;
81 test_standard_options();
82 test_executable();
84 diag('========== BEGIN version info ==========');
85 diag($exec_version);
86 diag('=========== END version info ===========');
88 todo_section:
91 if ($Opt{'all'} || $Opt{'todo'}) {
92 diag('Running TODO tests...');
93 TODO: {
94 local $TODO = '';
95 # Insert TODO tests here.
99 diag('Testing finished.');
101 return $Retval;
104 sub test_standard_options {
105 diag('Testing -h (--help) option...');
106 likecmd("$CMD -h",
107 '/ Show this help/i',
108 '/^$/',
110 'Option -h prints help screen');
112 diag('Testing -v (--verbose) option...');
113 likecmd("$CMD -hv",
114 '/^\n\S+ \d+\.\d+\.\d+/s',
115 '/^$/',
117 'Option -v with -h returns version number and help screen');
119 diag('Testing --version option...');
120 likecmd("$CMD --version",
121 '/^\S+ \d+\.\d+\.\d+/',
122 '/^$/',
124 'Option --version returns version number');
126 return;
129 sub test_executable {
130 return;
133 sub testcmd {
134 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
135 defined($descriptions{$Desc})
136 && BAIL_OUT("testcmd(): '$Desc' description is used twice");
137 $descriptions{$Desc} = 1;
138 my $stderr_cmd = '';
139 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
140 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
141 my $TMP_STDERR = "$CMDB-stderr.tmp";
142 my $retval = 1;
144 if (defined($Exp_stderr)) {
145 $stderr_cmd = " 2>$TMP_STDERR";
147 $retval &= is(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
148 my $ret_val = $?;
149 if (defined($Exp_stderr)) {
150 $retval &= is(file_data($TMP_STDERR),
151 $Exp_stderr, "$Txt (stderr)");
152 unlink($TMP_STDERR);
153 } else {
154 diag("Warning: stderr not defined for '$Txt'");
156 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
158 return $retval;
161 sub likecmd {
162 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
163 defined($descriptions{$Desc})
164 && BAIL_OUT("likecmd(): '$Desc' description is used twice");
165 $descriptions{$Desc} = 1;
166 my $stderr_cmd = '';
167 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
168 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
169 my $TMP_STDERR = "$CMDB-stderr.tmp";
170 my $retval = 1;
172 if (defined($Exp_stderr)) {
173 $stderr_cmd = " 2>$TMP_STDERR";
175 $retval &= like(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
176 my $ret_val = $?;
177 if (defined($Exp_stderr)) {
178 $retval &= like(file_data($TMP_STDERR),
179 $Exp_stderr, "$Txt (stderr)");
180 unlink($TMP_STDERR);
181 } else {
182 diag("Warning: stderr not defined for '$Txt'");
184 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
186 return $retval;
189 sub file_data {
190 # Return file content as a string
191 my $File = shift;
192 my $Txt;
194 open(my $fp, '<', $File) or return undef;
195 local $/ = undef;
196 $Txt = <$fp>;
197 close($fp);
199 return $Txt;
202 sub create_file {
203 # Create new file and fill it with data
204 my ($file, $text) = @_;
205 my $retval = 0;
207 open(my $fp, ">", $file) or return 0;
208 print($fp $text);
209 close($fp);
210 $retval = is(file_data($file), $text,
211 "$file was successfully created");
213 return $retval; # 0 if error, 1 if ok
216 sub print_version {
217 # Print program version
218 print("$progname $VERSION\n");
220 return;
223 sub usage {
224 # Send the help message to stdout
225 my $Retval = shift;
227 if ($Opt{'verbose'}) {
228 print("\n");
229 print_version();
231 print(<<"END");
233 Usage: $progname [options]
235 Contains tests for the $CMDB(1) program.
237 Options:
239 -a, --all
240 Run all tests, also TODOs.
241 -h, --help
242 Show this help.
243 -q, --quiet
244 Be more quiet. Can be repeated to increase silence.
245 -t, --todo
246 Run only the TODO tests.
247 -v, --verbose
248 Increase level of verbosity. Can be repeated.
249 --version
250 Print version information.
253 exit($Retval);
256 sub msg {
257 # Print a status message to stderr based on verbosity level
258 my ($verbose_level, $Txt) = @_;
260 $verbose_level > $Opt{'verbose'} && return;
261 print(STDERR "$progname: $Txt\n");
263 return;
266 __END__
268 # This program is free software; you can redistribute it and/or modify it under
269 # the terms of the GNU General Public License as published by the Free Software
270 # Foundation; either version 2 of the License, or (at your option) any later
271 # version.
273 # This program is distributed in the hope that it will be useful, but WITHOUT
274 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
275 # FOR A PARTICULAR PURPOSE.
276 # See the GNU General Public License for more details.
278 # You should have received a copy of the GNU General Public License along with
279 # this program.
280 # If not, see L<http://www.gnu.org/licenses/>.
282 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :