Files
mgmt/test/test-govet.sh
James Shubin f53376cea1 lang: Add function values and lambdas
This adds a giant missing piece of the language: proper function values!
It is lovely to now understand why early programming language designers
didn't implement these, but a joy to now reap the benefits of them. In
adding these, many other changes had to be made to get them to "fit"
correctly. This improved the code and fixed a number of bugs.
Unfortunately this touched many areas of the code, and since I was
learning how to do all of this for the first time, I've squashed most of
my work into a single commit. Some more information:

* This adds over 70 new tests to verify the new functionality.

* Functions, global variables, and classes can all be implemented
natively in mcl and built into core packages.

* A new compiler step called "Ordering" was added. It is called by the
SetScope step, and determines statement ordering and shadowing
precedence formally. It helped remove at least one bug and provided the
additional analysis required to properly capture variables when
implementing function generators and closures.

* The type unification code was improved to handle the new cases.

* Light copying of Node's allowed our function graphs to be more optimal
and share common vertices and edges. For example, if two different
closures capture a variable $x, they'll both use the same copy when
running the function, since the compiler can prove if they're identical.

* Some areas still need improvements, but this is ready for mainstream
testing and use!
2019-07-17 00:27:09 -04:00

107 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# check that go vet passes
echo running "$0"
#ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${ROOT}"
. test/util.sh
failures=''
function run-test()
{
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
}
GO_VERSION=($(go version))
function simplify-gocase() {
if grep 'case _ = <-' "$1"; then
return 1 # 'case _ = <- can be simplified to: case <-'
fi
return 0
}
function token-coloncheck() {
# add quotes to avoid matching three X's
if grep -Ei "[\/]+[\/]+[ ]*(T"'O''D'"O[^:]|F"'I''X''M'"E[^:]|X"'X'"X[^:])" "$1"; then
return 1 # tokens must end with a colon
fi
# tokens must be upper case
if grep -E "[t][Oo][Dd][Oo]|[Tt][o][Dd][Oo]|[Tt][Oo][d][Oo]|[Tt][Oo][Dd][o]|[f][Ii][Xx][Mm][Ee]|[Ff][i][Xx][Mm][Ee]|[Ff][Ii][x][Mm][Ee]|[Ff][Ii][Xx][m][Ee]|[Ff][Ii][Xx][Mm][e]|[x][Xx][Xx]|[Xx][x][Xx]|[Xx][Xx][x]" "$1"; then
return 1
fi
return 0
}
function naked-error() {
# the $ before the \t magically makes grep match the tab somehow...
if grep $'\terrors.New(' "$1"; then # missing a leading return
return 1
fi
if grep $'\tfmt.Errorf(' "$1"; then # missing a leading return
return 1
fi
if grep $'\terrwrap.Wrap' "$1"; then # missing a leading return
return 1
fi
return 0
}
function consistent-imports() {
if [ "$1" = './util/errwrap/errwrap.go' ]; then
return 0
fi
# import as github.com/purpleidea/mgmt/util/errwrap
if grep $'\t"github.com/pkg/errors"' "$1"; then
return 1
fi
# import as github.com/purpleidea/mgmt/util/errwrap
if grep $'\t"github.com/hashicorp/go-multierror"' "$1"; then
return 1
fi
# import as langutil
if grep $'\t"github.com/purpleidea/mgmt/lang/util"' "$1"; then
return 1
fi
# import as engineutil
if grep $'\t"github.com/purpleidea/mgmt/engine/util"' "$1"; then
return 1
fi
if grep '"golang.org/x/net/context"' "$1"; then # use built-in context
return 1
fi
}
# run go vet on a per-package basis
base=$(go list .)
for pkg in `go list -e ./... | grep -v "^${base}/vendor/" | grep -v "^${base}/examples/" | grep -v "^${base}/test/" | grep -v "^${base}/old" | grep -v "^${base}/old/" | grep -v "^${base}/tmp" | grep -v "^${base}/tmp/"`; do
echo -e "\tgo vet: $pkg"
# workaround go vet issues by adding the new -source flag (go1.9+)
run-test go vet -source "$pkg" || fail_test "go vet -source did not pass pkg"
done
# loop through individual *.go files
for file in `find . -maxdepth 9 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -not -path './vendor/*'`; do
#if [[ $file == "./vendor/"* ]]; then # skip files that start with...
# continue
#fi
run-test grep 'log.Print' "$file" | grep '\\n"' && fail_test 'no newline needed in log.Print*()' # no \n needed in log.Printf or log.Println
run-test simplify-gocase "$file"
run-test token-coloncheck "$file"
run-test naked-error "$file"
run-test consistent-imports "$file"
done
if [[ -n "$failures" ]]; then
echo 'FAIL'
echo 'The following tests have failed:'
echo -e "$failures"
echo
exit 1
fi
echo 'PASS'