Convert Figma logo to code with AI

mfridman logotparse

CLI tool for summarizing go test output. Pipe friendly. CI/CD friendly.

1,036
23
1,036
22

Top Related Projects

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.

1,350

go test with colors

8,416

A Modern Testing Framework for Go

6,214

A mock code autogenerator for Go

Quick Overview

mfridman/tparse is a command-line tool designed to parse and summarize Go test output. It enhances the readability of test results by providing a clear, concise summary of test execution, including pass/fail status, execution time, and coverage information. This tool is particularly useful for large Go projects with numerous tests.

Pros

  • Improves test result readability with a clean, organized summary
  • Highlights slow tests and provides package-level statistics
  • Supports various output formats, including JSON and custom templates
  • Integrates well with CI/CD pipelines for automated test result processing

Cons

  • Limited to Go test output, not applicable for other programming languages
  • Requires additional setup and integration into existing workflows
  • May add complexity to simple projects with few tests
  • Dependent on the format of Go's test output, which could change in future Go versions

Getting Started

To use tparse, follow these steps:

  1. Install tparse:

    go install github.com/mfridman/tparse@latest
    
  2. Run your Go tests and pipe the output to tparse:

    go test ./... -json | tparse
    
  3. For more options and customization, refer to the tparse documentation:

    tparse -h
    

This will display a summary of your test results, including pass/fail status, execution time, and coverage information.

Competitor Comparisons

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.

Pros of gotestsum

  • More comprehensive test output formatting options
  • Supports JUnit XML output for CI integration
  • Offers real-time test progress reporting

Cons of gotestsum

  • Larger codebase, potentially more complex to contribute to
  • May have a steeper learning curve for basic usage

Code Comparison

tparse:

cmd := exec.Command("go", "test", "-json", "./...")
cmd.Stderr = os.Stderr
out, err := cmd.StdoutPipe()

gotestsum:

cmd := gotestsum.NewCmd(gotestsum.DefaultConfig())
cmd.Args = append(cmd.Args, "go", "test", "./...")
out, err := cmd.StdoutPipe()

Both tools execute Go tests and capture the output, but gotestsum provides a more abstracted interface with additional configuration options.

Summary

gotestsum offers more features and flexibility in test output formatting, making it suitable for complex testing scenarios and CI/CD pipelines. However, tparse may be simpler to use for basic test result parsing. The choice between the two depends on the specific needs of the project and the desired level of test output customization.

1,350

go test with colors

Pros of gotest

  • Provides colorized output for better readability
  • Supports running specific tests or packages
  • Offers a watch mode for continuous testing during development

Cons of gotest

  • Less detailed parsing of test output compared to tparse
  • Doesn't provide summary statistics or performance metrics
  • Limited customization options for output format

Code Comparison

tparse:

cmd := exec.Command("go", "test", "-json", "./...")
out, err := cmd.Output()
report, err := tparse.Parse(bytes.NewReader(out))

gotest:

cmd := exec.Command("go", "test", "./...")
cmd.Stdout = colorable.NewColorableStdout()
cmd.Stderr = colorable.NewColorableStderr()
cmd.Run()

tparse focuses on parsing and analyzing test output, providing detailed reports and statistics. It's particularly useful for CI/CD pipelines and performance analysis. gotest, on the other hand, emphasizes improving the test running experience with colorized output and convenient features like watch mode. While tparse offers more in-depth analysis, gotest provides a more user-friendly interface for day-to-day testing tasks.

8,416

A Modern Testing Framework for Go

Pros of Ginkgo

  • Comprehensive testing framework with rich features for behavior-driven development (BDD)
  • Supports parallel test execution, improving performance for large test suites
  • Provides a DSL for writing expressive and readable tests

Cons of Ginkgo

  • Steeper learning curve due to its extensive feature set
  • Requires additional setup and configuration compared to standard Go testing
  • May be overkill for simple projects or small test suites

Code Comparison

Ginkgo test example:

