go>> gtfo>> 返回
项目作者: nobe4

项目描述 :
Go Test FOrmat
高级语言: Go
项目地址: git://github.com/nobe4/gtfo.git
创建时间: 2020-05-12T17:37:33Z
项目社区:https://github.com/nobe4/gtfo

开源协议:MIT License

下载


GTFO

Go Test FOrmat

This package aims at creating a simple formatter for the test logs in golang.

In a sense, this adds a missing -format to the go test command. This is
required in some cases when the editor expect some defined-output from a
command in order to jump directly to the issues.

Usage

gtfo accepts only the JSON output from go test, so you can call it in the
following way:

  1. go test -json ./... | gtfo

All the flags for test should work as well, tho you might not get the
expected output. I recommend using gtfo for testing and jumping to results
directly, but not for complete output.

Configuration

You can pass a string to the -format flag to specify how you want to format
your output. The syntax follows golang’s
template
. Have a look at
formatter.go for more informations.

Example

If we make a test in
parser_test.go fail, we might get the
following output:

  1. $ go test ./...
  2. ? github.com/nobe4/gtfo/cmd/gtfo [no test files]
  3. ok github.com/nobe4/gtfo/internal/formatter 0.523s
  4. ok github.com/nobe4/gtfo/internal/module (cached)
  5. --- FAIL: TestCases (14.80s)
  6. parser_test.go:188: No Test
  7. ...
  8. parser_test.go:188: Fatal and fatal
  9. parser_test.go:197:
  10. Error Trace: parser_test.go:197
  11. Error: Not equal:
  12. expected: "8"
  13. actual : "9"
  14. Diff:
  15. --- Expected
  16. +++ Actual
  17. @@ -1 +1 @@
  18. -8
  19. +9
  20. Test: TestCases
  21. FAIL
  22. FAIL github.com/nobe4/gtfo/internal/parser 15.223s
  23. FAIL
  1. $ go test -json ./... | gtfo
  2. internal/formatter/parser_test.go:188: No Test
  3. ...
  4. internal/formatter/parser_test.go:188: Fatal and fatal
  5. internal/formatter/parser_test.go:197:
  6. Error Trace: parser_test.go:197
  7. Error: Not equal:
  8. expected: "8"
  9. actual : "9"
  10. Diff:
  11. --- Expected
  12. +++ Actual
  13. @@ -1 +1 @@
  14. -8
  15. +9
  16. Test: TestCases

We have the full path from the root directory to the file in question, which
allows for easier jumping to it.

With a special format:

  1. $ go test -json ./... | gtfo -format "{{.File}}:{{.Line}}:{{.Output}}\n"
  2. parser_test.go:188:No Test
  3. ...
  4. parser_test.go:188:Fatal and fatal
  5. parser_test.go:197:
  6. Error Trace: parser_test.go:197
  7. Error: Not equal:
  8. expected: "8"
  9. actual : "9"
  10. Diff:
  11. --- Expected
  12. +++ Actual
  13. @@ -1 +1 @@
  14. -8
  15. +9
  16. Test: TestCases

Installation

Clone and build:

  1. make build

You might want to change some environment variables, e.g.:

  1. GOOS=linux make build

Contribute

Ideas and improvement in TODO.