[PATCH v9 2/2] improve tests
From: Harald Nordgren <haraldnordgren@gmail.com>
Simplify tests based on feedback.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
t/t6040-tracking-info.sh | 249 +++++++++++++++++++--------------------
1 file changed, 124 insertions(+), 125 deletions(-)
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index fe34ddf0ab..a875b4c73b 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -308,45 +308,44 @@ test_expect_success 'setup for ahead of non-main tracking branch' '
test_expect_success 'status shows ahead of both tracked branch and origin/main' '
(
cd test &&
- git checkout work >/dev/null &&
+ git checkout work &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work
-Your branch is ahead of '\''origin/feature'\'' by 2 commits.
- (use "git push" to publish your local commits)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work
+ Your branch is ahead of ${SQ}origin/feature${SQ} by 2 commits.
+ (use "git push" to publish your local commits)
-Ahead of '\''origin/main'\'' by 3 commits.
+ Ahead of ${SQ}origin/main${SQ} by 3 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
test_expect_success 'checkout shows ahead of both tracked branch and origin/main' '
(
cd test &&
- git checkout main >/dev/null &&
+ git checkout main &&
git config status.goalBranch origin/main &&
- git checkout work 2>&1
- ) >actual &&
- cat >expect <<-\EOF &&
-Switched to branch '\''work'\''
-Your branch is ahead of '\''origin/feature'\'' by 2 commits.
- (use "git push" to publish your local commits)
+ git checkout work >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ Your branch is ahead of ${SQ}origin/feature${SQ} by 2 commits.
+ (use "git push" to publish your local commits)
-Ahead of '\''origin/main'\'' by 3 commits.
-EOF
+ Ahead of ${SQ}origin/main${SQ} by 3 commits.
+ EOF
test_cmp expect actual
'
test_expect_success 'status tracking origin/main shows only main' '
(
cd test &&
- git checkout b4 >/dev/null &&
- git status --long -b
- ) >actual &&
+ git checkout b4 &&
+ git status >../actual
+ ) &&
test_grep "ahead of .origin/main. by 2 commits" actual &&
test_grep ! "Ahead of" actual
'
@@ -369,19 +368,19 @@ test_expect_success 'setup for ahead of tracked but diverged from main' '
test_expect_success 'status shows ahead of tracked and diverged from origin/main' '
(
cd test &&
- git checkout work2 >/dev/null &&
+ git checkout work2 &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work2
-Your branch is ahead of '\''origin/oldfeature'\'' by 1 commit.
- (use "git push" to publish your local commits)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work2
+ Your branch is ahead of ${SQ}origin/oldfeature${SQ} by 1 commit.
+ (use "git push" to publish your local commits)
-Diverged from '\''origin/main'\'' by 3 commits.
+ Diverged from ${SQ}origin/main${SQ} by 3 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -401,20 +400,20 @@ test_expect_success 'setup for diverged from tracked but behind main' '
test_expect_success 'status shows diverged from tracked and behind origin/main' '
(
cd test &&
- git checkout work2b >/dev/null &&
+ git checkout work2b &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work2b
-Your branch and '\''origin/oldfeature'\'' have diverged,
-and have 1 and 1 different commits each, respectively.
- (use "git pull" if you want to integrate the remote branch with yours)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work2b
+ Your branch and ${SQ}origin/oldfeature${SQ} have diverged,
+ and have 1 and 1 different commits each, respectively.
+ (use "git pull" if you want to integrate the remote branch with yours)
-Behind '\''origin/main'\'' by 1 commit.
+ Behind ${SQ}origin/main${SQ} by 1 commit.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -436,19 +435,19 @@ test_expect_success 'setup for behind tracked but ahead of main' '
test_expect_success 'status shows behind tracked and ahead of origin/main' '
(
cd test &&
- git checkout work3 >/dev/null &&
+ git checkout work3 &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work3
-Your branch is behind '\''origin/feature3'\'' by 2 commits, and can be fast-forwarded.
- (use "git pull" to update your local branch)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work3
+ Your branch is behind ${SQ}origin/feature3${SQ} by 2 commits, and can be fast-forwarded.
+ (use "git pull" to update your local branch)
-Ahead of '\''origin/main'\'' by 1 commit.
+ Ahead of ${SQ}origin/main${SQ} by 1 commit.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -464,19 +463,19 @@ test_expect_success 'setup upstream remote preference' '
test_expect_success 'status prefers upstream remote over origin for comparison' '
(
cd test &&
- git checkout work >/dev/null &&
+ git checkout work &&
git config status.goalBranch upstream/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work
-Your branch is ahead of '\''origin/feature'\'' by 2 commits.
- (use "git push" to publish your local commits)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work
+ Your branch is ahead of ${SQ}origin/feature${SQ} by 2 commits.
+ (use "git push" to publish your local commits)
-Diverged from '\''upstream/main'\'' by 5 commits.
+ Diverged from ${SQ}upstream/main${SQ} by 5 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -494,18 +493,18 @@ test_expect_success 'setup for up to date with tracked but ahead of default' '
test_expect_success 'status shows up to date with tracked but diverged from default' '
(
cd test &&
- git checkout synced_feature >/dev/null &&
+ git checkout synced_feature &&
git config status.goalBranch upstream/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature
-Your branch is up to date with '\''origin/feature'\''.
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-Diverged from '\''upstream/main'\'' by 3 commits.
+ Diverged from ${SQ}upstream/main${SQ} by 3 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -524,18 +523,18 @@ test_expect_success 'setup for up to date with tracked but ahead of origin/main'
test_expect_success 'status shows up to date with tracked but diverged from origin/main' '
(
cd test &&
- git checkout synced_feature2 >/dev/null &&
+ git checkout synced_feature2 &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature2
-Your branch is up to date with '\''origin/feature'\''.
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature2
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-Diverged from '\''origin/main'\'' by 5 commits.
+ Diverged from ${SQ}origin/main${SQ} by 5 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
@@ -550,85 +549,85 @@ test_expect_success 'setup for up to date with tracked but purely ahead of origi
test_expect_success 'status shows up to date with tracked but shows default branch comparison' '
(
cd test &&
- git checkout synced_feature3 >/dev/null &&
+ git checkout synced_feature3 &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature3
-Your branch is up to date with '\''origin/feature'\''.
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature3
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-Diverged from '\''origin/main'\'' by 5 commits.
+ Diverged from ${SQ}origin/main${SQ} by 5 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
test_expect_success 'status with status.goalBranch unset shows no default comparison' '
(
cd test &&
- git checkout synced_feature3 >/dev/null &&
- git config --unset status.goalBranch 2>/dev/null || true &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature3
-Your branch is up to date with '\''origin/feature'\''.
+ git checkout synced_feature3 &&
+ git config --unset status.goalBranch || true &&
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature3
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
test_expect_success 'status with status.goalBranch set uses configured branch' '
(
cd test &&
- git checkout synced_feature3 >/dev/null &&
+ git checkout synced_feature3 &&
git config status.goalBranch origin/main &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature3
-Your branch is up to date with '\''origin/feature'\''.
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature3
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-Diverged from '\''origin/main'\'' by 5 commits.
+ Diverged from ${SQ}origin/main${SQ} by 5 commits.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
test_expect_success 'status with status.goalBranch set to different remote/branch' '
(
cd test &&
- git checkout work >/dev/null &&
+ git checkout work &&
git config status.goalBranch origin/feature &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch work
-Your branch is ahead of '\''origin/feature'\'' by 2 commits.
- (use "git push" to publish your local commits)
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch work
+ Your branch is ahead of ${SQ}origin/feature${SQ} by 2 commits.
+ (use "git push" to publish your local commits)
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
test_expect_success 'status with status.goalBranch set to non-existent branch' '
(
cd test &&
- git checkout synced_feature3 >/dev/null &&
+ git checkout synced_feature3 &&
git config status.goalBranch origin/nonexistent &&
- git status --long -b
- ) >actual &&
- cat >expect <<-\EOF &&
-On branch synced_feature3
-Your branch is up to date with '\''origin/feature'\''.
+ git status >../actual
+ ) &&
+ cat >expect <<-EOF &&
+ On branch synced_feature3
+ Your branch is up to date with ${SQ}origin/feature${SQ}.
-nothing to commit, working tree clean
-EOF
+ nothing to commit, working tree clean
+ EOF
test_cmp expect actual
'
--
gitgitgadget