Skip to content

Commit

Permalink
check for .git in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keegancsmith committed Oct 10, 2022
1 parent 5040bd7 commit b07c069
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cmd/git-sg/catfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestInfo(t *testing.T) {
setGitDir(t)

p, err := startGitCatFileBatch("")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -43,6 +45,8 @@ func TestInfo(t *testing.T) {
}

func TestContents(t *testing.T) {
setGitDir(t)

p, err := startGitCatFileBatch("")
if err != nil {
t.Fatal(err)
Expand Down
26 changes: 16 additions & 10 deletions cmd/git-sg/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ import (
)

func TestDo(t *testing.T) {
dir, err := filepath.Abs("../../.git")
if err != nil {
t.Fatal(err)
}
t.Setenv("GIT_DIR", dir)

if _, err := os.Stat(dir); os.Getenv("CI") != "" && os.IsNotExist(err) {
t.Skipf("skipping since on CI and this is not a git checkout: %v", err)
}
setGitDir(t)

for _, envvar := range []string{"", "GIT_SG_BUFFER", "GIT_SG_FILTER", "GIT_SG_CATFILE", "GIT_SG_LSTREE"} {
name := envvar
Expand All @@ -27,7 +19,7 @@ func TestDo(t *testing.T) {
t.Setenv(envvar, "1")
}
var w countingWriter
err = do(&w)
err := do(&w)
if err != nil {
t.Fatal(err)
}
Expand All @@ -47,3 +39,17 @@ func (w *countingWriter) Write(b []byte) (int, error) {
w.N += len(b)
return len(b), nil
}

func setGitDir(t *testing.T) {
t.Helper()

dir, err := filepath.Abs("../../.git")
if err != nil {
t.Fatal(err)
}
t.Setenv("GIT_DIR", dir)

if _, err := os.Stat(dir); os.Getenv("CI") != "" && os.IsNotExist(err) {
t.Skipf("skipping since on CI and this is not a git checkout: %v", err)
}
}

0 comments on commit b07c069

Please sign in to comment.