Fixes #17078.
Change-Id: I1dfb71f64361b575ec461ed44b0779f2d5cf45fc
Reviewed-on: https://go-review.googlesource.com/31352
Reviewed-by: Quentin Smith <quentin@golang.org>
        tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
 }
 
+func TestGoTestDashIDashOWritesBinary(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.makeTempdir()
+       tg.run("test", "-v", "-i", "-o", tg.path("myerrors.test"+exeSuffix), "errors")
+       tg.grepBothNot("PASS|FAIL", "test should not have run")
+       tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
+}
+
 // Issue 4568.
 func TestSymlinksList(t *testing.T) {
        switch runtime.GOOS {
 
        testStreamOutput = len(pkgArgs) == 0 || testBench ||
                (testShowPass && (len(pkgs) == 1 || buildP == 1))
 
+       // For 'go test -i -o x.test', we want to build x.test. Imply -c to make the logic easier.
+       if buildI && testO != "" {
+               testC = true
+       }
+
        var b builder
        b.init()