Skip to content

Commit

Permalink
Merge branch 'refmt-tool-cmd'
Browse files Browse the repository at this point in the history
  • Loading branch information
warpfork committed Oct 15, 2017
2 parents 3623b39 + b243a1b commit 3df1bf6
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
36 changes: 36 additions & 0 deletions cmd/refmt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"os"

"github.com/polydawn/refmt/cbor"
"github.com/polydawn/refmt/pretty"
"github.com/polydawn/refmt/shared"
)

func main() {
in, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
bs := make([]byte, len(in)/2)
n, err := hex.Decode(bs, in)
if err != nil {
panic(err)
}
if n != len(in)/2 {
panic(fmt.Errorf("hex len mismatch: %d chars became %d bytes", len(in), n))
}

pump := shared.TokenPump{
cbor.NewDecoder(bytes.NewBuffer(bs)),
pretty.NewEncoder(os.Stdout),
}
if err := pump.Run(); err != nil {
panic(err)
}
}
60 changes: 59 additions & 1 deletion goad
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -euo pipefail
### Project details
name="refmt"
pkg="github.com/polydawn/$name" # everything under here will be tested
cmd="$pkg/cmd/$name" # if you have a main.main not at the repo root, set this



Expand Down Expand Up @@ -38,6 +39,12 @@ TEST_TIMEOUT="${TEST_TIMEOUT:-"5s"}"
if [ -z "$SUBCOMMAND" ] ; then
(
go fmt "$SUBSECTION"
go install -ldflags "$LDFLAGS" "$cmd" && {
echo -e "\E[1;32minstall successful.\E[0;m\n"
} || {
echo -e "\E[1;41minstall failed!\E[0;m"
exit 8
}
go test "$SUBSECTION" -timeout="$TEST_TIMEOUT" && {
echo -e "\n\E[1;32mall tests green.\E[0;m"
} || {
Expand All @@ -52,6 +59,13 @@ else
# passthrough for other commands
go "$@"
;;
env)
echo "GOROOT=`go env GOROOT`"
echo "GOPATH=`go env GOPATH`"
;;
path)
echo "$GOPATH"
;;
init)
# it's your responsibility to do this the first time
# (we don't do it at the front of every build because it will move submodules if you already have them, and that might not be what you want as you're plowing along)
Expand All @@ -70,14 +84,58 @@ else
exit 4
}
;;
install)
go install -ldflags "$LDFLAGS" "$cmd"
;;
bench)
profPath="$GOPATH/tmp/prof/"
mkdir -p "$profPath"
set +e ; shift ; set -e # munch $subsection from passing on in "$@"
go test -i "$SUBSECTION" "$@" &&
GOCONVEY_REPORTER=silent \
go test \
-run=XXX -bench=. \
-o "$profPath/bench.bin" \
-cpuprofile="$profPath/cpu.pprof" \
"$SUBSECTION" "$@" || {
echo -e "\E[1;41msome benchmarks failed!\E[0;m"
exit 4
}
# use e.g.: go tool pprof --text .gopath/tmp/prof/bench.bin .gopath/tmp/prof/cpu.pprof
;;
fmt)
go fmt "$SUBSECTION"
;;
doc)
set +e ; shift ; set -e # munch $subsection from passing on in "$@"
for package in $(go list "$SUBSECTION" | sed "s#^_${PWD}#${pkg}#"); do
echo -e "==== $package ====\n"
godoc "$@" "$package"
echo -e "\n\n\n"
done
;;
cover)
coverFile="$GOPATH/tmp/cover/cover.out"
mkdir -p "$(dirname "$coverFile")"
for package in $(go list "$SUBSECTION" | sed "s#^_${PWD}#${pkg}#"); do
rm -f "$coverFile"
echo "==== $package ===="
go test -coverprofile="$coverFile" "$package" && \
[ -f "$coverFile" ] && \
echo ---- && \
go tool cover -func="$coverFile" && \
echo ---- && \
go tool cover -html="$coverFile"
echo ====
echo
done
rm -f "$coverFile"
;;
clean)
rm -rf "$GOBIN" "$GOPATH/pkg" "$GOPATH/tmp"
;;
*)
echo "Usage: $0 {init|test|fmt|clean}" 1>&2;
echo "Usage: $0 {init|test|install|bench|fmt|doc|cover|clean}" 1>&2;
exit 1
;;
esac
Expand Down

0 comments on commit 3df1bf6

Please sign in to comment.