TestFindSymbols tests the FindSymbols routine using a hardcoded nm output.
(t *testing.T)
| 24 | |
| 25 | // TestFindSymbols tests the FindSymbols routine using a hardcoded nm output. |
| 26 | func TestFindSymbols(t *testing.T) { |
| 27 | type testcase struct { |
| 28 | query, syms string |
| 29 | want []plugin.Sym |
| 30 | } |
| 31 | |
| 32 | testsyms := `0000000000001000 t lineA001 |
| 33 | 0000000000001000 t lineA002 |
| 34 | 0000000000001000 t line1000 |
| 35 | 0000000000002000 t line200A |
| 36 | 0000000000002000 t line2000 |
| 37 | 0000000000002000 t line200B |
| 38 | 0000000000003000 t line3000 |
| 39 | 0000000000003000 t _ZNK4DumbclEPKc |
| 40 | 0000000000003000 t lineB00C |
| 41 | 0000000000003000 t line300D |
| 42 | 0000000000004000 t _the_end |
| 43 | ` |
| 44 | testcases := []testcase{ |
| 45 | { |
| 46 | "line.*[AC]", |
| 47 | testsyms, |
| 48 | []plugin.Sym{ |
| 49 | {Name: []string{"lineA001"}, File: "object.o", Start: 0x1000, End: 0x1FFF}, |
| 50 | {Name: []string{"line200A"}, File: "object.o", Start: 0x2000, End: 0x2FFF}, |
| 51 | {Name: []string{"lineB00C"}, File: "object.o", Start: 0x3000, End: 0x3FFF}, |
| 52 | }, |
| 53 | }, |
| 54 | { |
| 55 | "Dumb::operator", |
| 56 | testsyms, |
| 57 | []plugin.Sym{ |
| 58 | {Name: []string{"Dumb::operator()(char const*) const"}, File: "object.o", Start: 0x3000, End: 0x3FFF}, |
| 59 | }, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | for _, tc := range testcases { |
| 64 | syms, err := findSymbols([]byte(tc.syms), "object.o", regexp.MustCompile(tc.query), 0) |
| 65 | if err != nil { |
| 66 | t.Fatalf("%q: findSymbols: %v", tc.query, err) |
| 67 | } |
| 68 | if err := checkSymbol(syms, tc.want); err != nil { |
| 69 | t.Errorf("%q: %v", tc.query, err) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func checkSymbol(got []*plugin.Sym, want []plugin.Sym) error { |
| 75 | if len(got) != len(want) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…