Skip to content

Commit

Permalink
Check for required bins pretest
Browse files Browse the repository at this point in the history
Verify that git, bazaar, and mercurial are installed before running tests
that require them. If not, fail the test.
  • Loading branch information
spenczar committed Mar 10, 2017
1 parent 41bc589 commit 249129b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func TestGetSources(t *testing.T) {
if testing.Short() {
t.Skip("Skipping source setup test in short mode")
}
requiresBins(t, "git", "hg", "bzr")

sm, clean := mkNaiveSM(t)

Expand Down
1 change: 1 addition & 0 deletions result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestWriteDepTree(t *testing.T) {
if testing.Short() {
t.Skip("Skipping dep tree writing test in short mode")
}
requiresBins(t, "git", "hg", "bzr")

tmp, err := ioutil.TempDir("", "writetree")
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestGitSourceInteractions(t *testing.T) {
if testing.Short() {
t.Skip("Skipping git source version fetching test in short mode")
}
requiresBins(t, "git")

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
Expand Down Expand Up @@ -113,6 +114,7 @@ func TestGopkginSourceInteractions(t *testing.T) {
if testing.Short() {
t.Skip("Skipping gopkg.in source version fetching test in short mode")
}
requiresBins(t, "git")

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
Expand Down Expand Up @@ -252,6 +254,7 @@ func TestBzrSourceInteractions(t *testing.T) {
if testing.Short() {
t.Skip("Skipping bzr source version fetching test in short mode")
}
requiresBins(t, "bzr")

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
Expand Down Expand Up @@ -361,6 +364,7 @@ func TestHgSourceInteractions(t *testing.T) {
if testing.Short() {
t.Skip("Skipping hg source version fetching test in short mode")
}
requiresBins(t, "hg")

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)
Expand Down Expand Up @@ -129,3 +130,13 @@ func TestCopyFile(t *testing.T) {
t.Fatalf("expected %s: %#v\n to be the same mode as %s: %#v", srcf.Name(), srcinfo.Mode(), destf, destinfo.Mode())
}
}

// Fail a test if the specified binaries aren't installed.
func requiresBins(t *testing.T, bins ...string) {
for _, b := range bins {
_, err := exec.LookPath(b)
if err != nil {
t.Fatalf("%s is not installed", b)
}
}
}

0 comments on commit 249129b

Please sign in to comment.