github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/go/build_test.go (about) 1 // Copyright 2016 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 5 package main 6 7 import ( 8 "os" 9 "reflect" 10 "testing" 11 ) 12 13 func TestRemoveDevNull(t *testing.T) { 14 fi, err := os.Lstat(os.DevNull) 15 if err != nil { 16 t.Skip(err) 17 } 18 if fi.Mode().IsRegular() { 19 t.Errorf("Lstat(%s).Mode().IsRegular() = true; expected false", os.DevNull) 20 } 21 mayberemovefile(os.DevNull) 22 _, err = os.Lstat(os.DevNull) 23 if err != nil { 24 t.Errorf("mayberemovefile(%s) did remove it; oops", os.DevNull) 25 } 26 } 27 28 func TestSplitPkgConfigOutput(t *testing.T) { 29 for _, test := range []struct { 30 in []byte 31 want []string 32 }{ 33 {[]byte(`-r:foo -L/usr/white\ space/lib -lfoo\ bar -lbar\ baz`), []string{"-r:foo", "-L/usr/white space/lib", "-lfoo bar", "-lbar baz"}}, 34 {[]byte(`-lextra\ fun\ arg\\`), []string{`-lextra fun arg\`}}, 35 {[]byte(`broken flag\`), []string{"broken", "flag"}}, 36 {[]byte("\textra whitespace\r\n"), []string{"extra", "whitespace"}}, 37 {[]byte(" \r\n "), nil}, 38 } { 39 got := splitPkgConfigOutput(test.in) 40 if !reflect.DeepEqual(got, test.want) { 41 t.Errorf("splitPkgConfigOutput(%v) = %v; want %v", test.in, got, test.want) 42 } 43 } 44 }