Replaced the messy GNU-styled, multi-lingual documents with a single Markdown README.md. Added the GitHub repository to the document and removed the SourceForge website, my web page, and the SourceForge mailing list from the document. Removed the document license, and my PGP key from the package. Removed the signature file from the repository. Changed the license from GPLv3 to APLv2. Various fixes to avoid JetBrains IDE problem detection.

This commit is contained in:
2021-02-06 19:37:28 +08:00
parent 09e7f61f52
commit 9b06296eb5
39 changed files with 1707 additions and 4744 deletions

View File

@ -1,17 +1,23 @@
#!/usr/bin/perl
use strict;
print "1..1\n";
if (!-s 'SIGNATURE') {
if (!$ENV{TEST_SIGNATURE}) {
print "ok 1 # skip Set the environment variable",
" TEST_SIGNATURE to enable this test\n";
}
elsif (!-s 'SIGNATURE') {
print "ok 1 # skip No signature file found\n";
}
elsif (!eval { require Module::Signature; 1 }) {
print "ok 1 # skip ",
"Next time around, consider install Module::Signature, ",
"so you can verify the integrity of this distribution.\n";
"Next time around, consider install Module::Signature, ",
"so you can verify the integrity of this distribution.\n";
}
elsif (!eval { require Socket; Socket::inet_aton('pgp.mit.edu') }) {
print "ok 1 # skip Cannot connect to the keyserver\n";
elsif (!eval { require Socket; Socket::inet_aton('pool.sks-keyservers.net') }) {
print "ok 1 # skip ",
"Cannot connect to the keyserver\n";
}
else {
(Module::Signature::verify() == Module::Signature::SIGNATURE_OK())

View File

@ -1,20 +1,19 @@
#! /usr/bin/perl -w
# Test all the possible combination of options
# Copyright (c) 2005-2007 imacat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (c) 2005-2021 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is combined from 01-plain.t, 02-gzip.t and 03-bzip2.t.
@ -32,99 +31,99 @@ use File::Spec::Functions qw(catdir catfile updir devnull);
use FindBin;
use lib $FindBin::Bin;
use _helper;
use vars qw($WORKDIR $tno $reslog);
our ($WORKDIR, $tno, $reslog);
$WORKDIR = catdir($FindBin::Bin, "logs");
$tno = 0;
$reslog = catfile($FindBin::Bin, updir, "blib", "script", "reslog");
# Test each source log file type
foreach my $st (@SRCTYPES) {
foreach my $st (@SOURCE_TYPES) {
# Test each source file content type
foreach my $sct (@CNTTYPES) {
# Test each keep type
foreach my $kt (@KEEPTYPES) {
# Test each override type
foreach my $ot (@OVERTYPES) {
foreach my $sct (@CONTENT_TYPES) {
# Test each keep mode
foreach my $keep (@KEEP_MODES) {
# Test each override mode
foreach my $override (@OVERRIDE_MODES) {
# Test each existing file content type
my @ecnttypes;
if (!$$ot{"mkex"}) {
if (!$$override{"exists"}) {
# Existing file content type is meaningless
# if there is no existing file.
@ecnttypes = (1);
} else {
# mkrndlog_noip() does not make a difference than
# mkrndlog_normal() as an existing file.
@ecnttypes = grep $$_{"title"} ne "log file without IP",
@CNTTYPES;
# make_resolved_log_file() does not make a difference than
# make_log_file() as an existing file.
@ecnttypes = grep $$_{"title"} ne "resolved log file",
@CONTENT_TYPES;
}
foreach my $ect (@ecnttypes) {
# Test each suffix type
foreach my $suft (@SUFTYPES) {
foreach my $suffix (@SUFFICES) {
# Test each trim-suffix type
foreach my $tsuft (@TSUFTYPES) {
foreach my $trim_suffix (@TRIM_SUFFIX) {
$_ = eval {
return if $$st{"skip"};
my ($title, $cmd, $retno, $out, $err, $logfile);
my ($title, $cmd, $ret_no, $out, $err, $logfile);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $fo, $cs, $csr, $co, $suf, $tsuf);
my ($fs, $fo, $cs, $csr, $co, $suf, $trim_suf);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", $$st{"title"}, $$sct{"title"},
$$kt{"title"}, $$ot{"title"},
$$suft{"title"}, $$tsuft{"title"};
$logfile = randword;
$suf = defined $$suft{"suf"}? $$suft{"suf"}: "." . randword;
if (defined $$tsuft{"suf"}) {
$tsuf = $$tsuft{"suf"};
$$keep{"title"}, $$override{"title"},
$$suffix{"title"}, $$trim_suffix{"title"};
$logfile = random_word;
$suf = defined $$suffix{"suf"}? $$suffix{"suf"}: "." . random_word;
if (defined $$trim_suffix{"suf"}) {
$trim_suf = $$trim_suffix{"suf"};
} else {
do { $tsuf = "." . randword; } until $tsuf ne $suf;
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
}
$fs = catfile($WORKDIR, "$logfile$tsuf" . $$st{"suf"});
$fs = catfile($WORKDIR, "$logfile$trim_suf" . $$st{"suf"});
($cs, $csr) = &{$$sct{"sub"}}($fs);
if ($$ot{"mkex"}) {
if ($$override{"exists"}) {
$fo = catfile($WORKDIR, "$logfile$suf" . $$st{"suf"});
$co = (&{$$ect{"sub"}}($fo))[0];
}
@fle = qw();
push @fle, basename($fs) if !($$ot{"ok"} && $$kt{"del"});
if ($$ot{"ok"}) {
push @fle, basename($fs) if !($$override{"ok"} && $$keep{"del"});
if ($$override{"ok"}) {
push @fle, "$logfile$suf" . $$st{"suf"};
} else {
push @fle, basename($fo) if !$$kt{"del"} || $$ot{"mkex"};
push @fle, basename($fo) if !$$keep{"del"} || $$override{"exists"};
}
prsrvsrc $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1), @{$$kt{"opts"}},
@{$$ot{"opts"}}, &{$$suft{"opts"}}($suf),
&{$$tsuft{"opts"}}($tsuf), $fs);
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1), @{$$keep{"opts"}},
@{$$override{"opts"}}, &{$$suffix{"opts"}}($suf),
&{$$trim_suffix{"opts"}}($trim_suf), $fs);
$cmd = join " ", @_;
($retno, $out, $err) = runcmd "", @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
%trf = qw(); # Resulted file type by file
if (!($$ot{"ok"} && $$kt{"del"})) {
if (!($$override{"ok"} && $$keep{"del"})) {
$fr = $fs;
$frb = basename($fr);
$cef{$frb} = $$kt{"keep"} || !$$ot{"ok"}? $cs: "";
$cef{$frb} = $$keep{"keep"} || !$$override{"ok"}? $cs: "";
$tef{$frb} = $$st{"type"};
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
if ($$ot{"ok"} || $$ot{"mkex"}) {
if ($$override{"ok"} || $$override{"exists"}) {
$frb = "$logfile$suf" . $$st{"suf"};
$fr = catfile($WORKDIR, $frb);
$cef{$frb} = &{$$ot{"ce"}}($co, $csr);
$cef{$frb} = &{$$override{"ce"}}($co, $csr);
$tef{$frb} = $$st{"type"};
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
die "$title\n$cmd\n$out$err"
unless $$ot{"ok"}? $retno == 0: $retno != 0;
unless $$override{"ok"}? $ret_no == 0: $ret_no != 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr}
unless has_no_file || $trf{$fr} eq $tef{$fr}
|| ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr));
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
@ -132,57 +131,57 @@ foreach my $st (@SRCTYPES) {
1;
};
skip($$st{"skip"}, $_, 1, $@);
cleanup $_ || $$st{"skip"}, $WORKDIR, ++$tno;
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
die unless $_ || $$st{"skip"};
}
}
}
}
# 37: From file to STDOUT
$_ = eval {
return if $$st{"skip"};
my ($title, $cmd, $retno, $out, $err, $logfile, $result);
my ($title, $cmd, $ret_no, $out, $err, $logfile, $result);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $fo, $cs, $csr, $co);
my ($fs, $cs, $csr);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "From file to STDOUT", $$sct{"title"},
$$st{"title"}, $$kt{"title"};
$logfile = randword;
do { $result = randword; } until $result ne $logfile;
$$st{"title"}, $$keep{"title"};
$logfile = random_word;
do { $result = random_word; } until $result ne $logfile;
$fs = catfile($WORKDIR, "$logfile" . $$st{"suf"});
($cs, $csr) = &{$$sct{"sub"}}($fs);
@fle = qw();
push @fle, basename($fs) if !$$kt{"cdel"};
push @fle, basename($fs) if !$$keep{"cdel"};
push @fle, $result . $$st{"suf"};
prsrvsrc $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1 -c), @{$$kt{"opts"}}, $fs);
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1 -c), @{$$keep{"opts"}}, $fs);
$cmd = join " ", @_;
($retno, $out, $err) = runcmd "", @_;
frwrite(catfile($WORKDIR, $result . $$st{"suf"}), $out);
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
write_raw_file(catfile($WORKDIR, $result . $$st{"suf"}), $out);
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
%trf = qw(); # Resulted file type by file
if (!$$kt{"cdel"}) {
if (!$$keep{"cdel"}) {
$fr = $fs;
$frb = basename($fr);
$cef{$frb} = $$kt{"ckeep"}? $cs: "";
$cef{$frb} = $$keep{"ckeep"}? $cs: "";
$tef{$frb} = $$st{"type"};
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
$frb = $result . $$st{"suf"};
$fr = catfile($WORKDIR, $frb);
($cef{$frb}, $tef{$frb}) = ($csr, $$st{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno == 0;
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
die "$title\n$cmd\n$out$err" unless $ret_no == 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr}
unless has_no_file || $trf{$fr} eq $tef{$fr}
|| ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr));
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
@ -190,33 +189,33 @@ foreach my $st (@SRCTYPES) {
1;
};
skip($$st{"skip"}, $_, 1, $@);
cleanup $_ || $$st{"skip"}, $WORKDIR, ++$tno;
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
die unless $_ || $$st{"skip"};
}
# 85: From STDIN to STDOUT
$_ = eval {
return if $$st{"skip"};
my ($title, $cmd, $retno, $out, $err, $logfile, $result);
my ($title, $cmd, $ret_no, $out, $err, $logfile, $result);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $fo, $cs, $csr, $co);
my ($fs, $cs, $csr);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "From STDIN to STDOUT", $$sct{"title"},
$$st{"title"};
$logfile = randword;
do { $result = randword; } until $result ne $logfile;
$logfile = random_word;
do { $result = random_word; } until $result ne $logfile;
$fs = catfile($WORKDIR, "$logfile" . $$st{"suf"});
($cs, $csr) = &{$$sct{"sub"}}($fs);
@fle = qw();
push @fle, basename($fs);
push @fle, $result . $$st{"suf"};
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1));
$cmd = join(" ", @_) . " < $fs";
($retno, $out, $err) = runcmd frread $fs, @_;
frwrite(catfile($WORKDIR, $result . $$st{"suf"}), $out);
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd read_raw_file $fs, @_;
write_raw_file(catfile($WORKDIR, $result . $$st{"suf"}), $out);
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -225,17 +224,17 @@ foreach my $st (@SRCTYPES) {
$frb = basename($fr);
$cef{$frb} = $cs;
$tef{$frb} = $$st{"type"};
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
$frb = $result . $$st{"suf"};
$fr = catfile($WORKDIR, $frb);
($cef{$frb}, $tef{$frb}) = ($csr, $$st{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno == 0;
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
die "$title\n$cmd\n$out$err" unless $ret_no == 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr}
unless has_no_file || $trf{$fr} eq $tef{$fr}
|| ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr));
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
@ -243,7 +242,7 @@ foreach my $st (@SRCTYPES) {
1;
};
skip($$st{"skip"}, $_, 1, $@);
cleanup $_ || $$st{"skip"}, $WORKDIR, ++$tno;
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
die unless $_ || $$st{"skip"};
}
}

View File

@ -1,20 +1,19 @@
#! /usr/bin/perl -w
# Test processing several log files at once
# Copyright (c) 2007 imacat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (c) 2007-2021 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file replaces 04-hybrix.t.
@ -32,7 +31,7 @@ use File::Spec::Functions qw(catdir catfile updir);
use FindBin;
use lib $FindBin::Bin;
use _helper;
use vars qw($WORKDIR $tno $reslog);
our ($WORKDIR, $tno, $reslog);
$WORKDIR = catdir($FindBin::Bin, "logs");
$tno = 0;
@ -40,35 +39,35 @@ $reslog = catfile($FindBin::Bin, updir, "blib", "script", "reslog");
# 1: Source log files listed as the arguments
$_ = eval {
my ($title, $cmd, $retno, $out, $err, %logfiles);
my ($title, $cmd, $ret_no, $out, $err, %logfiles);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $tsuf);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $trim_suf);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "several log files", "all listed as arguments";
$suf = "." . randword;
do { $tsuf = "." . randword; } until $tsuf ne $suf;
$suf = "." . random_word;
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
# (2-4 times available compression) log files
$_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2);
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2);
$num = $_ + int rand $_;
%_ = qw();
my %types = qw();
# At least 2 files for each available compression
foreach my $st (@SRCTYPES) {
next if ($$st{"type"} eq TYPE_GZIP && nogzip)
|| ($$st{"type"} eq TYPE_BZIP2 && nobzip2);
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
foreach my $st (@SOURCE_TYPES) {
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2);
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
}
# Set random compression on the rest files
foreach (grep !exists $_{$_}, (0...$num-1)) {
foreach (grep !exists $types{$_}, (0...$num-1)) {
do {
$_{$_} = $SRCTYPES[int rand @SRCTYPES];
} until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip)
&& !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2);
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2);
}
@st = map $_{$_}, (0...$num-1);
@st = map $types{$_}, (0...$num-1);
@fs = qw();
@fo = qw();
@cs = qw();
@ -78,27 +77,27 @@ $_ = eval {
%logfiles = qw();
for (my $k = 0; $k < $num; $k++) {
my ($logfile, $cs, $csr, $co);
do { $logfile = randword } until !exists $logfiles{$logfile};
do { $logfile = random_word } until !exists $logfiles{$logfile};
$logfiles{$logfile} = 1;
push @fs, catfile($WORKDIR, "$logfile$tsuf" . ${$st[$k]}{"suf"});
push @fs, catfile($WORKDIR, "$logfile$trim_suf" . ${$st[$k]}{"suf"});
push @fo, catfile($WORKDIR, "$logfile$suf" . ${$st[$k]}{"suf"});
($cs, $csr) = mkrndlog_normal $fs[$k];
($cs, $csr) = make_log_file $fs[$k];
push @cs, $cs;
push @csr, $csr;
push @fle, basename($fo[$k]);
# 1: create existing file, 0: no existing file
if (int rand 1) {
$co = (mkrndlog_normal $fo[$k])[0];
$co = (make_log_file $fo[$k])[0];
push @co, $co;
} else {
push @co, "";
}
}
prsrvsrc $WORKDIR;
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $tsuf, @fs);
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $trim_suf, @fs);
$cmd = join(" ", @_);
($retno, $out, $err) = runcmd "", @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -107,66 +106,66 @@ $_ = eval {
$fr = $fo[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($co[$k] . $csr[$k], ${$st[$k]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
die "$title\n$cmd\n$out$err" unless $retno == 0;
die "$title\n$cmd\n$out$err" unless $ret_no == 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr};
unless has_no_file || $trf{$fr} eq $tef{$fr};
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
}
1;
};
ok($_, 1, $@);
cleanup $_, $WORKDIR, ++$tno;
clean_up $_, $WORKDIR, ++$tno;
# 2-4: One of the source log files is read from STDIN
# The file type at STDIN
foreach my $ststdin (@SRCTYPES) {
foreach my $st_stdin (@SOURCE_TYPES) {
my $skip;
$skip = 0;
$_ = eval {
if ( ($$ststdin{"type"} eq TYPE_GZIP && nogzip)
|| ($$ststdin{"type"} eq TYPE_BZIP2 && nobzip2)) {
if ( ($$st_stdin{"type"} eq TYPE_GZIP && has_no_gzip)
|| ($$st_stdin{"type"} eq TYPE_BZIP2 && has_no_bzip2)) {
$skip = 1;
return;
}
my ($title, $cmd, $retno, $out, $err, %logfiles);
my ($title, $cmd, $ret_no, $out, $err, %logfiles);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $tsuf, $stdin);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $trim_suf, $stdin);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "several log files", "one read from STDIN",
"STDIN " . $$ststdin{"title"};
$suf = "." . randword;
do { $tsuf = "." . randword; } until $tsuf ne $suf;
"STDIN " . $$st_stdin{"title"};
$suf = "." . random_word;
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
# (2-4 times available compression) log files
$_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2);
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2);
$num = $_ + int rand $_;
%_ = qw();
my %types = qw();
# At least 2 files for each available compression
foreach my $st (@SRCTYPES) {
next if ($$st{"type"} eq TYPE_GZIP && nogzip)
|| ($$st{"type"} eq TYPE_BZIP2 && nobzip2);
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
foreach my $st (@SOURCE_TYPES) {
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2);
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
}
# Set random compression on the rest files
foreach (grep !exists $_{$_}, (0...$num-1)) {
foreach (grep !exists $types{$_}, (0...$num-1)) {
do {
$_{$_} = $SRCTYPES[int rand @SRCTYPES];
} until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip)
&& !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2);
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2);
}
# Choose the STDIN from the matching compression
@_ = grep ${$_{$_}}{"type"} eq $$ststdin{"type"}, (0...$num-1);
@_ = grep ${$types{$_}}{"type"} eq $$st_stdin{"type"}, (0...$num-1);
$stdin = $_[int rand @_];
@st = map $_{$_}, (0...$num-1);
@st = map $types{$_}, (0...$num-1);
@fs = qw();
@fo = qw();
@cs = qw();
@ -176,37 +175,37 @@ foreach my $ststdin (@SRCTYPES) {
%logfiles = qw();
for (my $k = 0; $k < $num; $k++) {
my ($logfile, $cs, $csr, $co);
do { $logfile = randword } until !exists $logfiles{$logfile};
do { $logfile = random_word } until !exists $logfiles{$logfile};
$logfiles{$logfile} = 1;
push @fs, catfile($WORKDIR, "$logfile$tsuf" . ${$st[$k]}{"suf"});
push @fs, catfile($WORKDIR, "$logfile$trim_suf" . ${$st[$k]}{"suf"});
if ($k == $stdin) {
do { $_ = randword } until !exists $logfiles{$_};
do { $_ = random_word } until !exists $logfiles{$_};
$logfiles{$_} = 1;
push @fo, catfile($WORKDIR, "$_" . ${$st[$k]}{"suf"});
} else {
push @fo, catfile($WORKDIR, "$logfile$suf" . ${$st[$k]}{"suf"});
}
($cs, $csr) = mkrndlog_normal $fs[$k];
($cs, $csr) = make_log_file $fs[$k];
push @cs, $cs;
push @csr, $csr;
push @fle, basename($fs[$k]) if $k == $stdin;
push @fle, basename($fo[$k]);
# 1: create existing file, 0: no existing file
if ($k != $stdin && int rand 1) {
$co = (mkrndlog_normal $fo[$k])[0];
$co = (make_log_file $fo[$k])[0];
push @co, $co;
} else {
push @co, "";
}
}
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
@_ = @fs;
$_[$stdin] = "-";
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $tsuf, @_);
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $trim_suf, @_);
$cmd = join(" ", @_) . " < " . $fs[$stdin];
($retno, $out, $err) = runcmd frread $fs[$stdin], @_;
frwrite($fo[$stdin], $out);
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd read_raw_file $fs[$stdin], @_;
write_raw_file($fo[$stdin], $out);
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -214,25 +213,25 @@ foreach my $ststdin (@SRCTYPES) {
$fr = $fs[$stdin];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs[$stdin], ${$st[$stdin]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
for (my $k = 0; $k < $num; $k++) {
$fr = $fo[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($co[$k] . $csr[$k], ${$st[$k]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
die "$title\n$cmd\n$out$err" unless $retno == 0;
die "$title\n$cmd\n$out$err" unless $ret_no == 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr};
unless has_no_file || $trf{$fr} eq $tef{$fr};
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
}
1;
};
skip($skip, $_, 1, $@);
cleanup $_ || $skip, $WORKDIR, ++$tno;
clean_up $_ || $skip, $WORKDIR, ++$tno;
die if !$_ && !$skip;
}

View File

@ -1,20 +1,19 @@
#! /usr/bin/perl -w
# Test the errors that should be captured.
# Copyright (c) 2007 imacat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (c) 2007-2021 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use 5.005;
use strict;
@ -30,35 +29,35 @@ use File::Spec::Functions qw(catdir catfile updir);
use FindBin;
use lib $FindBin::Bin;
use _helper;
use vars qw($WORKDIR $reslog $tno);
our ($WORKDIR, $reslog, $tno);
$WORKDIR = catdir($FindBin::Bin, "logs");
$reslog = catfile($FindBin::Bin, updir, "blib", "script", "reslog");
$tno = 0;
# 1-6: Trim suffix is the same as suffix
foreach my $st (@SRCTYPES) {
foreach my $st (@SOURCE_TYPES) {
# 1: Trim suffix is the same as suffix
$_ = eval {
return if $$st{"skip"};
my ($title, $cmd, $retno, $out, $err, $logfile);
my ($title, $cmd, $ret_no, $out, $err, $logfile);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $fo, $cs, $csr, $co, $suf);
my ($fs, $cs, $csr, $suf);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "Trim suffix is the same as suffix",
$$st{"title"};
$logfile = randword;
$suf = "." . randword;
$logfile = random_word;
$suf = "." . random_word;
$fs = catfile($WORKDIR, "$logfile" . $$st{"suf"});
($cs, $csr) = mkrndlog_normal $fs;
($cs, $csr) = make_log_file $fs;
@fle = qw();
push @fle, basename($fs);
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1), "-s", $suf, "-t", $suf, $fs);
$cmd = join " ", @_;
($retno, $out, $err) = runcmd "", @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -66,13 +65,13 @@ foreach my $st (@SRCTYPES) {
$fr = $fs;
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs, $$st{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno != 0;
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
die "$title\n$cmd\n$out$err" unless $ret_no != 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr}
unless has_no_file || $trf{$fr} eq $tef{$fr}
|| ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr));
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
@ -80,29 +79,29 @@ foreach my $st (@SRCTYPES) {
1;
};
skip($$st{"skip"}, $_, 1, $@);
cleanup $_ || $$st{"skip"}, $WORKDIR, ++$tno;
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
# 2: Default suffix and trim suffix is set to .resolved
$_ = eval {
return if $$st{"skip"};
my ($title, $cmd, $retno, $out, $err, $logfile);
my ($title, $cmd, $ret_no, $out, $err, $logfile);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $fo, $cs, $csr, $co, $suf);
my ($fs, $cs, $csr, $suf);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ", ", "Default suffix and trim suffix is set to .resolved",
$$st{"title"};
$logfile = randword;
$logfile = random_word;
$suf = ".resolved";
$fs = catfile($WORKDIR, "$logfile" . $$st{"suf"});
($cs, $csr) = mkrndlog_normal $fs;
($cs, $csr) = make_log_file $fs;
@fle = qw();
push @fle, basename($fs);
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
@_ = ($reslog, qw(-d -d -d -n 1), "-t", $suf, $fs);
$cmd = join " ", @_;
($retno, $out, $err) = runcmd "", @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -110,13 +109,13 @@ foreach my $st (@SRCTYPES) {
$fr = $fs;
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs, $$st{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno != 0;
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
die "$title\n$cmd\n$out$err" unless $ret_no != 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr}
unless has_no_file || $trf{$fr} eq $tef{$fr}
|| ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr));
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
@ -124,40 +123,40 @@ foreach my $st (@SRCTYPES) {
1;
};
skip($$st{"skip"}, $_, 1, $@);
cleanup $_ || $$st{"skip"}, $WORKDIR, ++$tno;
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
}
# 7: A same log file is specified more than once
$_ = eval {
my ($title, $cmd, $retno, $out, $err, %logfiles);
my ($title, $cmd, $ret_no, $out, $err, %logfiles);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $tsuf, $dup);
my ($num, @fs, @fo, @cs, @csr, @co, @st, $suf, $trim_suf, $dup);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = "A same log file is specified more than once";
$suf = "." . randword;
do { $tsuf = "." . randword; } until $tsuf ne $suf;
$suf = "." . random_word;
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
# (2-4 times available compression) log files
$_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2);
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2);
$num = $_ + int rand $_;
%_ = qw();
my %types = qw();
# At least 2 files for each available compression
foreach my $st (@SRCTYPES) {
next if ($$st{"type"} eq TYPE_GZIP && nogzip)
|| ($$st{"type"} eq TYPE_BZIP2 && nobzip2);
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
@_ = grep !exists $_{$_}, (0...$num-1);
$_{$_[int rand @_]} = $st;
foreach my $st (@SOURCE_TYPES) {
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2);
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
@_ = grep !exists $types{$_}, (0...$num-1);
$types{$_[int rand @_]} = $st;
}
# Set random compression on the rest files
foreach (grep !exists $_{$_}, (0...$num-1)) {
foreach (grep !exists $types{$_}, (0...$num-1)) {
do {
$_{$_} = $SRCTYPES[int rand @SRCTYPES];
} until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip)
&& !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2);
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2);
}
@st = map $_{$_}, (0...$num-1);
@st = map $types{$_}, (0...$num-1);
@fs = qw();
@fo = qw();
@cs = qw();
@ -167,31 +166,31 @@ $_ = eval {
%logfiles = qw();
for (my $k = 0; $k < $num; $k++) {
my ($logfile, $cs, $csr, $co);
do { $logfile = randword } until !exists $logfiles{$logfile};
do { $logfile = random_word } until !exists $logfiles{$logfile};
$logfiles{$logfile} = 1;
push @fs, catfile($WORKDIR, "$logfile$tsuf" . ${$st[$k]}{"suf"});
push @fs, catfile($WORKDIR, "$logfile$trim_suf" . ${$st[$k]}{"suf"});
push @fo, catfile($WORKDIR, "$logfile$suf" . ${$st[$k]}{"suf"});
($cs, $csr) = mkrndlog_normal $fs[$k];
($cs, $csr) = make_log_file $fs[$k];
push @cs, $cs;
push @csr, $csr;
push @fle, basename($fs[$k]);
# 1: create existing file, 0: no existing file
if (int rand 1) {
$co = (mkrndlog_normal $fo[$k])[0];
$co = (make_log_file $fo[$k])[0];
push @co, $co;
push @fle, basename($fo[$k]);
} else {
push @co, "";
}
}
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
$dup = $fs[int rand @fs];
$_ = int rand(@fs + 1);
@_ = (@fs[0...$_-1], $dup, @fs[$_...$#fs]);
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $tsuf, @_);
@_ = ($reslog, qw(-d -d -d -o a), "-s", $suf, "-t", $trim_suf, @_);
$cmd = join(" ", @_);
($retno, $out, $err) = runcmd "", @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd "", @_;
($fle, $flr) = (join(" ", sort @fle), list_files $WORKDIR);
%cef = qw(); # Expected content by file
%tef = qw(); # Expected file type by file
%crf = qw(); # Resulted content by file
@ -200,24 +199,24 @@ $_ = eval {
$fr = $fs[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
if ($co[$k] ne "") {
$fr = $fo[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($co[$k], ${$st[$k]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
}
die "$title\n$cmd\n$out$err" unless $retno != 0;
die "$title\n$cmd\n$out$err" unless $ret_no != 0;
die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err"
unless $flr eq $fle;
foreach $fr (@fle) {
die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err"
unless nofile || $trf{$fr} eq $tef{$fr};
unless has_no_file || $trf{$fr} eq $tef{$fr};
die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err"
unless $crf{$fr} eq $cef{$fr};
}
1;
};
ok($_, 1, $@);
cleanup $_, $WORKDIR, ++$tno;
clean_up $_, $WORKDIR, ++$tno;

File diff suppressed because it is too large Load Diff