parallel: fixup to pass testsuite. Passes testsuite.

This commit is contained in:
Ole Tange 2011-05-05 17:37:27 +02:00
parent e2cf6fdd0a
commit 1f3af83d66
9 changed files with 92 additions and 76 deletions

View file

@ -1,3 +1,5 @@
Test with first argument == END_OF_FILE string
unittest til xapply og uden.
parallel echo {1} {2} {3} ::: a b c :::: myfile ::: X Y

View file

@ -3411,7 +3411,7 @@ sub number_of_replacements {
my %count = ();
my $sum = 0;
my $cmd = $command;
my $multi_regexp = multi_regexp();
my $multi_regexp = multi_regexp();
my $replacement_regexp =
"(?:".
'\{\d+/?\.?\}'. # {n}, {n.} {n/.} {n/}
@ -3949,19 +3949,30 @@ sub nest_get {
# Initialize @::arg_matrix with one arg from each file
# read one line from each file
my @first_arg_set;
my $all_empty = 1;
for (my $fhno = 0; $fhno < $no_of_inputs ; $fhno++) {
$::arg_matrix[$fhno][0]=read_arg_from_fh($self->{'fhs'}[$fhno]);
my $arg = read_arg_from_fh($self->{'fhs'}[$fhno]);
if(defined $arg) {
$all_empty = 0;
}
$::arg_matrix[$fhno][0] = $arg || Arg->new("");
push @first_arg_set, $::arg_matrix[$fhno][0];
}
$self->unget([@first_arg_set]);
if($all_empty) {
# All filehandles were at eof or eof-string
return undef;
}
return [@first_arg_set];
}
for (my $fhno = $no_of_inputs - 1; $fhno >= 0; $fhno--) {
if(eof($self->{'fhs'}[$fhno])) {
next;
} else {
# read one
my $arg = read_arg_from_fh($self->{'fhs'}[$fhno])
|| next; # If we just read an EOF string: Treat this as EOF
my $len = $#{$::arg_matrix[$fhno]} + 1;
$::arg_matrix[$fhno][$len]=read_arg_from_fh($self->{'fhs'}[$fhno]);
$::arg_matrix[$fhno][$len] = $arg;
# make all new combinations
my @combarg = ();
for (my $fhn = 0; $fhn < $no_of_inputs; $fhn++) {
@ -3986,8 +3997,8 @@ sub nest_get {
return shift @{$self->{'unget'}};
}
}
# all are eof; return undef
return undef;
# all are eof or at EOF string; return from the unget queue
return shift @{$self->{'unget'}};
}
sub read_arg_from_fh {
@ -3997,44 +4008,47 @@ sub read_arg_from_fh {
# undef if end of file
my $fh = shift;
my $prepend = undef;
loop:
if(eof($fh)) {
my $arg;
do {{
if(eof($fh)) {
if(defined $prepend) {
return Arg->new($prepend);
} else {
return undef;
}
}
$arg = <$fh>;
::debug("read $arg\n");
# Remove delimiter
$arg =~ s:$/$::;
if($Global::end_of_file_string and
$arg eq $Global::end_of_file_string) {
# Ignore the rest of input file
while (<$fh>) {}
::debug("EOF-string $arg\n");
if(defined $prepend) {
return Arg->new($prepend);
} else {
return undef;
}
}
if(defined $prepend) {
return Arg->new($prepend);
} else {
return undef;
$arg = $prepend.$arg; # For line continuation
$prepend = undef; #undef;
}
}
my $arg = <$fh>;
# Remove delimiter
$arg =~ s:$/$::;
if($Global::end_of_file_string and
$arg eq $Global::end_of_file_string) {
# Ignore the rest of input file
while (<$fh>) {}
::debug("EOF-string $arg\n");
if(defined $prepend) {
return Arg->new($prepend);
} else {
return undef;
if($Global::ignore_empty) {
if($arg =~ /^\s*$/) {
redo; # Try the next line
}
}
}
if(defined $prepend) {
$arg = $prepend.$arg; # For line continuation
$prepend = undef; #undef;
}
if($Global::ignore_empty) {
if($arg =~ /^\s*$/) {
redo; # Try the next line
if($Global::max_lines) {
if($arg =~ /\s$/) {
# Trailing space => continued on next line
$prepend = $arg;
redo;
}
}
}
if($Global::max_lines) {
if($arg =~ /\s$/) {
# Trailing space => continued on next line
$prepend = $arg;
redo;
}
}
}} while (1 == 0); # Dummy loop for redo
if(defined $arg) {
return Arg->new($arg);
} else {

View file

@ -190,7 +190,7 @@ stdout ssh $SERVER1 ls '/tmp/parallel.file*' || echo OK
stdout ssh parallel@$SERVER2 ls '/tmp/parallel.file*' || echo OK
echo '### --transfer --cleanup - multiple argument files'
parallel -kv --transfer --cleanup -Sparallel@$SERVER2 cat {2} {1} :::: /tmp/test17rel <(sort -r /tmp/test17abs)
parallel --xapply -kv --transfer --cleanup -Sparallel@$SERVER2 cat {2} {1} :::: /tmp/test17rel <(sort -r /tmp/test17abs)
# Should give: No such file or directory
stdout ssh parallel@$SERVER2 ls '/tmp/parallel.file*' || echo OK

View file

@ -2,53 +2,53 @@
echo '### Test ::::'
echo '### Change --arg-file-sep'
parallel --arg-file-sep :::: -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
parallel --arg-file-sep .--- -k echo {1} {2} .--- <(seq 1 10) <(seq 5 15)
parallel --argfilesep :::: -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
parallel --argfilesep .--- -k echo {1} {2} .--- <(seq 1 10) <(seq 5 15)
parallel --xapply --arg-file-sep :::: -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
parallel --xapply --arg-file-sep .--- -k echo {1} {2} .--- <(seq 1 10) <(seq 5 15)
parallel --xapply --argfilesep :::: -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
parallel --xapply --argfilesep .--- -k echo {1} {2} .--- <(seq 1 10) <(seq 5 15)
echo '### Test xapply --max-replace-args'
seq 0 7 | parallel -k --max-replace-args=3 echo {3} {2} {1}
seq 0 7 | parallel --xapply -k --max-replace-args=3 echo {3} {2} {1}
echo '### Test -N'
seq 1 5 | parallel -kN3 echo {1} {2} {3}
seq 1 5 | parallel --xapply -kN3 echo {1} {2} {3}
echo '### Test -N with 0'
seq 0 7 | parallel -kN3 echo {1} {2} {3}
seq 0 7 | parallel --xapply -kN3 echo {1} {2} {3}
echo '### Test :::: on nonexistent'
stdout parallel -k echo {1} {2} {3} :::: nonexistent
stdout parallel --xapply -k echo {1} {2} {3} :::: nonexistent
echo '### Test :::: two files'
parallel -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
parallel --xapply -k echo {1} {2} :::: <(seq 1 10) <(seq 5 15)
echo '### Test -d, ::::'
parallel -kd, 'echo a{1} {2}b' :::: <(echo 1,2,3,) <(echo 5,6,7,8)
parallel --xapply -kd, 'echo a{1} {2}b' :::: <(echo 1,2,3,) <(echo 5,6,7,8)
echo '### Test -d, :::: one file too much'
parallel -kd, echo 'a{1}' '{2}b' :::: <(echo 1,2,3,) <(echo 5,6,7,8) <(echo 9,0)
parallel --xapply -kd, echo 'a{1}' '{2}b' :::: <(echo 1,2,3,) <(echo 5,6,7,8) <(echo 9,0)
echo '### Bug: did not quote'
parallel echo {1} {2} :::: <(echo '>') <(echo b)
parallel --xapply echo {1} {2} :::: <(echo '>') <(echo b)
echo '### Quote test triplet 1'
parallel -kv :::: <(echo 'echo a'; echo 'echo b')
parallel -kv -a <(echo 'echo a'; echo 'echo b')
(echo 'echo a'; echo 'echo b') | parallel -kv
parallel --xapply -kv :::: <(echo 'echo a'; echo 'echo b')
parallel --xapply -kv -a <(echo 'echo a'; echo 'echo b')
(echo 'echo a'; echo 'echo b') | parallel --xapply -kv
echo '### Quote test triplet 2'
parallel -kv echo :::: <(echo 'echo a'; echo 'echo b')
parallel -kv -a <(echo 'echo a'; echo 'echo b') echo
(echo 'echo a'; echo 'echo b') | parallel -kv echo
parallel --xapply -kv echo :::: <(echo 'echo a'; echo 'echo b')
parallel --xapply -kv -a <(echo 'echo a'; echo 'echo b') echo
(echo 'echo a'; echo 'echo b') | parallel --xapply -kv echo
echo '### Quoting if there is a command and 2 arg files'
parallel -kv echo :::: <(echo 'echo a') <(echo 'echo b')
parallel --xapply -kv echo :::: <(echo 'echo a') <(echo 'echo b')
echo '### Quoting if there is a command and 2 arg files of uneven length'
parallel -kv echo :::: <(echo 'echo a';echo a1) <(echo 'echo b')
parallel --xapply -kv echo :::: <(echo 'echo a';echo a1) <(echo 'echo b')
echo '### Quoting if there is no command and 2 arg files'
parallel -kv :::: <(echo 'echo a') <(echo 'echo b')
parallel --xapply -kv :::: <(echo 'echo a') <(echo 'echo b')
echo '### Quoting if there is no command and 2 arg files of uneven length'
parallel -kv :::: <(echo 'echo a';echo echo a1) <(echo 'echo b')
parallel --xapply -kv :::: <(echo 'echo a';echo echo a1) <(echo 'echo b')
echo '### Test multiple -a'
parallel -kv -a <(echo a) -a <(echo b) echo {2} {1}
parallel -kv echo {2} {1} :::: <(echo a) <(echo b)
parallel --xapply -kv -a <(echo a) -a <(echo b) echo {2} {1}
parallel --xapply -kv echo {2} {1} :::: <(echo a) <(echo b)
echo '### Multiple -a: An unused file'
parallel -kv -a <(echo a) -a <(echo b) -a <(echo c) echo {2} {1}
parallel -kv echo {2} {1} :::: <(echo a) <(echo b) <(echo c)
parallel --xapply -kv -a <(echo a) -a <(echo b) -a <(echo c) echo {2} {1}
parallel --xapply -kv echo {2} {1} :::: <(echo a) <(echo b) <(echo c)
echo '### Multiple -a: nonexistent'
stdout parallel -kv echo {2} {1} :::: nonexist nonexist2
stdout parallel -kv -a nonexist -a nonexist2 echo {2} {1}
stdout parallel --xapply -kv echo {2} {1} :::: nonexist nonexist2
stdout parallel --xapply -kv -a nonexist -a nonexist2 echo {2} {1}
echo '### Test {#.}'
parallel -kv -a <(echo a-noext) -a <(echo b-withext.extension) -a <(echo c-ext.gif) echo {3.} {2.} {1.}
parallel --xapply -kv -a <(echo a-noext) -a <(echo b-withext.extension) -a <(echo c-ext.gif) echo {3.} {2.} {1.}

View file

@ -39,10 +39,10 @@ printf 'def\tabc\njkl\tghi' | parallel -k --colsep '\t' echo {2} {1}
parallel -k -a <(printf 'def\tabc\njkl\tghi') --colsep '\t' echo {2} {1}
echo '### Test of multiple -a plus colsep'
parallel -k -a <(printf 'def\njkl\n') -a <(printf 'abc\tghi\nmno\tpqr') --colsep '\t' echo {2} {1}
parallel --xapply -k -a <(printf 'def\njkl\n') -a <(printf 'abc\tghi\nmno\tpqr') --colsep '\t' echo {2} {1}
echo '### Test of multiple -a no colsep'
parallel -k -a <(printf 'ghi\npqr\n') -a <(printf 'abc\tdef\njkl\tmno') echo {2} {1}
parallel --xapply -k -a <(printf 'ghi\npqr\n') -a <(printf 'abc\tdef\njkl\tmno') echo {2} {1}
echo '### Test of quoting after colsplit'
parallel --colsep % echo {2} {1} ::: '>/dev/null%>/tmp/null'

View file

@ -32,7 +32,7 @@ chmod 755 /tmp/shebang
echo '### Test of #! with 2 files as input'
cat >/tmp/shebang <<EOF
#!/usr/local/bin/parallel -Yrk -a /tmp/123 echo
#!/usr/local/bin/parallel -Yrk --xapply -a /tmp/123 echo
A
B
C

View file

@ -23,7 +23,7 @@ echo '### Test -N'
seq 1 5 | parallel -kN3 echo {1} {2} {3}
echo '### Test --arg-file-sep with files of different lengths'
parallel --arg-file-sep :::: -k echo {1} {2} :::: <(seq 1 1) <(seq 3 4)
parallel --xapply --arg-file-sep :::: -k echo {1} {2} :::: <(seq 1 1) <(seq 3 4)
echo '### Test respect -s'
parallel -kvm -IARG -s15 echo ARG ::: 1 22 333 4444 55555 666666 7777777 88888888 999999999

View file

@ -2,6 +2,6 @@
echo "### Computing length of command line"
seq 1 2 | parallel -k -N2 echo {1} {2}
parallel -k -a <(seq 11 12) -a <(seq 1 3) echo
parallel --xapply -k -a <(seq 11 12) -a <(seq 1 3) echo
parallel -k -C %+ echo '"{1}_{3}_{2}_{4}"' ::: 'a% c %%b' 'a%c% b %d'
parallel -k -C %+ echo {4} ::: 'a% c %%b'

View file

@ -192,7 +192,7 @@ stdout ssh $SERVER1 ls '/tmp/parallel.file*' || echo OK
stdout ssh parallel@$SERVER2 ls '/tmp/parallel.file*' || echo OK
echo '### --transfer --cleanup - multiple argument files'
parallel -kv --transfer --cleanup -Sparallel@$SERVER2 cat {2} {1} :::: /tmp/test17rel <(sort -r /tmp/test17abs)
parallel -kv --xapply --transfer --cleanup -Sparallel@$SERVER2 cat {2} {1} :::: /tmp/test17rel <(sort -r /tmp/test17abs)
# Should give: No such file or directory
stdout ssh parallel@$SERVER2 ls '/tmp/parallel.file*' || echo OK