summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/comments.test47
-rw-r--r--test/one.test272
-rw-r--r--test/reorder.test49
-rwxr-xr-xtest/run149
4 files changed, 345 insertions, 172 deletions
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 /(?<!\\)\s+/, $line ];
+ $prog_line = $line_number;
+ $in = [];
+ $out = [];
+ }
+ } else {
+ process_test($prog, $prog_line, $in, $out);
+ last;
}
- next if (defined($script) && $script =~ /^!/);
- if (!defined($script) || $script =~ s/^\$ ?//) {
- if (@$prog) {
- #print "[$prog_line] \$ ", join(' ', @$prog), " -- ";
+}
+
+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 process_test($$$$) {
+ my ($prog, $prog_line, $in, $out) = @_;
+
+ return unless @$prog;
+
my $p = [ @$prog ];
print "[$prog_line] \$ ", join(' ',
map { s/\s/\\$&/g; $_ } @$p), " -- ";
@@ -43,9 +90,6 @@ for (;;) {
if (!defined($out->[$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 /(?<!\\)\s+/, $script ] if $script;
- $prog_line = $line;
- $in = [];
- $out = [];
- } elsif ($script =~ s/^> ?//) {
- 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;
}
}