t3200: test for specific errors
In the "--set-upstream-to" and "--unset-upstream" tests, specific error conditions are being tested. However, there is no way of ensuring that a test case is failing because of some specific error. Check stderr of failing commands to ensure that they are failing in the expected way. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Jun 15, 2020 at 07:53 UTC
6b7093064a8db318bb18272a064590d558998dbf
1 file changed
+32
-13
t/t3200-branch.sh
+32
-13
@@ -835,32 +835,42 @@ test_expect_success 'branch from tag w/--track causes failure' '
835
'
836
837
test_expect_success '--set-upstream-to fails on multiple branches' '
838
- test_must_fail git branch --set-upstream-to master a b c
838
+ echo "fatal: too many arguments to set new upstream" >expect &&
839
+ test_must_fail git branch --set-upstream-to master a b c 2>err &&
840
+ test_i18ncmp expect err
841
'
842
843
test_expect_success '--set-upstream-to fails on detached HEAD' '
844
git checkout HEAD^{} &&
843
- test_must_fail git branch --set-upstream-to master &&
844
- git checkout -
845
+ test_when_finished git checkout - &&
846
+ echo "fatal: could not set upstream of HEAD to master when it does not point to any branch." >expect &&
847
+ test_must_fail git branch --set-upstream-to master 2>err &&
848
+ test_i18ncmp expect err
849
'
850
851
test_expect_success '--set-upstream-to fails on a missing dst branch' '
848
- test_must_fail git branch --set-upstream-to master does-not-exist
852
+ echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
853
+ test_must_fail git branch --set-upstream-to master does-not-exist 2>err &&
854
+ test_i18ncmp expect err
855
'
856
857
test_expect_success '--set-upstream-to fails on a missing src branch' '
852
- test_must_fail git branch --set-upstream-to does-not-exist master
858
+ test_must_fail git branch --set-upstream-to does-not-exist master 2>err &&
859
+ test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
860
'
861
862
test_expect_success '--set-upstream-to fails on a non-ref' '
856
- test_must_fail git branch --set-upstream-to HEAD^{}
863
+ echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect &&
864
+ test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
865
+ test_i18ncmp expect err
866
'
867
868
test_expect_success '--set-upstream-to fails on locked config' '
869
test_when_finished "rm -f .git/config.lock" &&
870
>.git/config.lock &&
871
git branch locked &&
863
- test_must_fail git branch --set-upstream-to locked
872
+ test_must_fail git branch --set-upstream-to locked 2>err &&
873
+ test_i18ngrep "could not lock config file .git/config: File exists" err
874
'
875
876
test_expect_success 'use --set-upstream-to modify HEAD' '
@@ -881,14 +891,17 @@ test_expect_success 'use --set-upstream-to modify a particular branch' '
891
'
892
893
test_expect_success '--unset-upstream should fail if given a non-existent branch' '
884
- test_must_fail git branch --unset-upstream i-dont-exist
894
+ echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
895
+ test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
896
+ test_i18ncmp expect err
897
'
898
899
test_expect_success '--unset-upstream should fail if config is locked' '
900
test_when_finished "rm -f .git/config.lock" &&
901
git branch --set-upstream-to locked &&
902
>.git/config.lock &&
891
- test_must_fail git branch --unset-upstream
903
+ test_must_fail git branch --unset-upstream 2>err &&
904
+ test_i18ngrep "could not lock config file .git/config: File exists" err
905
'
906
907
test_expect_success 'test --unset-upstream on HEAD' '
@@ -900,17 +913,23 @@ test_expect_success 'test --unset-upstream on HEAD' '
913
test_must_fail git config branch.master.remote &&
914
test_must_fail git config branch.master.merge &&
915
# fail for a branch without upstream set
903
- test_must_fail git branch --unset-upstream
916
+ echo "fatal: Branch '"'"'master'"'"' has no upstream information" >expect &&
917
+ test_must_fail git branch --unset-upstream 2>err &&
918
+ test_i18ncmp expect err
919
'
920
921
test_expect_success '--unset-upstream should fail on multiple branches' '
907
- test_must_fail git branch --unset-upstream a b c
922
+ echo "fatal: too many arguments to unset upstream" >expect &&
923
+ test_must_fail git branch --unset-upstream a b c 2>err &&
924
+ test_i18ncmp expect err
925
'
926
927
test_expect_success '--unset-upstream should fail on detached HEAD' '
928
git checkout HEAD^{} &&
912
- test_must_fail git branch --unset-upstream &&
913
- git checkout -
929
+ test_when_finished git checkout - &&
930
+ echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
931
+ test_must_fail git branch --unset-upstream 2>err &&
932
+ test_i18ncmp expect err
933
'
934
935
test_expect_success 'test --unset-upstream on a particular branch' '