Debian Codegraph @

cmd/bpf2go/makedep_test.go

raw symbols SCIP
1 //go:build !windows
2
3 package main
4
5 import (
6 "bytes"
7 "reflect"
8 "strings"
9 "testing"
10 )
11
12 func TestParseDependencies(t *testing.T) {
13 const input = `main.go: /foo/bar baz
14
15 frob: /gobble \
16 gubble
17
18 nothing:
19 `
20
21 have, err := parseDependencies("/foo", strings.NewReader(input))
22 if err != nil {
23 t.Fatal("Can't parse dependencies:", err)
24 }
25
26 want := []dependency{
27 {"/foo/main.go", []string{"/foo/bar", "/foo/baz"}},
28 {"/foo/frob", []string{"/gobble", "/foo/gubble"}},
29 {"/foo/nothing", nil},
30 }
31
32 if !reflect.DeepEqual(have, want) {
33 t.Logf("Have: %#v", have)
34 t.Logf("Want: %#v", want)
35 t.Error("Result doesn't match")
36 }
37
38 var output bytes.Buffer
39 err = adjustDependencies(&output, "/foo", want)
40 if err != nil {
41 t.Error("Can't adjust dependencies")
42 }
43
44 const wantOutput = `main.go: \
45 bar \
46 baz
47
48 frob: \
49 ../gobble \
50 gubble
51
52 nothing:
53
54 `
55
56 if have := output.String(); have != wantOutput {
57 t.Logf("Have:\n%s", have)
58 t.Logf("Want:\n%s", wantOutput)
59 t.Error("Output doesn't match")
60 }
61 }