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:34:55 +08:00
parent 8e134b3a67
commit 896b7ac5ce
40 changed files with 2235 additions and 5081 deletions
+113 -113
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,7 +29,7 @@ use File::Spec::Functions qw(catdir catfile updir);
use FindBin;
use lib $FindBin::Bin;
use _helper;
use vars qw($WORKDIR $arclog $tno);
our ($WORKDIR, $arclog, $tno);
$WORKDIR = catdir($FindBin::Bin, "logs");
$arclog = catfile($FindBin::Bin, updir, "blib", "script", "arclog");
@@ -38,166 +37,166 @@ $tno = 0;
# 1: STDIN alone
$_ = eval {
my ($title, $cmd, $retno, $out, $err, $vardump, $logfile);
my ($title, $cmd, $ret_no, $out, $err, $var_dump, $logfile);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $cs, %cem);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = "STDIN alone";
$logfile = randword;
$logfile = random_word;
$fs = catfile($WORKDIR, $logfile);
($cs, $vardump, %cem) = mkrndlog_apache $fs;
frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump);
($cs, $var_dump, %cem) = make_apache_log_file $fs;
write_raw_file(catfile($WORKDIR, "$logfile.var-dump"), $var_dump);
@fle = qw();
push @fle, basename($fs);
push @fle, "$logfile.vardump";
prsrvsrc $WORKDIR;
push @fle, "$logfile.var-dump";
preserve_source $WORKDIR;
@_ = ($arclog, qw(-d -d -d -c n), "-");
$cmd = join(" ", @_) . " < " . $fs;
($retno, $out, $err) = runcmd frread $fs, @_;
($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR);
($ret_no, $out, $err) = run_cmd read_raw_file $fs, @_;
($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
$fr = $fs;
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs, TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
$frb = "$logfile.vardump";
($cef{$frb}, $tef{$frb}) = ($cs, TYPE_TEXT);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
$frb = "$logfile.var-dump";
$fr = catfile($WORKDIR, $frb);
($cef{$frb}, $tef{$frb}) = ($vardump, TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno != 0;
($cef{$frb}, $tef{$frb}) = ($var_dump, TYPE_TEXT);
($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};
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: STDOUT as output prefix
$_ = eval {
my ($title, $cmd, $retno, $out, $err, $vardump, $logfile);
my ($title, $cmd, $ret_no, $out, $err, $var_dump, $logfile);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($fs, $cs, %cem);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = "STDOUT as output prefix";
$logfile = randword;
$logfile = random_word;
$fs = catfile($WORKDIR, $logfile);
($cs, $vardump, %cem) = mkrndlog_apache $fs;
frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump);
($cs, $var_dump, %cem) = make_apache_log_file $fs;
write_raw_file(catfile($WORKDIR, "$logfile.var-dump"), $var_dump);
@fle = qw();
push @fle, basename($fs);
push @fle, "$logfile.vardump";
prsrvsrc $WORKDIR;
push @fle, "$logfile.var-dump";
preserve_source $WORKDIR;
@_ = ($arclog, qw(-d -d -d -c n), $logfile, "-");
$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
$fr = $fs;
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs, TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
$frb = "$logfile.vardump";
($cef{$frb}, $tef{$frb}) = ($cs, TYPE_TEXT);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
$frb = "$logfile.var-dump";
$fr = catfile($WORKDIR, $frb);
($cef{$frb}, $tef{$frb}) = ($vardump, TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
die "$title\n$cmd\n$out$err" unless $retno != 0;
($cef{$frb}, $tef{$frb}) = ($var_dump, TYPE_TEXT);
($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};
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;
# 3: A same log file is specified more than once
$_ = eval {
my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles);
my ($title, $cmd, $ret_no, $out, $err, @var_dump, %logfiles);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $mt);
my (@st, $fmt, $rt, $dup);
rmtree $WORKDIR;
mkpath $WORKDIR;
$fmt = $LOGFMTS[int rand @LOGFMTS];
$rt = $RESTYPES[int rand @RESTYPES];
$fmt = $LOG_FORMATS[int rand @LOG_FORMATS];
$rt = $RESULT_TYPES[int rand @RESULT_TYPES];
$title = join ",", "A same log file is specified more than once",
$$fmt{"title"}, $$rt{"title"};
# (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();
@cs = qw();
@cem = qw();
@vardump = qw();
@var_dump = qw();
@fle = qw();
%logfiles = qw();
for (my $k = 0; $k < $num; $k++) {
my ($logfile, $cs, $vardump);
do { $logfile = randword } until !exists $logfiles{$logfile};
my ($logfile, $cs, $var_dump);
do { $logfile = random_word } until !exists $logfiles{$logfile};
$logfiles{$logfile} = 1;
$logfile .= ${$st[$k]}{"suf"};
push @fs, catfile($WORKDIR, $logfile);
($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]);
($cs, $var_dump, %types) = &{$$fmt{"sub"}}($fs[$k]);
push @cs, $cs;
push @cem, {%_};
push @cem, {%types};
push @fle, $logfile;
push @vardump, $vardump;
frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump);
push @fle, "$logfile.vardump";
push @var_dump, $var_dump;
write_raw_file(catfile($WORKDIR, "$logfile.var-dump"), $var_dump);
push @fle, "$logfile.var-dump";
}
%_ = qw();
%_ = (%_, map { $_ => 1 } keys %$_) foreach @cem;
@mle = sort keys %_;
%types = qw();
%types = (%types, map { $_ => 1 } keys %$_) foreach @cem;
@mle = sort keys %types;
$mt = pop @mle;
do { $oprfb = randword } until !exists $logfiles{$oprfb};
do { $oprfb = random_word } until !exists $logfiles{$oprfb};
$opref = catfile($WORKDIR, $oprfb);
%cof = mkrndlog_existing $$fmt{"sub"},
%cof = make_log_file $$fmt{"sub"},
$WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle;
push @fle, map basename($_), grep $cof{$_} ne "", keys %cof;
prsrvsrc $WORKDIR;
preserve_source $WORKDIR;
$dup = $fs[int rand @fs];
$_ = int rand(@fs + 1);
@_ = (@fs[0...$_-1], $dup, @fs[$_...$#fs]);
@_ = ($arclog, qw(-d -d -d -o a), @{$$rt{"opts"}}, @_, $opref);
$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
@@ -206,76 +205,77 @@ $_ = eval {
$fr = $fs[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"});
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
$fr = $fs[$k] . ".vardump";
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
$fr = $fs[$k] . ".var-dump";
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($cef{$frb}, $tef{$frb}) = ($var_dump[$k], TYPE_TEXT);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
}
foreach my $m (@mle) {
$fr = "$opref.$m" . $$rt{"suf"};
$frb = basename($fr);
next if $cof{$frb} eq "";
($cef{$frb}, $tef{$frb}) = ($cof{$frb}, $$rt{"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;
# 4-23: Mixing different formats
for (my $i = 0; $i < @LOGFMTS; $i++) {
for (my $j = 0; $j < @LOGFMTS; $j++) {
for (my $i = 0; $i < @LOG_FORMATS; $i++) {
for (my $j = 0; $j < @LOG_FORMATS; $j++) {
next if $i == $j;
$_ = eval {
my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles);
my ($title, $cmd, $ret_no, $out, $err, @var_dump, %logfiles);
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
my ($num, $swan, @fs, @cs, $opref, $oprfb);
rmtree $WORKDIR;
mkpath $WORKDIR;
$title = join ",", "Mixing formats", ${$LOGFMTS[$i]}{"title"},
${$LOGFMTS[$j]}{"title"};
$title = join ",", "Mixing formats", ${$LOG_FORMATS[$i]}{"title"},
${$LOG_FORMATS[$j]}{"title"};
# 3-5 log files
$num = 3 + int rand 3;
$swan = 1 + int rand($num - 1);
@fs = qw();
@cs = qw();
@vardump = qw();
@var_dump = qw();
@fle = qw();
%logfiles = qw();
for (my $k = 0; $k < $num; $k++) {
my ($logfile, $cs, $vardump);
do { $logfile = randword } until !exists $logfiles{$logfile};
my ($logfile, $cs, $var_dump);
do { $logfile = random_word } until !exists $logfiles{$logfile};
$logfiles{$logfile} = 1;
push @fs, catfile($WORKDIR, $logfile);
my %by_months;
if ($k != $swan) {
($cs, $vardump, %_) = &{${$LOGFMTS[$i]}{"sub"}}($fs[$k]);
($cs, $var_dump, %by_months) = &{${$LOG_FORMATS[$i]}{"sub"}}($fs[$k]);
} else {
($cs, $vardump, %_) = &{${$LOGFMTS[$j]}{"sub"}}($fs[$k]);
($cs, $var_dump, %by_months) = &{${$LOG_FORMATS[$j]}{"sub"}}($fs[$k]);
}
push @cs, $cs;
push @fle, $logfile;
push @vardump, $vardump;
frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump);
push @fle, "$logfile.vardump";
push @var_dump, $var_dump;
write_raw_file(catfile($WORKDIR, "$logfile.var-dump"), $var_dump);
push @fle, "$logfile.var-dump";
}
prsrvsrc $WORKDIR;
do { $oprfb = randword } until !exists $logfiles{$oprfb};
preserve_source $WORKDIR;
do { $oprfb = random_word } until !exists $logfiles{$oprfb};
$opref = catfile($WORKDIR, $oprfb);
@_ = ($arclog, qw(-d -d -d -c n), @fs, $opref);
$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
@@ -283,26 +283,26 @@ for (my $i = 0; $i < @LOGFMTS; $i++) {
for (my $k = 0; $k < $num; $k++) {
$fr = $fs[$k];
$frb = basename($fr);
($cef{$frb}, $tef{$frb}) = ($cs[$k], TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
$frb = "$frb.vardump";
($cef{$frb}, $tef{$frb}) = ($cs[$k], TYPE_TEXT);
($crf{$frb}, $trf{$frb}) = (read_file $fr, file_type $fr);
$frb = "$frb.var-dump";
$fr = catfile($WORKDIR, $frb);
($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN);
($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr);
($cef{$frb}, $tef{$frb}) = ($var_dump[$k], TYPE_TEXT);
($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;
die unless $_;
}
}