discover

package module
v0.0.0-...-362d51a Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 7 Imported by: 0

README

discover

Discover is a utility to aid in conceptualizing large Go code bases. It is based on the idea presented by Alan Shreve in his talk on conceptualizing large software systems, held at dotGo 2015 in Paris. Watch the video for more information.

It does this by taking a code coverage profile generated by "go test" and using it to trim the source code down to the blocks that were actually being run.

Installation

Simply run go get github.com/eandre/discover/...

Examples

Run tests and output to console

discover test

Run a single test and output to console

discover test TestMyTestName

Run all tests starting with "TestFoo"

discover test TestFoo

Run all tests and write the output to ./foo

discover -output=./foo test

Parse an existing cover profile and write the output to ./foo

discover -output=./foo parse my-cover-profile.cov

Tips

If you want to track changes between two tests, write the output to a directory, and then use git to track the changes:

# Run first test
discover -output=/tmp/example test TestFirst
cd /tmp/example
git init && git add -A && git commit -m "First"
cd -

# Run second test
discover -output=/tmp/example test TestSecond
cd /tmp/example
git diff

Documentation

Overview

Package discover implements trimming of ASTs based on test coverage, to aid in conceptualizing large code bases.

It is based on the idea presented by Alan Shreve in his talk on conceptualizing large software systems, held at dotGo 2015 in Paris.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Profile

type Profile struct {
	Stmts       map[ast.Stmt]bool
	Funcs       map[*ast.FuncDecl]bool
	ImportPaths map[*ast.File]string
	Files       []*ast.File
	Fset        *token.FileSet
}

Profile contains a map of statements and funcs that were covered by the cover profiles. It supports using the information to trim an AST down to the nodes that were actually reached.

func ParseProfile

func ParseProfile(profs []*cover.Profile) (*Profile, error)

ParseProfile parses a set of coverage profiles to produce a *Profile.

func (*Profile) Trim

func (p *Profile) Trim(node ast.Node)

Trim trims the AST rooted at node based on the coverage profile, removing irrelevant and unreached parts of the program. If the node is an *ast.File, comments are updated as well using an ast.CommentMap.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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