3 #=======================================================================
5 # File ID: 3c8499a2-394c-11e5-b0e5-fefdb24f8e10
7 # Test suite for txt2uc(1).
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
19 use Test
::More
qw{no_plan
};
28 our $CMD = "../$CMDB";
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0';
45 my %descriptions = ();
47 Getopt
::Long
::Configure
('bundling');
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'}) {
71 my $ucfile = "$ENV{'HOME'}/.unichar.sqlite";
73 diag
(sprintf('========== Executing %s v%s ==========',
74 $progname, $VERSION));
76 if ($Opt{'todo'} && !$Opt{'all'}) {
82 testcmd("$CMD command", # {{{
95 diag
('Testing -h (--help) option...');
96 likecmd
("$CMD -h", # {{{
100 'Option -h prints help screen',
104 diag
('Testing -v (--verbose) option...');
105 likecmd
("$CMD -h -v", # {{{
106 '/^\n\S+ \d+\.\d+\.\d+/s',
109 'Option -v with -h returns version number and help screen',
113 diag
('Testing --version option...');
114 likecmd
("$CMD --version", # {{{
115 '/^\S+ \d+\.\d+\.\d+/',
118 'Option --version returns version number',
123 diag
("$ucfile not found, skipping tests");
126 testcmd
("echo -n Boring. | $CMD", # {{{
128 0042;LATIN CAPITAL LETTER B;Lu;0;L;;;;;N;;;;0062;
129 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
130 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
131 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
132 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
133 0067;LATIN SMALL LETTER G;Ll;0;L;;;;;N;;;0047;;0047
134 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
142 testcmd
("echo Rock on. 🤘 | $CMD", # {{{
144 0052;LATIN CAPITAL LETTER R;Lu;0;L;;;;;N;;;;0072;
145 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
146 0063;LATIN SMALL LETTER C;Ll;0;L;;;;;N;;;0043;;0043
147 006B;LATIN SMALL LETTER K;Ll;0;L;;;;;N;;;004B;;004B
148 0020;SPACE;Zs;0;WS;;;;;N;;;;;
149 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
150 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
151 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
152 0020;SPACE;Zs;0;WS;;;;;N;;;;;
153 1F918;SIGN OF THE HORNS;So;0;ON;;;;;N;;;;;
154 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
158 'Use char from Unicode 8.0',
162 testcmd
("echo 🥓 FTW 🕺 | $CMD", # {{{
164 1F953;BACON;So;0;ON;;;;;N;;;;;
165 0020;SPACE;Zs;0;WS;;;;;N;;;;;
166 0046;LATIN CAPITAL LETTER F;Lu;0;L;;;;;N;;;;0066;
167 0054;LATIN CAPITAL LETTER T;Lu;0;L;;;;;N;;;;0074;
168 0057;LATIN CAPITAL LETTER W;Lu;0;L;;;;;N;;;;0077;
169 0020;SPACE;Zs;0;WS;;;;;N;;;;;
170 1F57A;MAN DANCING;So;0;ON;;;;;N;;;;;
171 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
175 'Use chars from Unicode 9.0',
179 testcmd
("echo The 🧟 wants 🧠, not 🥟 or ₿ | $CMD", # {{{
181 0054;LATIN CAPITAL LETTER T;Lu;0;L;;;;;N;;;;0074;
182 0068;LATIN SMALL LETTER H;Ll;0;L;;;;;N;;;0048;;0048
183 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
184 0020;SPACE;Zs;0;WS;;;;;N;;;;;
185 1F9DF;ZOMBIE;So;0;ON;;;;;N;;;;;
186 0020;SPACE;Zs;0;WS;;;;;N;;;;;
187 0077;LATIN SMALL LETTER W;Ll;0;L;;;;;N;;;0057;;0057
188 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
189 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
190 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
191 0073;LATIN SMALL LETTER S;Ll;0;L;;;;;N;;;0053;;0053
192 0020;SPACE;Zs;0;WS;;;;;N;;;;;
193 1F9E0;BRAIN;So;0;ON;;;;;N;;;;;
194 002C;COMMA;Po;0;CS;;;;;N;;;;;
195 0020;SPACE;Zs;0;WS;;;;;N;;;;;
196 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
197 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
198 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
199 0020;SPACE;Zs;0;WS;;;;;N;;;;;
200 1F95F;DUMPLING;So;0;ON;;;;;N;;;;;
201 0020;SPACE;Zs;0;WS;;;;;N;;;;;
202 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
203 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
204 0020;SPACE;Zs;0;WS;;;;;N;;;;;
205 20BF;BITCOIN SIGN;Sc;0;ET;;;;;N;;;;;
206 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
210 'Use chars from Unicode 10.0',
214 testcmd
("echo U̲l̲i̲n̲e̲ and s̶t̶r̶i̶k̶e̶. | $CMD", # {{{
216 0055;LATIN CAPITAL LETTER U;Lu;0;L;;;;;N;;;;0075;
217 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
218 006C;LATIN SMALL LETTER L;Ll;0;L;;;;;N;;;004C;;004C
219 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
220 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
221 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
222 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
223 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
224 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
225 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
226 0020;SPACE;Zs;0;WS;;;;;N;;;;;
227 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
228 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
229 0064;LATIN SMALL LETTER D;Ll;0;L;;;;;N;;;0044;;0044
230 0020;SPACE;Zs;0;WS;;;;;N;;;;;
231 0073;LATIN SMALL LETTER S;Ll;0;L;;;;;N;;;0053;;0053
232 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
233 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
234 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
235 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
236 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
237 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
238 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
239 006B;LATIN SMALL LETTER K;Ll;0;L;;;;;N;;;004B;;004B
240 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
241 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
242 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
243 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
244 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
248 'Display combining chars',
252 testcmd
("echo feff 48 61 74 65 2e | fromhex -u | $CMD", # {{{
254 FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
255 0048;LATIN CAPITAL LETTER H;Lu;0;L;;;;;N;;;;0068;
256 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
257 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
258 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
259 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
263 'Display bloody BOM',
271 if ($Opt{'all'} || $Opt{'todo'}) {
272 diag
('Running TODO tests...'); # {{{
277 # Insert TODO tests here.
283 diag
('Testing finished.');
290 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
291 defined($descriptions{$Desc}) &&
292 BAIL_OUT
("testcmd(): '$Desc' description is used twice");
293 $descriptions{$Desc} = 1;
295 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
296 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
297 my $TMP_STDERR = "$CMDB-stderr.tmp";
300 if (defined($Exp_stderr)) {
301 $stderr_cmd = " 2>$TMP_STDERR";
303 $retval &= is
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
305 if (defined($Exp_stderr)) {
306 $retval &= is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
309 diag
("Warning: stderr not defined for '$Txt'");
311 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
319 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
320 defined($descriptions{$Desc}) &&
321 BAIL_OUT
("likecmd(): '$Desc' description is used twice");
322 $descriptions{$Desc} = 1;
324 my $cmd_outp_str = $Opt{'verbose'} >= 1 ?
"\"$Cmd\" - " : '';
325 my $Txt = join('', $cmd_outp_str, defined($Desc) ?
$Desc : '');
326 my $TMP_STDERR = "$CMDB-stderr.tmp";
329 if (defined($Exp_stderr)) {
330 $stderr_cmd = " 2>$TMP_STDERR";
332 $retval &= like
(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
334 if (defined($Exp_stderr)) {
335 $retval &= like
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
338 diag
("Warning: stderr not defined for '$Txt'");
340 $retval &= is
($ret_val >> 8, $Exp_retval, "$Txt (retval)");
347 # Return file content as a string {{{
351 open(my $fp, '<', $File) or return undef;
360 # Print program version {{{
361 print("$progname $VERSION\n");
367 # Send the help message to stdout {{{
370 if ($Opt{'verbose'}) {
376 Usage: $progname [options]
378 Contains tests for the $CMDB(1) program.
383 Run all tests, also TODOs.
387 Be more quiet. Can be repeated to increase silence.
389 Run only the TODO tests.
391 Increase level of verbosity. Can be repeated.
393 Print version information.
401 # Print a status message to stderr based on verbosity level {{{
402 my ($verbose_level, $Txt) = @_;
404 $verbose_level > $Opt{'verbose'} && return;
405 print(STDERR
"$progname: $Txt\n");
412 # This program is free software; you can redistribute it and/or modify
413 # it under the terms of the GNU General Public License as published by
414 # the Free Software Foundation; either version 2 of the License, or (at
415 # your option) any later version.
417 # This program is distributed in the hope that it will be useful, but
418 # WITHOUT ANY WARRANTY; without even the implied warranty of
419 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
420 # See the GNU General Public License for more details.
422 # You should have received a copy of the GNU General Public License
423 # along with this program.
424 # If not, see L<http://www.gnu.org/licenses/>.
426 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :