LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package os_test | 5 package os_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } else { | 424 } else { |
425 cmd = "/bin/pwd" | 425 cmd = "/bin/pwd" |
426 args = []string{"pwd"} | 426 args = []string{"pwd"} |
427 adir = "/" | 427 adir = "/" |
428 expect = "/\n" | 428 expect = "/\n" |
429 } | 429 } |
430 p, err := StartProcess(cmd, args, nil, adir, []*File{nil, w, Stderr}) | 430 p, err := StartProcess(cmd, args, nil, adir, []*File{nil, w, Stderr}) |
431 if err != nil { | 431 if err != nil { |
432 t.Fatalf("StartProcess: %v", err) | 432 t.Fatalf("StartProcess: %v", err) |
433 } | 433 } |
434 » defer p.Close() | 434 » defer p.Release() |
435 w.Close() | 435 w.Close() |
436 | 436 |
437 var b bytes.Buffer | 437 var b bytes.Buffer |
438 io.Copy(&b, r) | 438 io.Copy(&b, r) |
439 output := b.String() | 439 output := b.String() |
440 if output != expect { | 440 if output != expect { |
441 args[0] = cmd | 441 args[0] = cmd |
442 t.Errorf("exec %q returned %q wanted %q", strings.Join(args, " "
), output, expect) | 442 t.Errorf("exec %q returned %q wanted %q", strings.Join(args, " "
), output, expect) |
443 } | 443 } |
444 p.Wait(0) | 444 p.Wait(0) |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 func run(t *testing.T, cmd []string) string { | 748 func run(t *testing.T, cmd []string) string { |
749 // Run /bin/hostname and collect output. | 749 // Run /bin/hostname and collect output. |
750 r, w, err := Pipe() | 750 r, w, err := Pipe() |
751 if err != nil { | 751 if err != nil { |
752 t.Fatal(err) | 752 t.Fatal(err) |
753 } | 753 } |
754 p, err := StartProcess("/bin/hostname", []string{"hostname"}, nil, "/",
[]*File{nil, w, Stderr}) | 754 p, err := StartProcess("/bin/hostname", []string{"hostname"}, nil, "/",
[]*File{nil, w, Stderr}) |
755 if err != nil { | 755 if err != nil { |
756 t.Fatal(err) | 756 t.Fatal(err) |
757 } | 757 } |
758 » defer p.Close() | 758 » defer p.Release() |
759 w.Close() | 759 w.Close() |
760 | 760 |
761 var b bytes.Buffer | 761 var b bytes.Buffer |
762 io.Copy(&b, r) | 762 io.Copy(&b, r) |
763 p.Wait(0) | 763 p.Wait(0) |
764 output := b.String() | 764 output := b.String() |
765 if n := len(output); n > 0 && output[n-1] == '\n' { | 765 if n := len(output); n > 0 && output[n-1] == '\n' { |
766 output = output[0 : n-1] | 766 output = output[0 : n-1] |
767 } | 767 } |
768 if output == "" { | 768 if output == "" { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 if err != nil { | 879 if err != nil { |
880 t.Fatal("stat failed:", err) | 880 t.Fatal("stat failed:", err) |
881 } | 881 } |
882 | 882 |
883 // Stat of path+"/" should succeed too. | 883 // Stat of path+"/" should succeed too. |
884 _, err = Stat(path + "/") | 884 _, err = Stat(path + "/") |
885 if err != nil { | 885 if err != nil { |
886 t.Fatal("stat failed:", err) | 886 t.Fatal("stat failed:", err) |
887 } | 887 } |
888 } | 888 } |
LEFT | RIGHT |