1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:04:40 -07:00
go/cmd/guru/emacs-test.bash
Alan Donovan e08a7ae6bc cmd/guru: add support for loading modified files
The -modified flag causes guru to read a simple archive file from stdin.
This archive specifies alternative contents for one or more file names.
The build.Context checks this table before delegating to the usual
behavior.

This will not work for files that import "C" since cgo accesses the
file system directly.

Added end-to-end test via Emacs.

Simplify findQueryPos (now: fileOffsetToPos)

Credit: Daniel Morsing, for the prototype of this feature.

Change-Id: I5ae818ed5e8bb81001781893dded2d085e9cf8d6
Reviewed-on: https://go-review.googlesource.com/19498
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-02-15 15:04:13 +00:00

51 lines
1.5 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"
# Run Emacs, set the scope to the guru tool itself,
# load ./main.go, and describe the "fmt" import.
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 '
(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))
' main.go >$log 2>&1 || die "emacs command failed"
# Check that Println is mentioned.
grep -q "fmt/print.go.*func Println" $log || die "didn't find expected lines in log; got:"
echo "PASS"