From 19d0048cc486b087ca938a14ce2be91ea0f0a3ae Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 4 May 2024 12:35:57 +0200 Subject: More explicit test of status panel content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use Equals instead of Contains for asserting the status view content. This solves the problem that we might assert Contains("↓2 repo"), but what it really shows is "↑1↓2 repo", and the test still succeeds. At best this is confusing. Also, this way we don't have to use the awkward DoesNotContain to check that it really doesn't show a checkmark. To do this, we need to fix two whitespace problems: - there was always a space at the end for no reason. Simply remove it. It was added in efb51eee96, but from looking at that diff it seems it was added accidentally. - there was a space at the beginning if the branch status was empty. This is actually a cosmetic problem, for branches without a status the text was indented by once space. Change this so that the space is added conditionally. It's a bit awkward that we have to use Decolorise here, but this will go away again later in this branch. --- pkg/gui/presentation/status.go | 8 ++++++-- .../tests/branch/delete_remote_branch_with_credential_prompt.go | 6 +++--- pkg/integration/tests/sync/force_push.go | 4 ++-- pkg/integration/tests/sync/force_push_multiple_matching.go | 4 ++-- pkg/integration/tests/sync/force_push_multiple_upstream.go | 4 ++-- pkg/integration/tests/sync/pull.go | 4 ++-- pkg/integration/tests/sync/pull_and_set_upstream.go | 4 ++-- pkg/integration/tests/sync/pull_merge.go | 4 ++-- pkg/integration/tests/sync/pull_merge_conflict.go | 4 ++-- pkg/integration/tests/sync/pull_rebase.go | 4 ++-- pkg/integration/tests/sync/pull_rebase_conflict.go | 4 ++-- pkg/integration/tests/sync/pull_rebase_interactive_conflict.go | 4 ++-- .../tests/sync/pull_rebase_interactive_conflict_drop.go | 4 ++-- pkg/integration/tests/sync/push.go | 2 +- pkg/integration/tests/sync/push_and_auto_set_upstream.go | 2 +- pkg/integration/tests/sync/push_and_set_upstream.go | 2 +- pkg/integration/tests/sync/push_follow_tags.go | 4 ++-- pkg/integration/tests/sync/push_no_follow_tags.go | 4 ++-- pkg/integration/tests/sync/push_with_credential_prompt.go | 6 +++--- pkg/integration/tests/sync/shared.go | 2 +- 20 files changed, 42 insertions(+), 38 deletions(-) (limited to 'pkg') diff --git a/pkg/gui/presentation/status.go b/pkg/gui/presentation/status.go index d3686510e..5ac591c48 100644 --- a/pkg/gui/presentation/status.go +++ b/pkg/gui/presentation/status.go @@ -10,6 +10,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/i18n" + "github.com/jesseduffield/lazygit/pkg/utils" ) func FormatStatus( @@ -24,7 +25,10 @@ func FormatStatus( status := "" if currentBranch.IsRealBranch() { - status += ColoredBranchStatus(currentBranch, itemOperation, tr, userConfig) + " " + status += ColoredBranchStatus(currentBranch, itemOperation, tr, userConfig) + if utils.Decolorise(status) != "" { + status += " " + } } if workingTreeState != enums.REBASE_MODE_NONE { @@ -40,7 +44,7 @@ func FormatStatus( } repoName = fmt.Sprintf("%s(%s%s)", repoName, icon, style.FgCyan.Sprint(linkedWorktreeName)) } - status += fmt.Sprintf("%s → %s ", repoName, name) + status += fmt.Sprintf("%s → %s", repoName, name) return status } diff --git a/pkg/integration/tests/branch/delete_remote_branch_with_credential_prompt.go b/pkg/integration/tests/branch/delete_remote_branch_with_credential_prompt.go index ad8f70c43..6e3f52028 100644 --- a/pkg/integration/tests/branch/delete_remote_branch_with_credential_prompt.go +++ b/pkg/integration/tests/branch/delete_remote_branch_with_credential_prompt.go @@ -44,7 +44,7 @@ var DeleteRemoteBranchWithCredentialPrompt = NewIntegrationTest(NewIntegrationTe Confirm() } - t.Views().Status().Content(Contains("✓ repo → mybranch")) + t.Views().Status().Content(Equals("✓ repo → mybranch")) deleteBranch() @@ -66,7 +66,7 @@ var DeleteRemoteBranchWithCredentialPrompt = NewIntegrationTest(NewIntegrationTe Content(Contains("incorrect username/password")). Confirm() - t.Views().Status().Content(Contains("✓ repo → mybranch")) + t.Views().Status().Content(Equals("✓ repo → mybranch")) // try again with correct password deleteBranch() @@ -81,7 +81,7 @@ var DeleteRemoteBranchWithCredentialPrompt = NewIntegrationTest(NewIntegrationTe Type("password"). Confirm() - t.Views().Status().Content(Contains("repo → mybranch").DoesNotContain("✓")) + t.Views().Status().Content(Equals("(upstream gone) repo → mybranch")) t.Views().Branches().TopLines(Contains("mybranch (upstream gone)")) }, }) diff --git a/pkg/integration/tests/sync/force_push.go b/pkg/integration/tests/sync/force_push.go index 89d8a8371..e563cfd28 100644 --- a/pkg/integration/tests/sync/force_push.go +++ b/pkg/integration/tests/sync/force_push.go @@ -26,7 +26,7 @@ var ForcePush = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓1 repo → master")) + t.Views().Status().Content(Equals("↓1 repo → master")) t.Views().Files().IsFocused().Press(keys.Universal.Push) @@ -40,7 +40,7 @@ var ForcePush = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Remotes().Focus(). Lines(Contains("origin")). diff --git a/pkg/integration/tests/sync/force_push_multiple_matching.go b/pkg/integration/tests/sync/force_push_multiple_matching.go index 37c43f264..63825ee4f 100644 --- a/pkg/integration/tests/sync/force_push_multiple_matching.go +++ b/pkg/integration/tests/sync/force_push_multiple_matching.go @@ -22,7 +22,7 @@ var ForcePushMultipleMatching = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓1 repo → master")) + t.Views().Status().Content(Equals("↓1 repo → master")) t.Views().Branches(). Lines( @@ -42,7 +42,7 @@ var ForcePushMultipleMatching = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Branches(). Lines( diff --git a/pkg/integration/tests/sync/force_push_multiple_upstream.go b/pkg/integration/tests/sync/force_push_multiple_upstream.go index 1ea512720..8c55b7e8c 100644 --- a/pkg/integration/tests/sync/force_push_multiple_upstream.go +++ b/pkg/integration/tests/sync/force_push_multiple_upstream.go @@ -21,7 +21,7 @@ var ForcePushMultipleUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓1 repo → master")) + t.Views().Status().Content(Equals("↓1 repo → master")) t.Views().Branches(). Lines( @@ -41,7 +41,7 @@ var ForcePushMultipleUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Branches(). Lines( diff --git a/pkg/integration/tests/sync/pull.go b/pkg/integration/tests/sync/pull.go index 7f5703791..b30cbb408 100644 --- a/pkg/integration/tests/sync/pull.go +++ b/pkg/integration/tests/sync/pull.go @@ -26,7 +26,7 @@ var Pull = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓1 repo → master")) + t.Views().Status().Content(Equals("↓1 repo → master")) t.Views().Files().IsFocused().Press(keys.Universal.Pull) @@ -36,6 +36,6 @@ var Pull = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) }, }) diff --git a/pkg/integration/tests/sync/pull_and_set_upstream.go b/pkg/integration/tests/sync/pull_and_set_upstream.go index b2dbfddb4..acffa24be 100644 --- a/pkg/integration/tests/sync/pull_and_set_upstream.go +++ b/pkg/integration/tests/sync/pull_and_set_upstream.go @@ -25,7 +25,7 @@ var PullAndSetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("repo → master")) + t.Views().Status().Content(Equals("repo → master")) t.Views().Files().IsFocused().Press(keys.Universal.Pull) @@ -40,6 +40,6 @@ var PullAndSetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) }, }) diff --git a/pkg/integration/tests/sync/pull_merge.go b/pkg/integration/tests/sync/pull_merge.go index d9c9e107d..d4809f00e 100644 --- a/pkg/integration/tests/sync/pull_merge.go +++ b/pkg/integration/tests/sync/pull_merge.go @@ -33,13 +33,13 @@ var PullMerge = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑1↓2 repo → master")) t.Views().Files(). IsFocused(). Press(keys.Universal.Pull) - t.Views().Status().Content(Contains("↑2 repo → master")) + t.Views().Status().Content(Equals("↑2 repo → master")) t.Views().Commits(). Lines( diff --git a/pkg/integration/tests/sync/pull_merge_conflict.go b/pkg/integration/tests/sync/pull_merge_conflict.go index 3177cabe5..6e05fafae 100644 --- a/pkg/integration/tests/sync/pull_merge_conflict.go +++ b/pkg/integration/tests/sync/pull_merge_conflict.go @@ -34,7 +34,7 @@ var PullMergeConflict = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑1↓2 repo → master")) t.Views().Files(). IsFocused(). @@ -62,7 +62,7 @@ var PullMergeConflict = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().ContinueOnConflictsResolved() - t.Views().Status().Content(Contains("↑2 repo → master")) + t.Views().Status().Content(Equals("↑2 repo → master")) t.Views().Commits(). Focus(). diff --git a/pkg/integration/tests/sync/pull_rebase.go b/pkg/integration/tests/sync/pull_rebase.go index 77810426e..158cdf3d3 100644 --- a/pkg/integration/tests/sync/pull_rebase.go +++ b/pkg/integration/tests/sync/pull_rebase.go @@ -35,13 +35,13 @@ var PullRebase = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑1↓2 repo → master")) t.Views().Files(). IsFocused(). Press(keys.Universal.Pull) - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Commits(). Lines( diff --git a/pkg/integration/tests/sync/pull_rebase_conflict.go b/pkg/integration/tests/sync/pull_rebase_conflict.go index 3b6c83b85..fa2920b7b 100644 --- a/pkg/integration/tests/sync/pull_rebase_conflict.go +++ b/pkg/integration/tests/sync/pull_rebase_conflict.go @@ -34,7 +34,7 @@ var PullRebaseConflict = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑1↓2 repo → master")) t.Views().Files(). IsFocused(). @@ -63,7 +63,7 @@ var PullRebaseConflict = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().ContinueOnConflictsResolved() - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Commits(). Focus(). diff --git a/pkg/integration/tests/sync/pull_rebase_interactive_conflict.go b/pkg/integration/tests/sync/pull_rebase_interactive_conflict.go index a6a3f5356..e93ca2e37 100644 --- a/pkg/integration/tests/sync/pull_rebase_interactive_conflict.go +++ b/pkg/integration/tests/sync/pull_rebase_interactive_conflict.go @@ -38,7 +38,7 @@ var PullRebaseInteractiveConflict = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑2↓2 repo → master")) t.Views().Files(). IsFocused(). @@ -76,7 +76,7 @@ var PullRebaseInteractiveConflict = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().ContinueOnConflictsResolved() - t.Views().Status().Content(Contains("↑2 repo → master")) + t.Views().Status().Content(Equals("↑2 repo → master")) t.Views().Commits(). Focus(). diff --git a/pkg/integration/tests/sync/pull_rebase_interactive_conflict_drop.go b/pkg/integration/tests/sync/pull_rebase_interactive_conflict_drop.go index b53790964..eba3ba746 100644 --- a/pkg/integration/tests/sync/pull_rebase_interactive_conflict_drop.go +++ b/pkg/integration/tests/sync/pull_rebase_interactive_conflict_drop.go @@ -38,7 +38,7 @@ var PullRebaseInteractiveConflictDrop = NewIntegrationTest(NewIntegrationTestArg Contains("one"), ) - t.Views().Status().Content(Contains("↓2 repo → master")) + t.Views().Status().Content(Equals("↑2↓2 repo → master")) t.Views().Files(). IsFocused(). @@ -85,7 +85,7 @@ var PullRebaseInteractiveConflictDrop = NewIntegrationTest(NewIntegrationTestArg t.Common().ContinueOnConflictsResolved() - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Commits(). Focus(). diff --git a/pkg/integration/tests/sync/push.go b/pkg/integration/tests/sync/push.go index ea27b399c..cb1e11aa9 100644 --- a/pkg/integration/tests/sync/push.go +++ b/pkg/integration/tests/sync/push.go @@ -21,7 +21,7 @@ var Push = NewIntegrationTest(NewIntegrationTestArgs{ shell.EmptyCommit("two") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Files(). IsFocused(). diff --git a/pkg/integration/tests/sync/push_and_auto_set_upstream.go b/pkg/integration/tests/sync/push_and_auto_set_upstream.go index c3f58d644..d8a336ea4 100644 --- a/pkg/integration/tests/sync/push_and_auto_set_upstream.go +++ b/pkg/integration/tests/sync/push_and_auto_set_upstream.go @@ -22,7 +22,7 @@ var PushAndAutoSetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(t *TestDriver, keys config.KeybindingConfig) { // assert no mention of upstream/downstream changes - t.Views().Status().Content(MatchesRegexp(`^\s+repo → master`)) + t.Views().Status().Content(Equals("repo → master")) t.Views().Files(). IsFocused(). diff --git a/pkg/integration/tests/sync/push_and_set_upstream.go b/pkg/integration/tests/sync/push_and_set_upstream.go index 0521c4b21..d900452eb 100644 --- a/pkg/integration/tests/sync/push_and_set_upstream.go +++ b/pkg/integration/tests/sync/push_and_set_upstream.go @@ -19,7 +19,7 @@ var PushAndSetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(t *TestDriver, keys config.KeybindingConfig) { // assert no mention of upstream/downstream changes - t.Views().Status().Content(MatchesRegexp(`^\s+repo → master`)) + t.Views().Status().Content(Equals("repo → master")) t.Views().Files(). IsFocused(). diff --git a/pkg/integration/tests/sync/push_follow_tags.go b/pkg/integration/tests/sync/push_follow_tags.go index 463172abf..c293cf005 100644 --- a/pkg/integration/tests/sync/push_follow_tags.go +++ b/pkg/integration/tests/sync/push_follow_tags.go @@ -24,13 +24,13 @@ var PushFollowTags = NewIntegrationTest(NewIntegrationTestArgs{ shell.SetConfig("push.followTags", "true") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Files(). IsFocused(). Press(keys.Universal.Push) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Remotes(). Focus(). diff --git a/pkg/integration/tests/sync/push_no_follow_tags.go b/pkg/integration/tests/sync/push_no_follow_tags.go index 599d05a64..18a1cf62d 100644 --- a/pkg/integration/tests/sync/push_no_follow_tags.go +++ b/pkg/integration/tests/sync/push_no_follow_tags.go @@ -22,13 +22,13 @@ var PushNoFollowTags = NewIntegrationTest(NewIntegrationTestArgs{ shell.CreateAnnotatedTag("mytag", "message", "HEAD") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Files(). IsFocused(). Press(keys.Universal.Push) - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Remotes(). Focus(). diff --git a/pkg/integration/tests/sync/push_with_credential_prompt.go b/pkg/integration/tests/sync/push_with_credential_prompt.go index 79d7fcc1d..62be89bf4 100644 --- a/pkg/integration/tests/sync/push_with_credential_prompt.go +++ b/pkg/integration/tests/sync/push_with_credential_prompt.go @@ -26,7 +26,7 @@ var PushWithCredentialPrompt = NewIntegrationTest(NewIntegrationTestArgs{ shell.CopyHelpFile("pre-push", ".git/hooks/pre-push") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) t.Views().Files(). IsFocused(). @@ -50,7 +50,7 @@ var PushWithCredentialPrompt = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("incorrect username/password")). Confirm() - t.Views().Status().Content(Contains("↑1 repo → master")) + t.Views().Status().Content(Equals("↑1 repo → master")) // try again with correct password t.Views().Files(). @@ -67,7 +67,7 @@ var PushWithCredentialPrompt = NewIntegrationTest(NewIntegrationTestArgs{ Type("password"). Confirm() - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) assertSuccessfullyPushed(t) }, diff --git a/pkg/integration/tests/sync/shared.go b/pkg/integration/tests/sync/shared.go index 8ea9a6c25..3e3d5c017 100644 --- a/pkg/integration/tests/sync/shared.go +++ b/pkg/integration/tests/sync/shared.go @@ -24,7 +24,7 @@ func createTwoBranchesReadyToForcePush(shell *Shell) { } func assertSuccessfullyPushed(t *TestDriver) { - t.Views().Status().Content(Contains("✓ repo → master")) + t.Views().Status().Content(Equals("✓ repo → master")) t.Views().Remotes(). Focus(). -- cgit v1.2.3