Merge "x/lib/metadata: go1.5 expects -X var=val, not -X var val."
diff --git a/cmdline/testdata/gendoc.go b/cmdline/testdata/gendoc.go
index 4c00726..8c1ef51 100644
--- a/cmdline/testdata/gendoc.go
+++ b/cmdline/testdata/gendoc.go
@@ -28,6 +28,7 @@
 	"os"
 	"os/exec"
 	"path/filepath"
+	"regexp"
 	"strings"
 )
 
@@ -48,17 +49,29 @@
 	}
 	pkg, args := args[0], args[1:]
 
-	// Build the gendoc binary in a temporary folder.
+	// Find out the binary name from the pkg name.
+	var listOut bytes.Buffer
+	listCmd := exec.Command("go", "list")
+	listCmd.Stdout = &listOut
+	if err := listCmd.Run(); err != nil {
+		return fmt.Errorf("%q failed: %v\n%v\n", strings.Join(listCmd.Args, " "), err, listOut.String())
+	}
+	binName := filepath.Base(strings.TrimSpace(listOut.String()))
+
+	// Install the gendoc binary in a temporary folder.
 	tmpDir, err := ioutil.TempDir("", "")
 	if err != nil {
 		return fmt.Errorf("TempDir() failed: %v", err)
 	}
 	defer os.RemoveAll(tmpDir)
-	gendocBin := filepath.Join(tmpDir, "gendoc")
-	buildArgs := []string{"go", "build", "-a", "-tags=" + flagTags, "-o=" + gendocBin, pkg}
-	buildCmd := exec.Command("v23", buildArgs...)
-	if err := buildCmd.Run(); err != nil {
-		return fmt.Errorf("%q failed: %v\n", strings.Join(buildCmd.Args, " "), err)
+	gendocBin := filepath.Join(tmpDir, binName)
+	env := environ()
+	env = append(env, "GOBIN="+tmpDir)
+	installArgs := []string{"go", "install", "-tags=" + flagTags, pkg}
+	installCmd := exec.Command("v23", installArgs...)
+	installCmd.Env = env
+	if err := installCmd.Run(); err != nil {
+		return fmt.Errorf("%q failed: %v\n", strings.Join(installCmd.Args, " "), err)
 	}
 
 	// Use it to generate the documentation.
@@ -86,7 +99,7 @@
 %s/*
 %s*/
 package main
-`, tagsConstraint, out.String())
+`, tagsConstraint, suppressParallelFlag(out.String()))
 
 	// Write the result to doc.go.
 	path, perm := filepath.Join(pkg, "doc.go"), os.FileMode(0644)
@@ -96,6 +109,17 @@
 	return nil
 }
 
+// suppressParallelFlag replaces the default value of the test.parallel flag
+// with the literal string "<number of threads>". The default value of the
+// test.parallel flag is GOMAXPROCS, which (since Go1.5) is set to the number
+// of logical CPU threads on the current system. This causes problems with the
+// vanadium-go-generate test, which requires that the output of gendoc is the
+// same on all systems.
+func suppressParallelFlag(input string) string {
+	pattern := regexp.MustCompile("(?m:(^ -test\\.parallel=)(?:\\d)+$)")
+	return pattern.ReplaceAllString(input, "$1<number of threads>")
+}
+
 // environ returns the environment variables to use when running the command to
 // retrieve full help information.
 func environ() []string {
diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go
index 6ba953e..4919157 100644
--- a/metadata/metadata_test.go
+++ b/metadata/metadata_test.go
@@ -240,7 +240,7 @@
 	const id, value = "zzzTestID", "abcdefg"
 	x := FromMap(map[string]string{id: value})
 	cmdRun := exec.Command("go", "run", "-ldflags="+LDFlag(x), "./testdata/testbin.go", "-metadata")
-	outXML, err := cmdRun.CombinedOutput()
+	outXML, err := cmdRun.Output()
 	if err != nil {
 		t.Errorf("%v failed: %v\n%v", cmdRun.Args, err, outXML)
 	}