gtfo

module
v0.0.0-...-471a937 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2020 License: MIT

README

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:

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:

$ go test ./...
?       github.com/nobe4/gtfo/cmd/gtfo  [no test files]
ok      github.com/nobe4/gtfo/internal/formatter        0.523s
ok      github.com/nobe4/gtfo/internal/module   (cached)
--- FAIL: TestCases (14.80s)
    parser_test.go:188: No Test
    ...
    parser_test.go:188: Fatal and fatal
    parser_test.go:197:
                Error Trace:    parser_test.go:197
                Error:          Not equal:
                                expected: "8"
                                actual  : "9"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -8
                                +9
                Test:           TestCases
FAIL
FAIL    github.com/nobe4/gtfo/internal/parser   15.223s
FAIL
$ go test -json ./... | gtfo
internal/formatter/parser_test.go:188: No Test
...
internal/formatter/parser_test.go:188: Fatal and fatal
internal/formatter/parser_test.go:197:
                Error Trace:    parser_test.go:197
                Error:          Not equal:
                                expected: "8"
                                actual  : "9"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -8
                                +9
                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:

$ go test -json ./... | gtfo -format "{{.File}}:{{.Line}}:{{.Output}}\n"
parser_test.go:188:No Test
...
parser_test.go:188:Fatal and fatal
parser_test.go:197:
                Error Trace:    parser_test.go:197
                Error:          Not equal:
                                expected: "8"
                                actual  : "9"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -8
                                +9
                Test:           TestCases

Installation

Clone and build:

make build

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

GOOS=linux make build

Contribute

Ideas and improvement in TODO.

Directories

Path Synopsis
cmd
gtfo
GTFO parses and allow to format output from go test.
GTFO parses and allow to format output from go test.
internal
formatter
Package formatter handlers how each logs will be displayed in the terminal.
Package formatter handlers how each logs will be displayed in the terminal.
module
Package module is fetching the current module from the script's context.
Package module is fetching the current module from the script's context.
parser
Package parser extract information from go test JSON output.
Package parser extract information from go test JSON output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL