Merge "jiri/cmd/jiri: verify that jiri can be built in TestBootstrapJiri test."
diff --git a/cmd/jiri/bootstrap_jiri_test.go b/cmd/jiri/bootstrap_jiri_test.go
index 3bdca29..c0300ac 100644
--- a/cmd/jiri/bootstrap_jiri_test.go
+++ b/cmd/jiri/bootstrap_jiri_test.go
@@ -6,8 +6,10 @@
 
 import (
 	"fmt"
+	"io/ioutil"
 	"os"
 	"path/filepath"
+	"regexp"
 	"strings"
 	"testing"
 
@@ -38,6 +40,31 @@
 	}
 }
 
+// TestBuildJiriLocally checks that the jiri binary built in the bootstrap
+// script can be built locally.
+func TestBuildJiriLocally(t *testing.T) {
+	sh := gosh.NewShell(gosh.Opts{Fatalf: t.Fatalf, Logf: t.Logf, PropagateChildOutput: true})
+	defer sh.Cleanup()
+
+	// Extract jiri package path from this line.
+	// GOPATH="${tmp_dir}" go build -o "${bin_dir}/jiri" v.io/jiri/cmd/jiri
+	bootstrap, err := filepath.Abs("./scripts/bootstrap_jiri")
+	if err != nil {
+		t.Fatalf("couldn't determine absolute path to bootstrap_jiri script")
+	}
+	pkgRE := regexp.MustCompile(`.*go build.*\s([^\s]*)\n`)
+	content, err := ioutil.ReadFile(bootstrap)
+	if err != nil {
+		t.Fatalf("couldn't read bootstrap script: %v", err)
+	}
+	matches := pkgRE.FindStringSubmatch(string(content))
+	if len(matches) <= 1 {
+		t.Fatalf("couldn't find jiri package from the bootstrap_jiri script")
+	}
+	pkg := matches[1]
+	sh.Cmd("jiri", "go", "build", "-o", filepath.Join(sh.MakeTempDir(), "jiri"), pkg).Run()
+}
+
 func TestBootstrapJiriAlreadyExists(t *testing.T) {
 	sh := gosh.NewShell(gosh.Opts{Fatalf: t.Fatalf, Logf: t.Logf, PropagateChildOutput: true})
 	defer sh.Cleanup()