cmd/go: convert TestImportCycle to the script framework

This test already calls tg.Parallel

Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I4cdb2464cd3e51f1369558c238925f036ce8d828
Reviewed-on: https://go-review.googlesource.com/c/go/+/213426
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 76566f3..014af70 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -1072,25 +1072,6 @@
 	tg.grepStderr("found import comments", "go build did not mention comment conflict")
 }
 
-func TestImportCycle(t *testing.T) {
-	tg := testgo(t)
-	defer tg.cleanup()
-	tg.parallel()
-	tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcycle"))
-	tg.runFail("build", "selfimport")
-
-	count := tg.grepCountBoth("import cycle not allowed")
-	if count == 0 {
-		t.Fatal("go build did not mention cyclical import")
-	}
-	if count > 1 {
-		t.Fatal("go build mentioned import cycle more than once")
-	}
-
-	// Don't hang forever.
-	tg.run("list", "-e", "-json", "selfimport")
-}
-
 // cmd/go: custom import path checking should not apply to Go packages without import comment.
 func TestIssue10952(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
diff --git a/src/cmd/go/testdata/importcycle/src/selfimport/selfimport.go b/src/cmd/go/testdata/importcycle/src/selfimport/selfimport.go
deleted file mode 100644
index dc63c4b..0000000
--- a/src/cmd/go/testdata/importcycle/src/selfimport/selfimport.go
+++ /dev/null
@@ -1,3 +0,0 @@
-package selfimport
-
-import "selfimport"
diff --git a/src/cmd/go/testdata/script/build_import_cycle.txt b/src/cmd/go/testdata/script/build_import_cycle.txt
new file mode 100644
index 0000000..0154305
--- /dev/null
+++ b/src/cmd/go/testdata/script/build_import_cycle.txt
@@ -0,0 +1,10 @@
+! go build selfimport
+stderr -count=1 'import cycle not allowed'
+
+go list -e -f '{{.Error}}' selfimport # Don't hang forever
+stdout -count=1 'import cycle not allowed'
+
+-- selfimport/selfimport.go --
+package selfimport
+
+import "selfimport"