Test+fix for bug 11887 (stg sink)
cover Test+fix for bug 11887 (stg sink)
This should go on the stable branch, of course.
---
Karl Hasselström (2):
Fix "stg sink" with no applied patches (bug 11887) Try "stg sink" without applied patches
stgit/commands/sink.py | 8 ++++++-- t/t1501-sink.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100755 t/t1501-sink.sh
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/2 Try "stg sink" without applied patches
It doesn't work, neither with an implicit nor an explicit patch to sink. This is bug 11887 in the bug tracker.
(The implicit sink testcase actually passes, but that's just because the test suite can't distinguish between a program bug and an orderly abort.)
The test was adapted from the script attached to the bug report, written by Erik Sandberg.
---
t/t1501-sink.sh | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) create mode 100755 t/t1501-sink.sh
t/t1501-sink.sh new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/sh + +test_description='Test "stg sink"' + +. ./test-lib.sh + +test_expect_success 'Initialize StGit stack' ' + echo 000 >> x && + git add x && + git commit -m initial && + echo 000 >> y && + git add y && + git commit -m y && + stg init && + stg uncommit && + stg pop +' + +test_expect_success 'sink without applied patches' ' + ! stg sink +' + +test_expect_failure 'sink a specific patch without applied patches' ' + stg sink y && + test $(echo $(stg applied)) = "y" +' + +test_done
Re: [StGit PATCH 1/2] Try "stg sink" without applied patches
Quoted 3 lines · Karl Hasselström
(The implicit sink testcase actually passes, but that's just because the test suite can't distinguish between a program bug and an orderly abort.)
Yes it can, that's where "test_must_fail" comes in.
<snip>
t/t1501-sink.sh line 22
Quoted 4 lines
t/t1501-sink.sh new file +4
-0+test_expect_success 'sink without applied patches' ' + test_must_fail stg sink +' +
Like that.
Signature · 3 lines
Cheers, Sverre Rabbelier
Re: [StGit PATCH 1/2] Try "stg sink" without applied patches
Quoted 6 lines · Sverre Rabbelier
Quoted 3 lines · Karl Hasselström
(The implicit sink testcase actually passes, but that's just because the test suite can't distinguish between a program bug and an orderly abort.)
Quoted 8 lines
Yes it can, that's where "
test_must_fail" comes in.t/t1501-sink.sh line 22
Quoted 4 lines
t/t1501-sink.sh new file +4
-0+test_expect_success 'sink without applied patches' ' + test_must_fail stg sink +' +Like that.
Well, except that
1. test_must_fail doesn't even exist in StGit's test-lib.sh, because I've omitted it on purpose when stealing good stuff from git's test-lib.sh, because
2. StGit is written in Python, so random bugs virtually never cause segfaults and stuff, they just raise various exceptions.
That said, StGit (especially in the master branch -- but this patch was against stable, where this is much less true) does exit with different exit codes depending on what kind of exception interrupted the program, and all exceptions not on a certain list cause it to exit with an exit code that means there's a bug (see the end of stgit/main.py for details). So writing a test_must_fail with sane behavior is perfectly doable and not actually all that hard.
Patch? :-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 2/2 Fix "stg sink" with no applied patches (bug 11887)
In reply to Karl HasselströmThere were two separate things to fix: bail out if we need a current patch and there isn't one (because there are no applied patches), and make sure we don't try to pop patches that don't exist.
---
stgit/commands/sink.py | 8 ++++++-- t/t1501-sink.sh | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-)
stgit/commands/sink.py +6 -2
@@ -58,9 +58,13 @@ def func(parser, options, args): if len(args) > 0: patches = parse_patches(args, all) else: - patches = [ crt_series.get_current() ] + current = crt_series.get_current() + if not current: + raise CmdException('No patch applied') + patches = [current] - crt_series.pop_patch(options.to or oldapplied[0]) + if oldapplied: + crt_series.pop_patch(options.to or oldapplied[0]) push_patches(crt_series, patches) if not options.nopush:
t/t1501-sink.sh +1 -1
@@ -20,7 +20,7 @@ test_expect_success 'sink without applied patches' ' ! stg sink ' -test_expect_failure 'sink a specific patch without applied patches' ' +test_expect_success 'sink a specific patch without applied patches' ' stg sink y && test $(echo $(stg applied)) = "y" '