var _ = Describe("Calculator", func() {
    It("should add two numbers", func() {
        result := Add(2, 3)
        Expect(result).To(Equal(5))
    })
})

tparse usage example:

func TestAdd(t *testing.T) {
    result := Add(2, 3)
    if result != 5 {
        t.Errorf("Expected 5, got %d", result)
    }
}

Key Differences

  • Ginkgo is a full-featured BDD testing framework, while tparse is a tool for parsing and summarizing Go test output
  • Ginkgo provides a DSL for writing tests, whereas tparse works with standard Go tests
  • tparse focuses on improving test result visualization and analysis, while Ginkgo aims to enhance the test writing and execution process
6,214

A mock code autogenerator for Go

Pros of mockery

  • Generates mock implementations for interfaces, simplifying unit testing
  • Supports custom templates for mock generation
  • Integrates well with popular testing frameworks like testify

Cons of mockery

  • Focuses solely on mock generation, lacking test result parsing capabilities
  • Requires additional setup and configuration compared to tparse
  • May introduce complexity in test suites for simpler projects

Code Comparison

mockery:

//go:generate mockery --name=Database
type Database interface {
    Get(id string) (string, error)
    Set(id string, value string) error
}

tparse:

package main

import (
    "os"
    "github.com/mfridman/tparse/parse"
)

func main() {
    parse.Run(os.Stdout, os.Stderr)
}

Summary

mockery is a powerful tool for generating mock implementations, making it easier to write unit tests for Go interfaces. It offers flexibility through custom templates and integrates well with popular testing frameworks. However, it focuses solely on mock generation and may introduce unnecessary complexity for simpler projects.

tparse, on the other hand, is a lightweight tool for parsing and summarizing Go test output. It provides a quick and easy way to analyze test results without the need for additional setup or configuration. While it doesn't offer mock generation capabilities, it excels in presenting test results in a clear and concise manner.

The choice between these tools depends on the specific needs of your project. If you require extensive mocking capabilities for complex interfaces, mockery may be the better choice. For projects that prioritize simple test result analysis, tparse offers a more straightforward solution.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

tparse Actions

A command line tool for analyzing and summarizing go test output.

[!TIP]

Don't forget to run go test with the -json flag.

PassFail

By default, tparse will always return test failures and panics, if any, followed by a package-level summary table.

To get additional info on passed tests run tparse with -pass flag. Tests are grouped by package and sorted by elapsed time in descending order (longest to shortest).

But why?! for more info.

Installation

go install github.com/mfridman/tparse@latest

Or download the latest pre-built binary here.

Usage

Once tparse is installed there are 2 ways to use it:

  1. Run go test as normal, but add -json flag and pipe output to tparse.
set -o pipefail && go test fmt -json | tparse -all
  1. Save the output of go test with -json flag into a file and call tparse with -file option.
go test fmt -json > fmt.out
tparse -all -file=fmt.out

Tip: run tparse -h to get usage and options.

But why?!

go test is awesome, but verbose. Sometimes you just want readily available failures, grouped by package, printed with a dash of color.

tparse attempts to do just that; return failed tests and panics, if any, followed by a single package-level summary. No more searching for the literal string: "--- FAIL".

But, let's take it a bit further. With -all (-pass and -skip combined) you can get additional info, such as skipped tests and elapsed time of each passed test.

tparse comes with a -follow flag to print raw output. Yep, go test pipes JSON, it's parsed and the output is printed back out as if you ran go test without -json flag. Eliminating the need for tee /dev/tty between pipes.

The default print order is:

  • go test output (if adding -follow flag)
  • passed/skipped table (if adding -all, -skip or -pass flag)
  • failed tests and panics
  • summary

For narrow displays the -smallscreen flag may be useful, dividing a long test name and making it vertical heavy:

TestSubtests/an_awesome_but_long/subtest_for_the/win

TestSubtests
 /an_awesome_but_long
 /subtest_for_the
 /win

tparse aims to be a simple alternative to one-liner bash functions.