github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/cmd/oracle/emacs-test.bash (about) 1 #!/bin/bash 2 # 3 # Simple test of Go oracle/Emacs integration. 4 # Requires that GOROOT and GOPATH are set. 5 # Side effect: builds and installs oracle in $GOROOT. 6 7 set -eu 8 9 [ -z "$GOROOT" ] && { echo "Error: GOROOT is unset." >&2; exit 1; } 10 [ -z "$GOPATH" ] && { echo "Error: GOPATH is unset." >&2; exit 1; } 11 12 log=/tmp/$(basename $0)-$$.log 13 thisdir=$(dirname $0) 14 15 function die() { 16 echo "Error: $@." 17 cat $log 18 exit 1 19 } >&2 20 21 trap "rm -f $log" EXIT 22 23 # Build and install oracle. 24 go get golang.org/x/tools/cmd/oracle || die "'go get' failed" 25 mv -f $GOPATH/bin/oracle $GOROOT/bin/ 26 $GOROOT/bin/oracle >$log 2>&1 || true # (prints usage and exits 1) 27 grep -q "Run.*help" $log || die "$GOROOT/bin/oracle not installed" 28 29 30 # Run Emacs, set the scope to the oracle tool itself, 31 # load ./main.go, and describe the "fmt" import. 32 emacs --batch --no-splash --no-window-system --no-init \ 33 --load $GOROOT/misc/emacs/go-mode.el \ 34 --load $thisdir/oracle.el \ 35 --eval ' 36 (progn 37 (setq go-oracle-scope "golang.org/x/tools/cmd/oracle") 38 (find-file "'$thisdir'/main.go") 39 (search-forward "\"fmt\"") 40 (backward-char) 41 (go-oracle-describe) 42 (princ (with-current-buffer "*go-oracle*" 43 (buffer-substring-no-properties (point-min) (point-max)))) 44 (kill-emacs 0)) 45 ' main.go >$log 2>&1 || die "emacs command failed" 46 47 # Check that Println is mentioned. 48 grep -q "fmt/print.go.*func Println" $log || die "didn't find expected lines in log; got:" 49 50 echo "PASS"