2016-02-11 15:57:17 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Simple test of Go guru/Emacs integration.
|
|
|
|
# Requires that GOROOT and GOPATH are set.
|
|
|
|
# Side effect: builds and installs guru in $GOROOT.
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
[ -z "$GOROOT" ] && { echo "Error: GOROOT is unset." >&2; exit 1; }
|
|
|
|
[ -z "$GOPATH" ] && { echo "Error: GOPATH is unset." >&2; exit 1; }
|
|
|
|
|
|
|
|
log=/tmp/$(basename $0)-$$.log
|
|
|
|
thisdir=$(dirname $0)
|
|
|
|
|
|
|
|
function die() {
|
|
|
|
echo "Error: $@."
|
|
|
|
cat $log
|
|
|
|
exit 1
|
|
|
|
} >&2
|
|
|
|
|
|
|
|
trap "rm -f $log" EXIT
|
|
|
|
|
|
|
|
# Build and install guru.
|
|
|
|
go get golang.org/x/tools/cmd/guru || die "'go get' failed"
|
|
|
|
mv -f $GOPATH/bin/guru $GOROOT/bin/
|
|
|
|
$GOROOT/bin/guru >$log 2>&1 || true # (prints usage and exits 1)
|
|
|
|
grep -q "Run.*help" $log || die "$GOROOT/bin/guru not installed"
|
|
|
|
|
2016-02-15 09:45:55 -07:00
|
|
|
# Usage: run_emacs <elisp>
|
|
|
|
function run_emacs() {
|
|
|
|
emacs --batch --no-splash --no-window-system --no-init \
|
|
|
|
--load $GOPATH/src/github.com/dominikh/go-mode.el/go-mode.el \
|
|
|
|
--load $thisdir/guru.el \
|
|
|
|
--eval "$1" >$log 2>&1 || die "emacs command failed"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Usage: expect_log <regex>
|
|
|
|
function expect_log() {
|
|
|
|
grep -q "$1" $log || die "didn't find expected lines in log; got:"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load main.go and describe the "fmt" import.
|
|
|
|
# Check that Println is mentioned.
|
|
|
|
run_emacs '
|
2016-02-11 15:57:17 -07:00
|
|
|
(progn
|
2016-02-11 22:04:56 -07:00
|
|
|
(princ (emacs-version)) ; requires Emacs v23
|
2016-02-11 15:57:17 -07:00
|
|
|
(find-file "'$thisdir'/main.go")
|
2016-02-14 20:14:31 -07:00
|
|
|
(insert "// modify but do not save the editor buffer\n")
|
2016-02-11 15:57:17 -07:00
|
|
|
(search-forward "\"fmt\"")
|
|
|
|
(backward-char)
|
|
|
|
(go-guru-describe)
|
|
|
|
(princ (with-current-buffer "*go-guru*"
|
|
|
|
(buffer-substring-no-properties (point-min) (point-max))))
|
|
|
|
(kill-emacs 0))
|
2016-02-15 09:45:55 -07:00
|
|
|
'
|
|
|
|
expect_log "fmt/print.go.*func Println"
|
2016-02-11 15:57:17 -07:00
|
|
|
|
2016-02-15 09:45:55 -07:00
|
|
|
# Jump to the definition of flag.Bool.
|
|
|
|
run_emacs '
|
|
|
|
(progn
|
|
|
|
(find-file "'$thisdir'/main.go")
|
|
|
|
(search-forward "flag.Bool")
|
|
|
|
(backward-char)
|
|
|
|
(go-guru-definition)
|
|
|
|
(message "file: %s" (buffer-file-name))
|
|
|
|
(message "line: %s" (buffer-substring (line-beginning-position)
|
|
|
|
(line-end-position)))
|
|
|
|
(kill-emacs 0))
|
|
|
|
'
|
|
|
|
expect_log "^file: .*flag.go"
|
|
|
|
expect_log "^line: func Bool"
|
2016-02-11 15:57:17 -07:00
|
|
|
|
|
|
|
echo "PASS"
|