gotest-ls

command module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: MIT Imports: 8 Imported by: 0

README

Go List Tests

master Go Reference codecov

gotest-ls is a tool to list tests in a Go project. It provides list of all the Tests (Test*, Benchmark*, Example*) in a Go project or a go file.

The tool provides output in JSON format. The output can be used to generate a report or for other tools for analysis.

Requirements

  • Go 1.18 or above

Installation

go install github.com/ninadingole/gotest-ls

Usage

gotest-ls [flags] [directories]

gotest-ls .
gotest-ls -p ./cmd
gotest-ls -p ./cmd ./pkg
gotest-ls -f ./pkg/random_test.go
gotest-ls -p -f ./pkg/random_test.go

Flags

  -h, --help                help for gotest-ls
  -f, --file    string      file to list tests from
  -p, --pretty  bool        pretty print the json output

Output

$> gotest-ls -p .                        
[
        {
                "name": "BenchmarkSomething",
                "fileName": "sample_test.go",
                "relativePath": "tests/sample_test.go",
                "absolutePath": "www/gotest-ls/tests/sample_test.go",
                "line": 14,
                "pos": 156
        },
        {
                "name": "Example_errorIfFileAndDirectoryBothAreProvided",
                "fileName": "main_test.go",
                "relativePath": "main_test.go",
                "absolutePath": "www/gotest-ls/main_test.go",
                "line": 37,
                "pos": 1090
        },
        {
                "name": "Example_errorIfFileProvidedIsDirectory",
                "fileName": "main_test.go",
                "relativePath": "main_test.go",
                "absolutePath": "www/gotest-ls/main_test.go",
                "line": 49,
                "pos": 1419
        },
        {
                "name": "Example_something",
                "fileName": "sample_test.go",
                "relativePath": "tests/sample_test.go",
                "absolutePath": "www/gotest-ls/tests/sample_test.go",
                "line": 20,
                "pos": 250
        },
        {
                "name": "TestListAllTestsForGivenFile",
                "fileName": "main_test.go",
                "relativePath": "main_test.go",
                "absolutePath": "www/gotest-ls/main_test.go",
                "line": 14,
                "pos": 126
        },
        {
                "name": "TestSomething",
                "fileName": "sample_test.go",
                "relativePath": "tests/sample_test.go",
                "absolutePath": "www/gotest-ls/tests/sample_test.go",
                "line": 8,
                "pos": 56
        }
]

Documentation

Overview

gotest-ls provides a list of all tests in a package or a file in JSON format.

Usage:

gotest-ls [flags] [directories...]

Examples:

gotest-ls .
gotest-ls -p ./cmd
gotest-ls -p ./cmd ./pkg
gotest-ls -f ./pkg/random_test.go
gotest-ls -p -f ./pkg/random_test.go

Flags:

-f, --file string   Path to a file, cannot be used with directories
-h, --help          help for gotest-ls
-p, --pretty        Pretty print the output in JSON format

Directories

Path Synopsis
Package pkg contains the core logic of the gotest-ls tool which finds all the go test files.
Package pkg contains the core logic of the gotest-ls tool which finds all the go test files.

Jump to

Keyboard shortcuts

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