github.com/ninadingole/gotest-ls@v0.0.3/README.md (about)

     1  
     2  ## Go List Tests
     3  ![master](https://github.com/ninadingole/gotest-ls/actions/workflows/base.yml/badge.svg?branch=main)
     4  [![Go Reference](https://pkg.go.dev/badge/github.com/ninadingole/gotest-ls.svg)](https://pkg.go.dev/github.com/ninadingole/gotest-ls)
     5  [![codecov](https://codecov.io/gh/ninadingole/gotest-ls/branch/main/graph/badge.svg?token=9ZYKWNF6JI)](https://codecov.io/gh/ninadingole/gotest-ls)
     6  
     7  `gotest-ls` is a tool to list tests in a Go project. It provides list of all the Tests
     8  (`Test*`, `Benchmark*`, `Example*`) in a Go project or a go file.
     9  
    10  The tool provides output in JSON format. The output can be used to generate a report or for other tools for analysis.
    11  
    12  ### Requirements
    13  - `Go 1.18` or above
    14  
    15  ### Installation
    16  
    17  ```bash
    18  go install github.com/ninadingole/gotest-ls
    19  ```
    20  
    21  ### Usage
    22  
    23  ```bash
    24  gotest-ls [flags] [directories]
    25  
    26  gotest-ls .
    27  gotest-ls -p ./cmd
    28  gotest-ls -p ./cmd ./pkg
    29  gotest-ls -f ./pkg/random_test.go
    30  gotest-ls -p -f ./pkg/random_test.go
    31  
    32  ```
    33  
    34  ### Flags
    35  
    36  ```bash
    37    -h, --help                help for gotest-ls
    38    -f, --file    string      file to list tests from
    39    -p, --pretty  bool        pretty print the json output
    40  ```
    41  
    42  ### Output
    43  
    44  ```bash
    45  $> gotest-ls -p .                        
    46  [
    47          {
    48                  "name": "BenchmarkSomething",
    49                  "fileName": "sample_test.go",
    50                  "relativePath": "tests/sample_test.go",
    51                  "absolutePath": "www/gotest-ls/tests/sample_test.go",
    52                  "line": 14,
    53                  "pos": 156
    54          },
    55          {
    56                  "name": "Example_errorIfFileAndDirectoryBothAreProvided",
    57                  "fileName": "main_test.go",
    58                  "relativePath": "main_test.go",
    59                  "absolutePath": "www/gotest-ls/main_test.go",
    60                  "line": 37,
    61                  "pos": 1090
    62          },
    63          {
    64                  "name": "Example_errorIfFileProvidedIsDirectory",
    65                  "fileName": "main_test.go",
    66                  "relativePath": "main_test.go",
    67                  "absolutePath": "www/gotest-ls/main_test.go",
    68                  "line": 49,
    69                  "pos": 1419
    70          },
    71          {
    72                  "name": "Example_something",
    73                  "fileName": "sample_test.go",
    74                  "relativePath": "tests/sample_test.go",
    75                  "absolutePath": "www/gotest-ls/tests/sample_test.go",
    76                  "line": 20,
    77                  "pos": 250
    78          },
    79          {
    80                  "name": "TestListAllTestsForGivenFile",
    81                  "fileName": "main_test.go",
    82                  "relativePath": "main_test.go",
    83                  "absolutePath": "www/gotest-ls/main_test.go",
    84                  "line": 14,
    85                  "pos": 126
    86          },
    87          {
    88                  "name": "TestSomething",
    89                  "fileName": "sample_test.go",
    90                  "relativePath": "tests/sample_test.go",
    91                  "absolutePath": "www/gotest-ls/tests/sample_test.go",
    92                  "line": 8,
    93                  "pos": 56
    94          }
    95  ]
    96  
    97  ```