mirror of
https://github.com/golang/go
synced 2024-11-18 16:04:44 -07:00
19c83edf02
go-guru--run has been split up to separate running the tool from turning its output into compilation-mode form. The definition command uses only the first part, and parses its output in JSON form. Added test, factoring the test script. Change-Id: I4c3e4a51a1346551a3703a5e3137c878d7b2d95f Reviewed-on: https://go-review.googlesource.com/19499 Reviewed-by: Michael Matloob <matloob@golang.org>
74 lines
2.0 KiB
Bash
Executable File
74 lines
2.0 KiB
Bash
Executable File
#!/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"
|
|
|
|
# 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 '
|
|
(progn
|
|
(princ (emacs-version)) ; requires Emacs v23
|
|
(find-file "'$thisdir'/main.go")
|
|
(insert "// modify but do not save the editor buffer\n")
|
|
(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))
|
|
'
|
|
expect_log "fmt/print.go.*func Println"
|
|
|
|
# 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"
|
|
|
|
echo "PASS"
|