GoPLS Viewer

Home|gopls/cmd/signature-fuzzer/fuzz-driver/drv_test.go
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package main
6
7import (
8    "os"
9    "os/exec"
10    "path/filepath"
11    "runtime"
12    "testing"
13
14    "golang.org/x/tools/internal/testenv"
15)
16
17// buildDriver builds the fuzz-driver executable, returning its path.
18func buildDriver(t *testing.Tstring {
19    t.Helper()
20    if runtime.GOOS == "android" {
21        t.Skipf("the dependencies are not available on android")
22        return ""
23    }
24    bindir := filepath.Join(t.TempDir(), "bin")
25    err := os.Mkdir(bindiros.ModePerm)
26    if err != nil {
27        t.Fatal(err)
28    }
29    binary := filepath.Join(bindir"driver")
30    if runtime.GOOS == "windows" {
31        binary += ".exe"
32    }
33    cmd := exec.Command("go""build""-o"binary)
34    if err := cmd.Run(); err != nil {
35        t.Fatalf("Building fuzz-driver: %v"err)
36    }
37    return binary
38}
39
40func TestEndToEndIntegration(t *testing.T) {
41    testenv.NeedsTool(t"go")
42    td := t.TempDir()
43
44    // Build the fuzz-driver binary.
45    // Note: if more tests are added to this package, move this to single setup fcn, so
46    // that we don't have to redo the build each time.
47    binary := buildDriver(t)
48
49    // Kick off a run.
50    gendir := filepath.Join(td"gen")
51    args := []string{"-numfcns""3""-numpkgs""1""-seed""101""-outdir"gendir}
52    c := exec.Command(binaryargs...)
53    berr := c.CombinedOutput()
54    if err != nil {
55        t.Fatalf("error invoking fuzz-driver: %v\n%s"errb)
56    }
57
58    found := ""
59    walker := func(path stringinfo os.FileInfoerr errorerror {
60        found = found + ":" + info.Name()
61        return nil
62    }
63
64    // Make sure it emits something.
65    err2 := filepath.Walk(gendirwalker)
66    if err2 != nil {
67        t.Fatalf("error from filepath.Walk: %v"err2)
68    }
69    const expected = ":gen:genCaller0:genCaller0.go:genChecker0:genChecker0.go:genMain.go:genUtils:genUtils.go:go.mod"
70    if found != expected {
71        t.Errorf("walk of generated code: got %s want %s"foundexpected)
72    }
73}
74
MembersX
TestEndToEndIntegration.gendir
TestEndToEndIntegration.found
filepath
runtime
testing
TestEndToEndIntegration.t
buildDriver.binary
TestEndToEndIntegration.args
TestEndToEndIntegration.expected
exec
buildDriver
buildDriver.bindir
buildDriver.err
TestEndToEndIntegration.td
TestEndToEndIntegration.binary
TestEndToEndIntegration.c
TestEndToEndIntegration.b
TestEndToEndIntegration.err
testenv
buildDriver.t
buildDriver.cmd
TestEndToEndIntegration
TestEndToEndIntegration.err2
Members
X