From c5d1652a7fbf91c5bdb2b8a530d6899de03c94f3 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 21 Apr 2015 11:46:43 +0200 Subject: [PATCH 1/3] test: Check more packages with gofmt and go vet Run go vet against packages in FORMATTABLE list instead of TESTABLE_AND_FORMATTABLE. The TESTABLE part should be only about packages that provide _test.go source files. Also, add more packages to check for formatting and suspicious constructs. --- test | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test b/test index fecd750..eb6fa8f 100755 --- a/test +++ b/test @@ -15,7 +15,7 @@ COVER=${COVER:-"-cover"} source ./build TESTABLE_AND_FORMATTABLE="pkg/keystore pkg/lock pkg/tar rkt rkt/config stage1/init store" -FORMATTABLE="$TESTABLE_AND_FORMATTABLE common networking stage0/run.go version" +FORMATTABLE="$TESTABLE_AND_FORMATTABLE common common/apps networking networking/netinfo pkg/aci pkg/keystore/keystoretest pkg/sys stage0 stage1 stage1/gc tests tests/inspect tests/test-auth-server tests/test-auth-server/aci version" # user has not provided PKG override if [ -z "$PKG" ]; then @@ -47,8 +47,12 @@ if [ -n "${fmtRes}" ]; then exit 255 fi +# split FMT into an array and prepend REPO_PATH to each local package for go vet +split_vet=(${FMT// / }) +VET_TEST=${split_vet[@]/#/${REPO_PATH}/} + echo "Checking govet..." -vetRes=$(go vet $TEST) +vetRes=$(go vet $VET_TEST) if [ -n "${vetRes}" ]; then echo -e "govet checking failed:\n${vetRes}" exit 255 From 638a8f0b8276b2e42ee9c87f82db87a633abbda3 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 21 Apr 2015 11:49:00 +0200 Subject: [PATCH 2/3] functional tests: Fix gofmt and go vet issues --- tests/inspect/inspect.go | 2 +- tests/rkt_auth_test.go | 6 +++--- tests/test-auth-server/aci/server.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/inspect/inspect.go b/tests/inspect/inspect.go index b9ffe1d..ee9a20e 100644 --- a/tests/inspect/inspect.go +++ b/tests/inspect/inspect.go @@ -63,7 +63,7 @@ func main() { globalFlagset.Parse(os.Args[1:]) args := globalFlagset.Args() if len(args) > 0 { - fmt.Fprintln(os.Stderr, "Wrong parameters\n") + fmt.Fprintln(os.Stderr, "Wrong parameters") os.Exit(1) } diff --git a/tests/rkt_auth_test.go b/tests/rkt_auth_test.go index 06020da..efba529 100644 --- a/tests/rkt_auth_test.go +++ b/tests/rkt_auth_test.go @@ -48,9 +48,9 @@ const ( ) type genericAuthTest struct { - name string - confDir authConfDir - expectedLine string + name string + confDir authConfDir + expectedLine string } func TestAuthBasic(t *testing.T) { diff --git a/tests/test-auth-server/aci/server.go b/tests/test-auth-server/aci/server.go index a037b91..2fe4926 100644 --- a/tests/test-auth-server/aci/server.go +++ b/tests/test-auth-server/aci/server.go @@ -229,7 +229,7 @@ func NewServerWithPaths(auth Type, msgCapacity int, acTool, goTool string) (*Ser func getTool(tool string) (string, error) { toolPath, err := exec.LookPath(tool) if err != nil { - return "", fmt.Errorf("failed to find %s in $PATH: $v", tool, err) + return "", fmt.Errorf("failed to find %s in $PATH: %v", tool, err) } absToolPath, err := filepath.Abs(toolPath) if err != nil { From b46eb513ad0fe8e1924027bff1e7fa254d26a1cc Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 21 Apr 2015 12:35:27 +0200 Subject: [PATCH 3/3] test: Compute testable and/or formattable directories Basically we want to run go test on all directories where _test.go files reside excluding functional tests and Godeps. I'm rather not sure about the last one - it might be useful to check if our Godeps pass their tests. We also want to check for formatting and suspicious constructs on all .go files. So instead of hardcoding the list, employ some basic tools to produce the list for us. That way we don't have to maintain the list - nobody ever remembers about that thing. --- test | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/test b/test index eb6fa8f..e2bc8c3 100755 --- a/test +++ b/test @@ -14,8 +14,37 @@ COVER=${COVER:-"-cover"} source ./build -TESTABLE_AND_FORMATTABLE="pkg/keystore pkg/lock pkg/tar rkt rkt/config stage1/init store" -FORMATTABLE="$TESTABLE_AND_FORMATTABLE common common/apps networking networking/netinfo pkg/aci pkg/keystore/keystoretest pkg/sys stage0 stage1 stage1/gc tests tests/inspect tests/test-auth-server tests/test-auth-server/aci version" +function find_dirs_with_suffixed_files +{ + # File suffix, can contain dots, asterisks and question marks - + # they will be escaped. Use of other metacharacters is at your own + # risk. + local suffix="$1" + # Escape question mark and asterisk metacharacters from suffix, so + # they are matched literally in find command. + local find_escaped_suffix=$(echo "${suffix}" | sed -e 's/\([?*]\)/\\\1/g') + # Escape dot and asterisk metacharacters from suffix, so they are + # matched literally in sed 's' command. + local sed_escaped_suffix=$(echo "${suffix}" | sed -e 's/\([.*]\)/\\\1/g') + # Variable 'exclude' is an POSIX ERE fragment to be put between + # '^(' and ')$'. + local exclude="$2" + # Find all files ending with given suffix, ... + find . -name '*'"${find_escaped_suffix}" | + # ... remove files with given suffix together with preceding slash, ... + sed -e 's/\/[[:alnum:]_]\+'"${sed_escaped_suffix}"'//g' | + # ... remove leading './', ... + sed -e 's/^\.\///g' | + # ... sort alphabetically, ... + sort | + # ... remove repeated directories, ... + uniq | + # ... and filter out given directories. + grep -vEe '^('"${exclude}"')$' +} + +TESTABLE_AND_FORMATTABLE=$(find_dirs_with_suffixed_files '_test.go' 'Godeps/.*|tests') +FORMATTABLE=$(find_dirs_with_suffixed_files '.go' 'Godeps/.*') # user has not provided PKG override if [ -z "$PKG" ]; then