github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/misc/vim/ftplugin/go/test.sh (about) 1 #!/bin/bash -e 2 # 3 # Copyright 2012 The Go Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style 5 # license that can be found in the LICENSE file. 6 # 7 # Tests for import.vim. 8 9 cd $(dirname $0) 10 11 cat > base.go <<EOF 12 package test 13 14 import ( 15 "bytes" 16 "io" 17 "net" 18 19 "mycorp/foo" 20 ) 21 EOF 22 23 fail=0 24 25 # usage: test_one command pattern 26 # Pattern is a PCRE expression that will match across lines. 27 test_one() { 28 echo 2>&1 -n "$1: " 29 vim -e -s -u /dev/null -U /dev/null --noplugin -c "source import.vim" \ 30 -c "$1" -c 'wq! test.go' base.go 31 # ensure blank lines are treated correctly 32 if ! gofmt test.go | cmp test.go -; then 33 echo 2>&1 "gofmt conflict" 34 gofmt test.go | diff -u test.go - | sed "s/^/ /" 2>&1 35 fail=1 36 return 37 fi 38 if ! [[ $(cat test.go) =~ $2 ]]; then 39 echo 2>&1 "$2 did not match" 40 cat test.go | sed "s/^/ /" 2>&1 41 fail=1 42 return 43 fi 44 echo 2>&1 "ok" 45 } 46 47 # Tests for Import 48 49 test_one "Import baz" '"baz".*"bytes"' 50 test_one "Import io/ioutil" '"io".*"io/ioutil".*"net"' 51 test_one "Import myc" '"io".*"myc".*"net"' # prefix of a site prefix 52 test_one "Import nat" '"io".*"nat".*"net"' 53 test_one "Import net/http" '"net".*"net/http".*"mycorp/foo"' 54 test_one "Import zoo" '"net".*"zoo".*"mycorp/foo"' 55 test_one "Import mycorp/bar" '"net".*"mycorp/bar".*"mycorp/foo"' 56 test_one "Import mycorp/goo" '"net".*"mycorp/foo".*"mycorp/goo"' 57 58 # Tests for Drop 59 60 cat > base.go <<EOF 61 package test 62 63 import ( 64 "foo" 65 66 "something" 67 "zoo" 68 ) 69 EOF 70 71 test_one "Drop something" '\([^"]*"foo"[^"]*"zoo"[^"]*\)' 72 73 rm -f base.go test.go 74 if [ $fail -gt 0 ]; then 75 echo 2>&1 "FAIL" 76 exit 1 77 fi 78 echo 2>&1 "PASS"