summaryrefslogtreecommitdiff
path: root/src/cmd/fix
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-02-20 15:36:08 +1100
committerRob Pike <r@golang.org>2012-02-20 15:36:08 +1100
commitb5a3bd5ff6f735f39a312a43d3f0a647f4d76590 (patch)
treeb9b7bf2552f1f876bf6429d0208a1541e645c26d /src/cmd/fix
parenta9e57f743d658ba27d3165dc6841915b12a98879 (diff)
downloadgo-git-b5a3bd5ff6f735f39a312a43d3f0a647f4d76590.tar.gz
os: drop the Wait function and the options to Process.Wait
They are portability problems and the options are almost always zero in practice anyway. R=golang-dev, dsymonds, r, bradfitz CC=golang-dev https://golang.org/cl/5688046
Diffstat (limited to 'src/cmd/fix')
-rw-r--r--src/cmd/fix/oswait.go56
-rw-r--r--src/cmd/fix/oswait_test.go41
2 files changed, 97 insertions, 0 deletions
diff --git a/src/cmd/fix/oswait.go b/src/cmd/fix/oswait.go
new file mode 100644
index 0000000000..fdc23f8537
--- /dev/null
+++ b/src/cmd/fix/oswait.go
@@ -0,0 +1,56 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "go/ast"
+)
+
+func init() {
+ register(oswaitFix)
+}
+
+var oswaitFix = fix{
+ "oswait",
+ "2012-02-20",
+ oswait,
+ `Delete options from os.Wait. If the option is the literal 0, rewrite the call.
+
+http://codereview.appspot.com/5688046
+`,
+}
+
+func oswait(f *ast.File) bool {
+ if !imports(f, "os") {
+ return false
+ }
+
+ fixed := false
+
+ walk(f, func(n interface{}) {
+ call, ok := n.(*ast.CallExpr)
+ if !ok {
+ return
+ }
+ if !isPkgDot(call.Fun, "os", "Wait") {
+ return
+ }
+ args := call.Args
+ const warning = "call to Process.Wait must be fixed manually"
+ if len(args) != 1 {
+ // Shouldn't happen, but check.
+ warn(call.Pos(), warning)
+ return
+ }
+ if basicLit, ok := args[0].(*ast.BasicLit); !ok || basicLit.Value != "0" {
+ warn(call.Pos(), warning)
+ return
+ }
+ call.Args = nil
+ fixed = true
+ })
+
+ return fixed
+}
diff --git a/src/cmd/fix/oswait_test.go b/src/cmd/fix/oswait_test.go
new file mode 100644
index 0000000000..baff017487
--- /dev/null
+++ b/src/cmd/fix/oswait_test.go
@@ -0,0 +1,41 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+ addTestCases(oswaitTests, oswait)
+}
+
+var oswaitTests = []testCase{
+ {
+ Name: "oswait.0",
+ In: `package main
+
+import (
+ "os"
+)
+
+func f() {
+ os.Wait()
+ os.Wait(0)
+ os.Wait(1)
+ os.Wait(A | B)
+}
+`,
+ Out: `package main
+
+import (
+ "os"
+)
+
+func f() {
+ os.Wait()
+ os.Wait()
+ os.Wait(1)
+ os.Wait(A | B)
+}
+`,
+ },
+}