From 1ce104d8a2487cc8f5d5b4ed351a3651392cb496 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Wed, 9 Apr 2003 02:03:17 +0000 Subject: - Never reorder files in patches. (Previously the file list was run through (sort | uniq) to remove duplicate entries.) - Update test script to new format, and add regression test cases. --- quilt.changes | 8 ++ scripts/patchfns.in | 7 +- test/comments.test | 47 +++++++++ test/one.test | 272 +++++++++++++++++++++++++++++----------------------- test/reorder.test | 49 ++++++++++ test/run | 149 ++++++++++++++++++---------- 6 files changed, 359 insertions(+), 173 deletions(-) create mode 100644 test/comments.test create mode 100644 test/reorder.test diff --git a/quilt.changes b/quilt.changes index 246e4b9..ac7171a 100644 --- a/quilt.changes +++ b/quilt.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Wed Apr 9 04:00:52 CEST 2003 - agruen@suse.de + +- Never reorder files in patches. (Previously the file list + was run through (sort | uniq) to remove duplicate entries.) +- Update test script to new format, and add regression test + cases. + ------------------------------------------------------------------- Wed Apr 9 02:38:30 CEST 2003 - agruen@suse.de diff --git a/scripts/patchfns.in b/scripts/patchfns.in index a1c39bf..6ae58a4 100644 --- a/scripts/patchfns.in +++ b/scripts/patchfns.in @@ -505,6 +505,8 @@ refresh_file_list() return 1 fi + # Do not reorder files in the file list... + if [ -e $pc_file ] then cat $pc_file >> $tmpfile @@ -514,7 +516,10 @@ refresh_file_list() then return 1 fi - sort $tmpfile | uniq > $pc_file + awk ' { if (seen[$0]) next + seen[$0]=1 + print + }' $tmpfile > $pc_file rm $tmpfile return 0 fi diff --git a/test/comments.test b/test/comments.test new file mode 100644 index 0000000..e1f7f0c --- /dev/null +++ b/test/comments.test @@ -0,0 +1,47 @@ +Regresion test case: Empty lines in patch descriptions were +accidentally removed. + + $ mkdir d + $ cd d + $ mkdir patches + $ echo one > f + $ cat > patches/test.diff + < C1 + < + < C3 + < + < Index: f + < =================================================================== + < --- f.orig 2003-04-09 03:18:06.000000000 +0200 + < +++ f 2003-04-09 03:18:09.000000000 +0200 + < @@ -1 +1 @@ + < -one + < +two + + $ cat > patches/series + < test.diff -p0 + + $ quilt push + > Applying test + > patching file f + > + > Now at patch test + + $ quilt refresh + > Refreshed patch test + $ sed -e "s/\\t.*//" patches/test.diff + > C1 + > + > C3 + > + > Index: f + > =================================================================== + > --- f.orig + > +++ f + > @@ -1 +1 @@ + > -one + > +two + + $ cd .. + $ rm -rf d + diff --git a/test/one.test b/test/one.test index e49eb66..40329a9 100644 --- a/test/one.test +++ b/test/one.test @@ -1,121 +1,151 @@ -# This is a minimal test script that runs a few quilt commands -# and verifies their output. Much needs to be done; particularly -# it sould be possible to run the tests using the built instead -# of the installed quilt with `make check'. -# -# (To run, type `./run one.test' in this directory.) -# -$ mkdir dir -$ echo "This is file one." > dir/file1 -$ quilt new patch1.diff -Patch patch1 is now on top -$ quilt add dir/file1 -File dir/file1 added to patch patch1 -$ quilt add file2 -File file2 added to patch patch1 -$ quilt diff -$ quilt diff -z -$ quilt refresh -Nothing in patch patch1 -$ quilt files -dir/file1 -file2 -$ echo "This is file two." > file2 -$ quilt diff | sed -e "s/\\t.*//" -Index: test/file2 -=================================================================== ---- test.orig/file2 -+++ test/file2 -@@ -0,0 +1 @@ -+This is file two. -$ quilt diff -z | sed -e "s/\\t.*//" -Index: test/file2 -=================================================================== ---- test.orig/file2 -+++ test/file2 -@@ -0,0 +1 @@ -+This is file two. -$ quilt refresh -Refreshed patch patch1 -$ quilt diff -z -$ echo "Another line has been added." >> dir/file1 -$ quilt diff -z | sed -e "s/\\t.*//" -Index: test/dir/file1 -=================================================================== ---- test.orig/dir/file1 -+++ test/dir/file1 -@@ -1 +1,2 @@ - This is file one. -+Another line has been added. -$ quilt refresh -Refreshed patch patch1 -$ quilt new patch2.diff -Patch patch2 is now on top -$ quilt add dir/file3 -File dir/file3 added to patch patch2 -$ echo "This is file three." > dir/file3 -$ quilt refresh -Refreshed patch patch2 -$ quilt add -p patch1 dir/file3 -File dir/file3 modified by patch patch2 -$ quilt pop -R -Removing patch2 -patching file dir/file3 - -Now at patch patch1 -$ quilt add file4 -File file4 added to patch patch1 -$ echo "This is file 4." > file4 -$ quilt refresh -Refreshed patch patch1 -$ quilt push -Applying patch2 -patching file dir/file3 - -Now at patch patch2 -$ quilt new subdir/patch3.diff -Patch subdir/patch3 is now on top -$ quilt add file4 -File file4 added to patch subdir/patch3 -$ rm file4 -$ quilt diff | sed -e "s/\\t.*//" -Index: test/file4 -=================================================================== ---- test.orig/file4 -+++ test/file4 -@@ -1 +0,0 @@ --This is file 4. -$ quilt add -p patch2 file4 -File file4 modified by patch subdir/patch3 -$ quilt refresh -Refreshed patch subdir/patch3 -$ echo "Another line here, too." >> dir/file3 -$ quilt refresh patch2 -Refreshed patch patch2 -$ echo "Another line added." >> file2 -$ quilt diff -z -P patch1 | sed -e "s/\\t.*//" -Index: test/file2 -=================================================================== ---- test.orig/file2 -+++ test/file2 -@@ -1 +1,2 @@ - This is file two. -+Another line added. -More recent patches modify files in patch1. -$ quilt refresh patch1 -More recent patches modify files in patch1. Enforce refresh with -f. -$ quilt refresh -f patch1 -Refreshed patch patch1 -$ echo "Another line here, too." >> dir/file3 -$ quilt pop -R -Removing subdir/patch3 -patching file file4 - -Now at patch patch2 -$ quilt refresh patch2 -Refreshed patch patch2 -$ quilt pop -qaR -Removing patch2 -Removing patch1 -No patches applied -$ rm -r dir patches +This is a minimal test script that runs a few quilt commands +and verifies their output. Much needs to be done; particularly +it sould be possible to run the tests using the built instead +of the installed quilt with `make check'. + +(To run, type `./run one.test' in this directory.) + + $ mkdir dir + $ echo "This is file one." > dir/file1 + $ quilt new patch1.diff + > Patch patch1 is now on top + + $ quilt add dir/file1 + > File dir/file1 added to patch patch1 + + $ quilt add file2 + > File file2 added to patch patch1 + + $ quilt diff + $ quilt diff -z + $ quilt refresh + > Nothing in patch patch1 + + $ quilt files + > dir/file1 + > file2 + + $ echo "This is file two." > file2 + $ quilt diff | sed -e "s/\\t.*//" + > Index: test/file2 + > =================================================================== + > --- test.orig/file2 + > +++ test/file2 + > @@ -0,0 +1 @@ + > +This is file two. + + $ quilt diff -z | sed -e "s/\\t.*//" + > Index: test/file2 + > =================================================================== + > --- test.orig/file2 + > +++ test/file2 + > @@ -0,0 +1 @@ + > +This is file two. + + $ quilt refresh + > Refreshed patch patch1 + + $ quilt diff -z + $ echo "Another line has been added." >> dir/file1 + $ quilt diff -z | sed -e "s/\\t.*//" + > Index: test/dir/file1 + > =================================================================== + > --- test.orig/dir/file1 + > +++ test/dir/file1 + > @@ -1 +1,2 @@ + > This is file one. + > +Another line has been added. + + $ quilt refresh + > Refreshed patch patch1 + + $ quilt new patch2.diff + > Patch patch2 is now on top + + $ quilt add dir/file3 + > File dir/file3 added to patch patch2 + + $ echo "This is file three." > dir/file3 + $ quilt refresh + > Refreshed patch patch2 + + $ quilt add -p patch1 dir/file3 + > File dir/file3 modified by patch patch2 + + $ quilt pop -R + > Removing patch2 + > patching file dir/file3 + > + > Now at patch patch1 + + $ quilt add file4 + > File file4 added to patch patch1 + + $ echo "This is file 4." > file4 + $ quilt refresh + > Refreshed patch patch1 + + $ quilt push + > Applying patch2 + > patching file dir/file3 + > + > Now at patch patch2 + + $ quilt new subdir/patch3.diff + > Patch subdir/patch3 is now on top + + $ quilt add file4 + > File file4 added to patch subdir/patch3 + + $ rm file4 + $ quilt diff | sed -e "s/\\t.*//" + > Index: test/file4 + > =================================================================== + > --- test.orig/file4 + > +++ test/file4 + > @@ -1 +0,0 @@ + > -This is file 4. + + $ quilt add -p patch2 file4 + > File file4 modified by patch subdir/patch3 + + $ quilt refresh + > Refreshed patch subdir/patch3 + + $ echo "Another line here, too." >> dir/file3 + $ quilt refresh patch2 + > Refreshed patch patch2 + + $ echo "Another line added." >> file2 + $ quilt diff -z -P patch1 | sed -e "s/\\t.*//" + > Index: test/file2 + > =================================================================== + > --- test.orig/file2 + > +++ test/file2 + > @@ -1 +1,2 @@ + > This is file two. + > +Another line added. + > More recent patches modify files in patch1. + + $ quilt refresh patch1 + > More recent patches modify files in patch1. Enforce refresh with -f. + + $ quilt refresh -f patch1 + > Refreshed patch patch1 + + $ echo "Another line here, too." >> dir/file3 + $ quilt pop -R + > Removing subdir/patch3 + > patching file file4 + > + > Now at patch patch2 + + $ quilt refresh patch2 + > Refreshed patch patch2 + + $ quilt pop -qaR + > Removing patch2 + > Removing patch1 + > No patches applied + + $ rm -r dir patches diff --git a/test/reorder.test b/test/reorder.test new file mode 100644 index 0000000..7acdf45 --- /dev/null +++ b/test/reorder.test @@ -0,0 +1,49 @@ +Regression test: Quilt did reorder files in patches. + + $ mkdir d + $ cd d + $ echo one > f + $ echo one > g + $ mkdir patches + $ cat > patches/test.diff + < --- g.orig 2003-04-09 01:48:01.000000000 +0200 + < +++ g 2003-04-09 01:49:17.000000000 +0200 + < @@ -1 +1 @@ + < -one + < +two + < --- f.orig 2003-04-09 01:48:01.000000000 +0200 + < +++ f 2003-04-09 01:49:17.000000000 +0200 + < @@ -1 +1 @@ + < -one + < +two + + $ cat > patches/series + < test.diff -p0 + $ quilt push -q + > Applying test + > Now at patch test + + $ quilt pop -q + > Removing test + > No patches applied + + $ echo one > h + $ sleep 2 + $ cat >> patches/test.diff + < --- h.orig 2003-04-09 01:48:01.000000000 +0200 + < +++ h 2003-04-09 01:49:17.000000000 +0200 + < @@ -1 +1 @@ + < -one + < +two + + $ quilt push -q + > Applying test + > Now at patch test + + $ quilt files + > g + > f + > h + + $ cd .. + $ rm -rf d diff --git a/test/run b/test/run index c6d09f6..f60f9c6 100755 --- a/test/run +++ b/test/run @@ -1,4 +1,13 @@ -#! /usr/bin/perl -w -U +#!/usr/bin/perl -w -U + +# +# Possible improvements: +# +# - distinguish stdout and stderr output +# - add environment variable like assignments +# - run up to a specific line +# - resume at a specific line +# use strict; use FileHandle; @@ -19,20 +28,58 @@ if (isatty(fileno(STDOUT))) { sub exec_test($$); my ($prog, $in, $out) = ([], [], []); -my $line = 0; +my $line_number = 0; my $prog_line; my ($tests, $failed) = (0,0); for (;;) { - my $script = <>; $line++; - if (defined $script) { + my $line = <>; $line_number++; + if (defined $line) { # Substitute %VAR and %{VAR} with environment variables. - $script =~ s[%(?:(\w+)|\{(\w+)\})][$ENV{"$1$2"}]eg; + $line =~ s[%(?:(\w+)|\{(\w+)\})][$ENV{"$1$2"}]eg; + } + if (defined $line) { + if ($line =~ s/^\s*< ?//) { + push @$in, $line; + } elsif ($line =~ s/^\s*> ?//) { + push @$out, $line; + } else { + process_test($prog, $prog_line, $in, $out); + + $prog = []; + $prog_line = 0; + } + if ($line =~ s/^\s*\$ ?//) { + $line =~ s/\s+#.*//; # remove comments here... + $prog = [ map { s/\\(.)/$1/g; $_ } split /(?[$n]) || !defined($result->[$n]) || $out->[$n] ne $result->[$n]) { $good = 0; - #chomp $out->[$n]; - #chomp $result->[$n]; - #print "$out->[$n] != $result->[$n]"; } } $tests++; @@ -57,41 +101,21 @@ for (;;) { chomp $l; my $r = defined($result->[$n]) ? $result->[$n] : "~"; chomp $r; - print sprintf("%-37s | %-39s\n", $l, $r); + print sprintf("%-37s %s %-39s\n", $l, $l eq $r ? '|' : '?', $r); } } elsif ($opt_v) { print join('', @$result); } - } - #$prog = [ split /\s+/, $script ] if $script; - $prog = [ map { s/\\(.)/$1/g; $_ } split /(? ?//) { - push @$in, $script; - } else { - push @$out, $script; - } - last unless defined($script); } -my $status = sprintf("%d commands (%d passed, %d failed)", - $tests, $tests-$failed, $failed); -if (isatty(fileno(STDOUT))) { - if ($failed) { - $status = "\033[31m\033[1m" . $status . "\033[m"; - } else { - $status = "\033[32m" . $status . "\033[m"; - } -} -print $status, "\n"; -exit $failed ? 1 : 0; + sub su($) { my ($user) = @_; + $user ||= "root"; + my ($login, $pass, $uid, $gid) = getpwnam($user) - or return [ "su: user $prog->[1] does not exist\n" ]; + or return [ "su: user $user does not exist\n" ]; my @groups = (); my $fh = new FileHandle("/etc/group") or return [ "opening /etc/group: $!\n" ]; @@ -107,27 +131,58 @@ sub su($) { my $groups = join(" ", ($gid, $gid, @groups)); #print STDERR "[[$groups]]\n"; + $! = 0; # reset errno $> = 0; $( = $gid; $) = $groups; if ($!) { - return [ "setgroups: $!\n" ]; + return [ "su: $!\n" ]; } if ($uid != 0) { $> = $uid; #$< = $uid; if ($!) { - return [ "seteuid: $prog->[1]: $!\n" ]; + return [ "su: $prog->[1]: $!\n" ]; } } #print STDERR "[($>,$<)($(,$))]"; return []; } + +sub sg($) { + my ($group) = @_; + + my $gid = getgrnam($group) + or return [ "sg: group $group does not exist\n" ]; + my %groups = map { $_ eq $gid ? () : ($_ => 1) } (split /\s/, $)); + + #print STDERR "<<", join("/", keys %groups), ">>\n"; + my $groups = join(" ", ($gid, $gid, keys %groups)); + #print STDERR "[[$groups]]\n"; + $! = 0; # reset errno + if ($> != 0) { + my $uid = $>; + $> = 0; + $( = $gid; + $) = $groups; + $> = $uid; + } else { + $( = $gid; + $) = $groups; + } + if ($!) { + return [ "sg: $!\n" ]; + } + print STDERR "[($>,$<)($(,$))]"; + return []; +} + + sub exec_test($$) { my ($prog, $in) = @_; local (*IN, *IN_DUP, *IN2, *OUT_DUP, *OUT, *OUT2); - my $needs_shell = (join('', @$prog) =~ /[|<>"'`\$]/); + my $needs_shell = (join('', @$prog) =~ /[][|<>"'`\$\*\?]/); if ($prog->[0] eq "umask") { umask oct $prog->[1]; @@ -139,15 +194,8 @@ sub exec_test($$) { return []; } elsif ($prog->[0] eq "su") { return su($prog->[1]); - } elsif ($prog->[0] eq "seteuid") { - my $user = $prog->[1]; - my ($login,$pass,$uid,$gid) = getpwnam($user) or - return [ "seteuid: user $prog->[1] does not exist\n" ]; - $> = $uid; - if ($> != $uid) { - return [ "seteuid: $prog->[1]: $!\n" ]; - } - return []; + } elsif ($prog->[0] eq "sg") { + return sg($prog->[1]); } pipe *IN2, *OUT @@ -213,13 +261,12 @@ sub exec_test($$) { open STDERR, ">&STDOUT" or die "Can't join STDOUT and STDERR: $!"; - #print ERR_DUP "<", join(' ', @$prog), ">\n"; if ($needs_shell) { exec ('/bin/sh', '-c', join(" ", @$prog)); } else { exec @$prog; } - print ERR_DUP $prog->[0], ": $!\n"; + print STDERR $prog->[0], ": $!\n"; exit; } } -- cgit