github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/ldd/ldd_unix_test.go (about) 1 // Copyright 2009-2018 the u-root 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 5 //go:build freebsd || linux 6 // +build freebsd linux 7 8 package ldd 9 10 import ( 11 "testing" 12 ) 13 14 var ( 15 cases = []struct { 16 name string 17 input string 18 output []string 19 }{ 20 { 21 name: "single vdso entry", 22 input: ` linux-vdso.so.1`, 23 output: []string{}, 24 }, 25 { 26 name: "duplicate vdso symlink", 27 input: ` linux-vdso.so.1 => linux-vdso.so.1`, 28 output: []string{}, 29 }, 30 { 31 name: "multiple entries", 32 input: ` linux-vdso.so.1 => linux-vdso.so.1 33 libc.so.6 => /usr/lib/libc.so.6 34 /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2`, 35 output: []string{"/usr/lib/libc.so.6", "/usr/lib64/ld-linux-x86-64.so.2"}, 36 }, 37 } 38 ) 39 40 func cmp(a, b []string) bool { 41 if len(a) != len(b) { 42 return false 43 } 44 for i, v := range a { 45 if v != b[i] { 46 return false 47 } 48 } 49 return true 50 } 51 52 func TestParseInterp(t *testing.T) { 53 for _, c := range cases { 54 out, _ := parseinterp(c.input) 55 if !cmp(out, c.output) { 56 t.Fatalf("'%s' expected %v, but got %v", c.name, c.output, out) 57 } 58 } 59 }