From 249129befcb27cb957a815067bef93d57d347ff2 Mon Sep 17 00:00:00 2001 From: Spencer Nelson Date: Fri, 10 Mar 2017 11:20:39 -0500 Subject: [PATCH] Check for required bins pretest Verify that git, bazaar, and mercurial are installed before running tests that require them. If not, fail the test. --- manager_test.go | 1 + result_test.go | 1 + source_test.go | 4 ++++ util_test.go | 11 +++++++++++ 4 files changed, 17 insertions(+) diff --git a/manager_test.go b/manager_test.go index bdd4aceda0..f77f3c7a9e 100644 --- a/manager_test.go +++ b/manager_test.go @@ -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) diff --git a/result_test.go b/result_test.go index ee6ab359f4..1cf9273266 100644 --- a/result_test.go +++ b/result_test.go @@ -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 { diff --git a/source_test.go b/source_test.go index db4f1d6e22..2d4a00b803 100644 --- a/source_test.go +++ b/source_test.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/util_test.go b/util_test.go index 036edbf742..9a2fb18d1f 100644 --- a/util_test.go +++ b/util_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "testing" ) @@ -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) + } + } +}