testing/git-bug: fix tests

This commit is contained in:
Sören Tempel 2023-07-13 00:57:57 +02:00
parent b24a23f141
commit c1f9a42614
2 changed files with 42 additions and 1 deletions

View file

@ -10,9 +10,9 @@ license="GPL-3.0-or-later"
makedepends="go"
source="
git-bug-$pkgver.tar.gz::https://github.com/MichaelMure/git-bug/archive/v$pkgver.tar.gz
fix-tests.patch
Makefile.patch
"
options="!check" # fail for some reason
export GIT_COMMIT=v$pkgver
export GIT_LAST_TAG=v$pkgver
@ -37,5 +37,6 @@ package() {
sha512sums="
85456c916f72c0d2764ccd09418d2db91a9aeed48182de12d6aaec7cd021c55ec323822e4aa9347739cfe232ff2287e1bc7adca37ff2574d822b78fc75121d83 git-bug-0.8.0.tar.gz
54788f03849ea4022e942355024458008590f8b08c5d5e5a4b1255a461e4b3cce7242d97c948b6411613a3d6cd8b576ca58a49858a00206a91f6f83ca76f32fc fix-tests.patch
fed7c606b146976cf2c3fc4c2849ae81e8f1dd17505863dcf5dcbafd4715a96d3a1984124e27c70b6a6aaf09f22a5b957fdfde7725132c8b775bdf5a6bce0a24 Makefile.patch
"

View file

@ -0,0 +1,40 @@
See:
* https://github.com/MichaelMure/git-bug/issues/926
* https://github.com/MichaelMure/git-bug/pull/984
diff --git a/commands/add_test.go b/commands/add_test.go
index 077995a6..d603e79a 100644
--- a/commands/add_test.go
+++ b/commands/add_test.go
@@ -4,12 +4,29 @@ import (
"strings"
"testing"
+ "github.com/fatih/color"
"github.com/stretchr/testify/require"
)
func newTestEnvAndBug(t *testing.T) (*testEnv, string) {
t.Helper()
+ // The Go testing framework either uses os.Stdout directly or a buffer
+ // depending on how the command is initially launched. This results
+ // in os.Stdout.Fd() sometimes being a Terminal, and other times not
+ // being a Terminal which determines whether the ANSI library sends
+ // escape sequences to colorize the text.
+ //
+ // The line below disables all colorization during testing so that the
+ // git-bug command output is consistent in all test scenarios.
+ //
+ // See:
+ // - https://github.com/MichaelMure/git-bug/issues/926
+ // - https://github.com/golang/go/issues/57671
+ // - https://github.com/golang/go/blob/f721fa3be9bb52524f97b409606f9423437535e8/src/cmd/go/internal/test/test.go#L1180-L1208
+ // - https://github.com/golang/go/issues/34877
+ color.NoColor = true
+
testEnv, _ := newTestEnvAndUser(t)
opts := addOptions{
title: "this is a bug title",