yields success, test is considered a failure.
This should _not_ be used for tests that succeed when their
- commands fail -- use test_expect_success and shell negation (!) for
- that. test_expect_failure is for cases when a test is known to be
- broken.
+ commands fail -- use test_expect_success and one of general_error,
+ command_error, and conflict for that. test_expect_failure is for
+ cases when a test is known to be broken.
- test_debug <script>
stg id foo@x/y/z//top'
test_expect_success 'Try old id with slashy branch' '
- ! stg id foo/ &&
- ! stg id foo/top &&
- ! stg id foo@x/y/z/top
+ command_error stg id foo/ &&
+ command_error stg id foo/top &&
+ command_error stg id foo@x/y/z/top
'
test_expect_success 'Create patch in slashy branch' \
test_expect_success 'Rename branches' \
'stg branch --rename master goo/gaa &&
- ! git show-ref --verify --quiet refs/heads/master &&
+ must_fail git show-ref --verify --quiet refs/heads/master &&
stg branch --rename goo/gaa x1/x2/x3/x4 &&
- ! git show-ref --verify --quiet refs/heads/goo/gaa &&
+ must_fail git show-ref --verify --quiet refs/heads/goo/gaa &&
stg branch --rename x1/x2/x3/x4 servant &&
- ! git show-ref --verify --quiet refs/heads/x1/x2/x3/x4
+ must_fail git show-ref --verify --quiet refs/heads/x1/x2/x3/x4
'
test_done
C foo/bar
EOF
test_expect_success 'Status after conflicting push' '
- ! stg push &&
+ conflict_old stg push &&
stg status > output.txt &&
test_cmp expected.txt output.txt
'
test_expect_success \
'Try to create an stgit branch with a spurious patches/ entry' '
- ! stg branch -c foo1
+ command_error stg branch -c foo1
'
test_expect_success \
test_expect_success \
'Try to create an stgit branch with an existing git branch by that name' '
- ! stg branch -c foo2
+ command_error stg branch -c foo2
'
test_expect_success \
test_expect_success \
'Create an invalid refs/heads/ entry' '
touch .git/refs/heads/foo3 &&
- ! stg branch -c foo3
+ command_error stg branch -c foo3
'
test_expect_failure \
test_expect_success \
'Create branch down the stack, behind the conflict caused by the generated file' '
- ! stg branch --create foo4 master^
+ command_error stg branch --create foo4 master^
'
test_expect_success \
test_expect_success \
'Rename the current stgit branch' \
- '! stg branch -r foo bar
+ 'command_error stg branch -r foo bar
'
test_expect_success \
test_expect_success \
'Try to create a patch in a GIT branch' \
'
- ! stg new p0 -m "p0"
+ command_error stg new p0 -m "p0"
'
test_expect_success \
test_expect_success \
'Attempt to push the first of those patches without --merged' \
- "(cd bar && ! stg push
+ "(cd bar && conflict_old stg push
)
"
test_expect_success \
'Push the second patch with conflict' \
'
- ! stg push bar
+ conflict_old stg push bar
'
test_expect_success \
test_expect_success \
'Check the push after undo fails as well' \
'
- ! stg push bar
+ conflict_old stg push bar
'
test_expect_success \
test_expect_success \
'Push the first patch with conflict' \
'
- ! stg push foo
+ conflict_old stg push foo
'
test_expect_success \
test_expect_success \
'Check that pop will fail while there are unmerged conflicts' \
'
- ! stg pop
+ command_error stg pop
'
test_expect_success \
[ "$(echo $(cat x.txt))" = "x0" ] &&
[ "$(echo $(cat foo/y.txt))" = "y0" ] &&
cd foo &&
- ! stg push p2 &&
+ conflict_old stg push p2 &&
cd .. &&
[ "$(echo $(stg status --conflict))" = "foo/y.txt x.txt" ]
'
stg pop &&
mkdir -p d &&
echo bar > d/test &&
- ! stg push foo &&
+ command_error stg push foo &&
[ $(stg top) != "foo" ]
'
test_expect_success \
'Repair in a non-initialized repository' \
- '! stg repair'
+ 'command_error stg repair'
test_expect_success \
'Initialize the StGIT repository' \
test_expect_success 'Pop two patches with git-reset' '
git reset --hard HEAD~2 &&
- ! stg refresh &&
+ command_error stg refresh &&
stg repair &&
stg refresh &&
[ "$(echo $(stg applied))" = "p0 p1 p2" ] &&
test_expect_success 'Go to an unapplied patch with with git-reset' '
git reset --hard $(stg id p3) &&
- ! stg refresh &&
+ command_error stg refresh &&
stg repair &&
stg refresh &&
[ "$(echo $(stg applied))" = "p0 p1 p2 p3" ] &&
echo bar > test && stg refresh &&
stg pop &&
echo foo > test && stg refresh &&
- ! stg push &&
+ conflict_old stg push &&
stg log --full | grep -q -e "^push(c) "
'
'
test_expect_success 'sink without applied patches' '
- ! stg sink
+ command_error stg sink
'
test_expect_success 'sink a specific patch without applied patches' '
'Try to delete a non-existing patch' \
'
[ $(stg applied | wc -l) -eq 1 ] &&
- ! stg delete bar &&
+ command_error stg delete bar &&
[ $(stg applied | wc -l) -eq 1 ]
'
'
echo dirty >> foo.txt &&
[ $(stg applied | wc -l) -eq 1 ] &&
- ! stg delete foo &&
+ command_error stg delete foo &&
[ $(stg applied | wc -l) -eq 1 ] &&
git reset --hard
'
'
[ "$(echo $(stg applied))" = "p0 p1 p2" ] &&
[ "$(echo $(stg unapplied))" = "p5 p8 p9" ] &&
- ! stg delete p7 p8 p2 p0 &&
+ command_error stg delete p7 p8 p2 p0 &&
[ "$(echo $(stg applied))" = "p0 p1 p2" ] &&
[ "$(echo $(stg unapplied))" = "p5 p8 p9" ]
'
test_expect_success \
'Synchronise the first two patches with the master branch (to fail)' \
'
- ! stg sync -B master -a
+ conflict_old stg sync -B master -a
'
test_expect_success \
test_expect_success \
'Synchronise the third patch with the exported series (to fail)' \
'
- ! stg sync -s patches-master/series p3
+ conflict_old stg sync -s patches-master/series p3
'
test_expect_success \
'Rewind/rewrite upstream commit and pull it from clone, without --merged' \
'
(cd upstream && echo b >> file2 && stg refresh) &&
- (cd clone && ! stg pull)
+ (cd clone && conflict_old stg pull)
'
test_expect_success \
test_expect_success \
'Attempt rebase to non-existing commit' \
'
- ! stg rebase not-a-ref
+ command_error stg rebase not-a-ref
'
test_expect_success \
stg new p2 -m p2
echo quux > foo.txt &&
stg refresh &&
- ! stg push
+ conflict_old stg push
'
test_expect_success 'Make sure conflicting patches are preserved' '
stg init
test_expect_success 'Rename in empty' '
- ! stg rename foo
+ command_error stg rename foo
'
test_expect_success 'Rename single top-most' '
# bar
test_expect_success 'Rename non-existing' '
- ! stg rename neithersuchpatch norsuchpatch
+ command_error stg rename neithersuchpatch norsuchpatch
'
test_expect_success 'Rename with two arguments' '
# foo,baz
test_expect_success 'Rename to existing name' '
- ! stg rename foo baz
+ command_error stg rename foo baz
'
test_expect_success 'Rename to same name' '
- ! stg rename foo foo
+ command_error stg rename foo foo
'
test_expect_success 'Rename top-most when others exist' '
echo 4 > a &&
[ "$(echo $(stg applied))" = "p1" ] &&
[ "$(echo $(stg unapplied))" = "p2" ] &&
- ! stg goto p2 &&
+ conflict stg goto p2 &&
[ "$(echo $(stg applied))" = "p1" ] &&
[ "$(echo $(stg unapplied))" = "p2" ] &&
[ "$(echo $(cat a))" = "4" ]
test_expect_success \
"v$ver: Make sure the base ref is no longer there" '
- ! git show-ref --verify --quiet refs/bases/master
+ must_fail git show-ref --verify --quiet refs/bases/master
'
cd ..
echo >&3 ""
}
+# When running an StGit command that should exit with an error, use
+# these instead of testing for any non-zero exit code with !.
+exit_code () {
+ expected=$1
+ shift
+ "$@"
+ test $? -eq $expected
+}
+general_error () { exit_code 1 "$@" ; }
+command_error () { exit_code 2 "$@" ; }
+conflict () { exit_code 3 "$@" ; }
+
+# Old-infrastructure commands don't exit with the proper value on
+# conflicts. But we don't want half the tests to fail because of that,
+# so use this instead of "conflict" for them.
+conflict_old () { command_error "$@" ; }
+
+# Same thing, but for other commands that StGit where we just want to
+# make sure that they fail instead of crashing.
+must_fail () {
+ "$@"
+ test $? -gt 0 -a $? -le 129
+}
+
# test_cmp is a helper function to compare actual and expected output.
# You can use it like:
#