Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3240)

Delta Between Two Patch Sets: src/pkg/os/os_test.go

Issue 9651047: code review 9651047: os: request appropriate access rights before calling wi... (Closed)
Left Patch Set: diff -r 4aa7943034c5 https://go.googlecode.com/hg/ Created 10 years, 9 months ago
Right Patch Set: diff -r fe447e02dc0b https://go.googlecode.com/hg/ Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/os/exec_windows.go ('k') | src/pkg/syscall/ztypes_windows.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "flag" 9 "flag"
10 "fmt" 10 "fmt"
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 1110
1111 dir, err := Stat(path) 1111 dir, err := Stat(path)
1112 if err != nil { 1112 if err != nil {
1113 t.Fatalf("Stat %q (looking for mode %#o): %s", path, mode, err) 1113 t.Fatalf("Stat %q (looking for mode %#o): %s", path, mode, err)
1114 } 1114 }
1115 if dir.Mode()&mode != mode { 1115 if dir.Mode()&mode != mode {
1116 t.Errorf("Stat %q: mode %#o want %#o", path, dir.Mode()&mode, mo de) 1116 t.Errorf("Stat %q: mode %#o want %#o", path, dir.Mode()&mode, mo de)
1117 } 1117 }
1118 } 1118 }
1119 1119
1120 func TestKillProcess(t *testing.T) { 1120 func TestReadAtEOF(t *testing.T) {
1121 » f := newFile("TestReadAtEOF", t)
1122 » defer Remove(f.Name())
1123 » defer f.Close()
1124
1125 » _, err := f.ReadAt(make([]byte, 10), 0)
1126 » switch err {
1127 » case io.EOF:
1128 » » // all good
1129 » case nil:
1130 » » t.Fatalf("ReadAt succeeded")
1131 » default:
1132 » » t.Fatalf("ReadAt failed: %s", err)
1133 » }
1134 }
1135
1136 func testKillProcess(t *testing.T, processKiller func(p *Process)) {
1121 dir, err := ioutil.TempDir("", "go-build") 1137 dir, err := ioutil.TempDir("", "go-build")
1122 if err != nil { 1138 if err != nil {
1123 t.Fatalf("Failed to create temp directory: %v", err) 1139 t.Fatalf("Failed to create temp directory: %v", err)
1124 } 1140 }
1125 defer RemoveAll(dir) 1141 defer RemoveAll(dir)
1126 1142
1127 src := filepath.Join(dir, "main.go") 1143 src := filepath.Join(dir, "main.go")
1128 f, err := Create(src) 1144 f, err := Create(src)
1129 if err != nil { 1145 if err != nil {
1130 t.Fatalf("Failed to create %v: %v", src, err) 1146 t.Fatalf("Failed to create %v: %v", src, err)
(...skipping 11 matching lines...) Expand all
1142 t.Fatalf("Failed to execute template: %v", err) 1158 t.Fatalf("Failed to execute template: %v", err)
1143 } 1159 }
1144 f.Close() 1160 f.Close()
1145 1161
1146 exe := filepath.Join(dir, "main.exe") 1162 exe := filepath.Join(dir, "main.exe")
1147 output, err := osexec.Command("go", "build", "-o", exe, src).CombinedOut put() 1163 output, err := osexec.Command("go", "build", "-o", exe, src).CombinedOut put()
1148 if err != nil { 1164 if err != nil {
1149 t.Fatalf("Failed to build exe %v: %v %v", exe, err, string(outpu t)) 1165 t.Fatalf("Failed to build exe %v: %v %v", exe, err, string(outpu t))
1150 } 1166 }
1151 1167
1152 » p := osexec.Command(exe) 1168 » cmd := osexec.Command(exe)
1153 » err = p.Start() 1169 » err = cmd.Start()
1154 if err != nil { 1170 if err != nil {
1155 t.Fatalf("Failed to start test process: %v", err) 1171 t.Fatalf("Failed to start test process: %v", err)
1156 } 1172 }
1157 go func() { 1173 go func() {
1158 time.Sleep(100 * time.Millisecond) 1174 time.Sleep(100 * time.Millisecond)
1159 » » p2, err := FindProcess(p.Process.Pid) 1175 » » processKiller(cmd.Process)
1176 » }()
1177 » err = cmd.Wait()
1178 » if err == nil {
1179 » » t.Errorf("Test process succeeded, but expected to fail")
1180 » }
1181 }
1182
1183 func TestKillStartProcess(t *testing.T) {
1184 » testKillProcess(t, func(p *Process) {
1185 » » err := p.Kill()
1186 » » if err != nil {
1187 » » » t.Fatalf("Failed to kill test process: %v", err)
1188 » » }
1189 » })
1190 }
1191
1192 func TestKillFindProcess(t *testing.T) {
1193 » testKillProcess(t, func(p *Process) {
1194 » » p2, err := FindProcess(p.Pid)
1160 if err != nil { 1195 if err != nil {
1161 t.Fatalf("Failed to find test process: %v", err) 1196 t.Fatalf("Failed to find test process: %v", err)
1162 } 1197 }
1163 err = p2.Kill() 1198 err = p2.Kill()
1164 if err != nil { 1199 if err != nil {
1165 t.Fatalf("Failed to kill test process: %v", err) 1200 t.Fatalf("Failed to kill test process: %v", err)
1166 } 1201 }
1167 » }() 1202 » })
1168 » err = p.Wait() 1203 }
1169 » if err == nil {
1170 » » t.Errorf("Test process succeeded")
1171 » }
1172 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b