MCPcopy
hub / github.com/tailscale/tailscale / TestBuildError

Function TestBuildError

cmd/testwrapper/testwrapper_test.go:323–357  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

321}
322
323func TestBuildError(t *testing.T) {
324 t.Parallel()
325
326 // Construct our broken package.
327 testfile := filepath.Join(t.TempDir(), "builderror_test.go")
328 code := []byte("package builderror_test\n\nderp")
329 err := os.WriteFile(testfile, code, 0o644)
330 if err != nil {
331 t.Fatalf("writing package: %s", err)
332 }
333
334 wantErr := "builderror_test.go:3:1: expected declaration, found derp\nFAIL"
335
336 // Confirm `go test` exits with code 1.
337 goOut, err := exec.Command("go", "test", testfile).CombinedOutput()
338 if code, ok := errExitCode(err); !ok || code != 1 {
339 t.Fatalf("go test %s: got exit code %d, want 1 (err: %v)", testfile, code, err)
340 }
341 if !strings.Contains(string(goOut), wantErr) {
342 t.Fatalf("go test %s: got output %q, want output containing %q", testfile, goOut, wantErr)
343 }
344
345 // Confirm `testwrapper` exits with code 1.
346 twOut, err := cmdTestwrapper(t, testfile).CombinedOutput()
347 if code, ok := errExitCode(err); !ok || code != 1 {
348 t.Fatalf("testwrapper %s: got exit code %d, want 1 (err: %v)", testfile, code, err)
349 }
350 if !strings.Contains(string(twOut), wantErr) {
351 t.Fatalf("testwrapper %s: got output %q, want output containing %q", testfile, twOut, wantErr)
352 }
353
354 if testing.Verbose() {
355 t.Logf("success - output:\n%s", twOut)
356 }
357}
358
359func TestTimeout(t *testing.T) {
360 t.Parallel()

Callers

nothing calls this directly

Calls 8

errExitCodeFunction · 0.85
cmdTestwrapperFunction · 0.85
CombinedOutputMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalfMethod · 0.65
LogfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…