diff --git a/.circleci/config.yml b/.circleci/config.yml index 45a53033..d518f4c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,9 +46,7 @@ workflows: echo 'export PATH="$PATH:/c/Program Files/Go/bin"' > $BASH_ENV - run: go version - - go/lint: - golangci-lint-version: 1.48.0 - + - lint - build - run @@ -107,13 +105,13 @@ jobs: steps: run: name: build binaries - command: bin/goreleaser --rm-dist --snapshot + command: bin/goreleaser --rm-dist --snapshot --config .project/goreleaser.yml - when: condition: << parameters.publish >> steps: run: name: build and publish binaries - command: bin/goreleaser --rm-dist --skip-validate + command: bin/goreleaser --rm-dist --skip-validate --config .project/goreleaser.yml - store_artifacts: path: ./dist destination: dist @@ -130,6 +128,26 @@ jobs: go build -o dist/gotestsum . - run: dist/gotestsum + lint: + executor: + name: go/golang + tag: 1.19-alpine + steps: + - checkout + - run: go mod download + - run: + name: Install golangci-lint + command: | + mkdir -p /go/bin + + download=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh + wget -O- -q "$download" | sh -s -- -b /go/bin/ v1.48.0 + - run: + name: Lint + command: | + golangci-lint run -v --concurrency 2 --config .project/golangci-lint.yml + + update-windows-golden: executor: windows steps: diff --git a/.github/workflows/sync-main.yaml b/.github/workflows/sync-main.yaml deleted file mode 100644 index 3f052d06..00000000 --- a/.github/workflows/sync-main.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: Merge main into master - -on: - push: - branches: [main] - -jobs: - sync: - name: Merge main branch - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: {fetch-depth: 0} - - name: merge - run: | - git checkout master - git merge --ff-only main - git push origin master diff --git a/.gitignore b/.gitignore index ce77fdac..a96bf81d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ vendor/ -.dobi/ dist/ junit.xml .plsdo/ diff --git a/.plsdo.sh b/.plsdo.sh deleted file mode 100644 index 94c08567..00000000 --- a/.plsdo.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -# plsdo.sh, version 0.1.1 -set -o errexit -o nounset -o pipefail - -_plsdo_run() { - case "${1-}" in - ""|help) - _plsdo_help "${2-}" ;; - *) - "$@" ;; - esac -} - -declare -A help - -help[list]="Print the list of tasks" -list() { - declare -F | awk '{print $3}' | grep -v '^_' -} - -_plsdo_help_task_name_width="${_plsdo_help_task_name_width:-12}" - -_plsdo_help() { - local topic="${1-}" - # print help for the topic - if [ -n "$topic" ]; then - if ! command -v "$topic" > /dev/null ; then - _plsdo_error "No such task: $topic" - return 1 - fi - - printf "\nUsage:\n %s %s\n\n%s\n" "$0" "$topic" "${help[$topic]-}" - return 0 - fi - - # print list of tasks and their help line. - [ -n "${banner-}" ] && echo "$banner" && echo - for i in $(list); do - printf "%-${_plsdo_help_task_name_width}s\t%s\n" "$i" "${help[$i]-}" | head -1 - done -} - -_plsdo_error() { - >&2 echo "$@" -} - -# shellcheck disable=SC2016 -help[_plsdo_completion]='Print tab completion for $SHELL. - -Redirect the output to a file that will be run when the shell starts, -such as ~/.bashrc. - - $ ./do _pldsdo_completion >> ~/.bash_complete/do -' -_plsdo_completion() { - local shell; shell="$(basename "$SHELL" 2> /dev/null)" - case "$shell" in - bash) - cat <<+++ -_dotslashdo_completions() { - if ! command -v $0 > /dev/null; then return; fi - if [ "\${#COMP_WORDS[@]}" != "2" ]; then return; fi - COMPREPLY=(\$(compgen -W "\$($0 list)" "\${COMP_WORDS[1]}")) -} -complete -F _dotslashdo_completions $0 -+++ - ;; - "") - _plsdo_error "Set \$SHELL to select tab completion." - return 1 ;; - *) - _plsdo_error "No completetion for shell: $shell" - return 1 ;; - esac -} diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 0cf49d19..00000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,9 +0,0 @@ -- id: gotestsum - name: gotestsum - description: | - `go test` runner with output optimized for humans, JUnit XML for CI - integration, and a summary of the test results. - entry: gotestsum - types: [go] - language: golang - pass_filenames: false diff --git a/Dockerfile b/.project/Dockerfile similarity index 75% rename from Dockerfile rename to .project/Dockerfile index 592d86c4..7fb9b5db 100644 --- a/Dockerfile +++ b/.project/Dockerfile @@ -1,6 +1,6 @@ ARG GOLANG_VERSION -FROM golang:${GOLANG_VERSION:-1.14-alpine} as golang +FROM golang:${GOLANG_VERSION:-1.18-alpine} as golang RUN apk add -U curl git bash ENV CGO_ENABLED=0 \ PS1="# " \ @@ -11,13 +11,11 @@ USER ${UID}:${UID} FROM golang as tools -RUN go get github.com/dnephin/filewatcher@v0.3.2 RUN wget -O- -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s && \ mv bin/golangci-lint /go/bin FROM golang as dev -COPY --from=tools /go/bin/filewatcher /usr/bin/filewatcher COPY --from=tools /go/bin/golangci-lint /usr/bin/golangci-lint diff --git a/docs/running-without-go.md b/.project/docs/running-without-go.md similarity index 100% rename from docs/running-without-go.md rename to .project/docs/running-without-go.md diff --git a/.golangci.yml b/.project/golangci-lint.yml similarity index 100% rename from .golangci.yml rename to .project/golangci-lint.yml diff --git a/.goreleaser.yml b/.project/goreleaser.yml similarity index 100% rename from .goreleaser.yml rename to .project/goreleaser.yml diff --git a/README.md b/README.md index f392f0d7..04763a61 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,13 @@ `gotestsum` runs tests using `go test -json`, prints formatted test output, and a summary of the test run. It is designed to work well for both local development, and for automation like CI. -`gotest.tools/gotestsum/testjson` ([godoc](https://pkg.go.dev/gotest.tools/gotestsum/testjson)) is a library -that can be used to read [`test2json`](https://golang.org/cmd/test2json/) output. - -See the [documentation](#documentation) for more details. ## Install Download a binary from [releases](https://github.com/gotestyourself/gotestsum/releases), or build from source with `go install gotest.tools/gotestsum@latest`. With `go` version before 1.17, use `go get gotest.tools/gotestsum`. -## Demo -A demonstration of three `--format` options. - -![Demo](https://i.ibb.co/XZfhmXq/demo.gif) -
[Source](https://github.com/gotestyourself/gotestsum/tree/readme-demo/scripts) - -## Documentation - -### Index +## Documentation **Core features** - [Output Format](#output-format) from compact to verbose, with color highlighting. @@ -28,15 +16,16 @@ A demonstration of three `--format` options. - [Add `go test` flags](#custom-go-test-command), or [run a compiled test binary](#executing-a-compiled-test-binary). -**Automation and CI** -- [JUnit XML file](#junit-xml-output) for integration with CI systems. -- [JSON file](#json-file-output) to capture the `test2json` output in a file. -- [Re-run failed tests](#re-running-failed-tests) to save time when dealing with flaky test suites. +**CI and Automation** +- [`--junitfile`](#junit-xml-output) - write a JUnit XML file for integration with CI systems. +- [`--jsonfile`](#json-file-output) - write the `test2json` output in a file. +- [`--rerun-fails`](#re-running-failed-tests) - run failed tests again to save time when dealing with flaky test suites. **Local Development** -- [Post run commands](#post-run-command) may be used for desktop notification. -- [Run tests when a file is saved](#run-tests-when-a-file-is-saved). -- [Find or skip slow tests](#finding-and-skipping-slow-tests) using `gotestsum tool slowest`. +- [`--watch`](#run-tests-when-a-file-is-saved) - when a file is saved, run the tests for the package that includes the file. +- [`--post-run-command`](#post-run-command) - run a command after the tests, can be used for desktop notification. +- [`gotestsum tool slowest`](#finding-and-skipping-slow-tests) - find the slowest tests, also update slow tests to be skipepd with `-short`. + ### Output Format @@ -55,6 +44,13 @@ Commonly used formats (see `--help` for a full list): Have an idea for a new format? Please [share it on github](https://github.com/gotestyourself/gotestsum/issues/new)! +#### Demo + +A demonstration of three `--format` options. + +![Demo](https://user-images.githubusercontent.com/442180/182284939-e08a0aa5-4504-4e30-9e88-207ef47f4537.gif) +
[Source](https://github.com/gotestyourself/gotestsum/tree/readme-demo/scripts) + ### Summary Following the formatted output is a summary of the test run. The summary includes: @@ -297,7 +293,7 @@ output. `./binary.test` is the path to the compiled test binary. The `-test.v` must be included so that `go tool test2json` receives all the output. To execute a test binary without installing Go, see -[running without go](./docs/running-without-go.md). +[running without go](./.project/docs/running-without-go.md). ### Finding and skipping slow tests diff --git a/cmd/handler.go b/cmd/handler.go index d51ef613..773ceac0 100644 --- a/cmd/handler.go +++ b/cmd/handler.go @@ -8,7 +8,7 @@ import ( "path/filepath" "gotest.tools/gotestsum/internal/junitxml" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" "gotest.tools/gotestsum/testjson" ) diff --git a/cmd/main.go b/cmd/main.go index 3e4645e8..020b1cef 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,7 +14,7 @@ import ( "github.com/dnephin/pflag" "github.com/fatih/color" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" "gotest.tools/gotestsum/testjson" ) diff --git a/cmd/tool/slowest/ast.go b/cmd/tool/slowest/ast.go index 3fbc8a57..d232434e 100644 --- a/cmd/tool/slowest/ast.go +++ b/cmd/tool/slowest/ast.go @@ -10,7 +10,7 @@ import ( "strings" "golang.org/x/tools/go/packages" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" "gotest.tools/gotestsum/testjson" ) diff --git a/cmd/tool/slowest/slowest.go b/cmd/tool/slowest/slowest.go index 0221b1cf..a2c13275 100644 --- a/cmd/tool/slowest/slowest.go +++ b/cmd/tool/slowest/slowest.go @@ -9,7 +9,7 @@ import ( "github.com/dnephin/pflag" "gotest.tools/gotestsum/internal/aggregate" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" "gotest.tools/gotestsum/testjson" ) diff --git a/do b/do index aed4df15..21920f8c 100755 --- a/do +++ b/do @@ -1,6 +1,7 @@ #!/usr/bin/env bash +set -o errexit -o nounset -o pipefail -source .plsdo.sh +declare -A help binary() { mkdir -p dist @@ -13,22 +14,11 @@ binary-static() { } update-golden() { - #_update-golden - if ldd ./dist/gotestsum > /dev/null 2>&1; then - binary-static - fi - GOLANG_VERSION=1.13-alpine ./do shell ./do _update-golden - GOLANG_VERSION=1.14.6-alpine ./do shell ./do _update-golden -} - -_update-golden() { - PATH="$PWD/dist:$PATH" gotestsum -- \ - ./cmd ./testjson ./internal/junitxml ./cmd/tool/slowest \ - -test.update-golden + gotestsum -- ./... -update } lint() { - golangci-lint run -v + golangci-lint run -v --config .project/golangci-lint.yml } go-mod-tidy() { @@ -57,7 +47,7 @@ shell() { _docker-build-dev() { set -e local idfile=".plsdo/docker-build-dev-image-id-${GOLANG_VERSION-default}" - local dockerfile=Dockerfile + local dockerfile=.project/Dockerfile local tag=gotest.tools/gotestsum/builder if [ -f "$idfile" ] && [ "$dockerfile" -ot "$idfile" ]; then cat "$idfile" @@ -83,4 +73,38 @@ godoc() { command godoc -http=:6060 } +help[list]="Print the list of tasks" +list() { + declare -F | awk '{print $3}' | grep -v '^_' +} + +_plsdo_help() { + local topic="${1-}" + # print help for the topic + if [ -n "$topic" ]; then + if ! command -v "$topic" > /dev/null ; then + >&2 echo "No such task: $topic" + return 1 + fi + + printf "\nUsage:\n %s %s\n\n%s\n" "$0" "$topic" "${help[$topic]-}" + return 0 + fi + + # print list of tasks and their help line. + [ -n "${banner-}" ] && echo "$banner" && echo + for i in $(list); do + printf "%-12s\t%s\n" "$i" "${help[$i]-}" | head -1 + done +} + +_plsdo_run() { + case "${1-}" in + ""|help) + _plsdo_help "${2-}" ;; + *) + "$@" ;; + esac +} + _plsdo_run "$@" diff --git a/docs/demo.gif b/docs/demo.gif deleted file mode 100644 index a77497b0..00000000 Binary files a/docs/demo.gif and /dev/null differ diff --git a/internal/filewatcher/term_unix.go b/internal/filewatcher/term_unix.go index 58109a0a..cf9b7d0f 100644 --- a/internal/filewatcher/term_unix.go +++ b/internal/filewatcher/term_unix.go @@ -11,7 +11,7 @@ import ( "os" "golang.org/x/sys/unix" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" ) type terminal struct { diff --git a/internal/filewatcher/watch.go b/internal/filewatcher/watch.go index 230183ea..e639f279 100644 --- a/internal/filewatcher/watch.go +++ b/internal/filewatcher/watch.go @@ -13,7 +13,7 @@ import ( "time" "github.com/fsnotify/fsnotify" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" ) const maxDepth = 7 diff --git a/internal/junitxml/report.go b/internal/junitxml/report.go index 703ed619..8520969f 100644 --- a/internal/junitxml/report.go +++ b/internal/junitxml/report.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" "gotest.tools/gotestsum/testjson" ) diff --git a/log/log.go b/internal/log/log.go similarity index 100% rename from log/log.go rename to internal/log/log.go diff --git a/main.go b/main.go index dcd4fb24..df3e7903 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "gotest.tools/gotestsum/cmd" "gotest.tools/gotestsum/cmd/tool" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" ) func main() { diff --git a/testjson/dotformat.go b/testjson/dotformat.go index 0345f0af..fa00d364 100644 --- a/testjson/dotformat.go +++ b/testjson/dotformat.go @@ -10,7 +10,7 @@ import ( "golang.org/x/term" "gotest.tools/gotestsum/internal/dotwriter" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" ) func dotsFormatV1(event TestEvent, exec *Execution) string { diff --git a/testjson/execution.go b/testjson/execution.go index a2ce5dff..dd6e5070 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -13,7 +13,7 @@ import ( "time" "golang.org/x/sync/errgroup" - "gotest.tools/gotestsum/log" + "gotest.tools/gotestsum/internal/log" ) // Action of TestEvent