Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the main Run functions into the cmd package #151

Merged
merged 3 commits into from
Oct 10, 2020

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Oct 10, 2020

This allows someone to run gotestsum as a library, by passing in a command line.

For example, a project could add a file test/main.go with contents:

package main

import (
	"fmt"
	"os"

	"gotest.tools/gotestsum/cmd"
)

func main() {
	name, args := os.Args[0], os.Args[1:]
	args = append([]string{"-f=testname", "--"}, args...)
	if err := cmd.Run(name, args); err != nil {
		fmt.Fprintln(os.Stderr, "ERROR ", err.Error())
		os.Exit(1)
	}
}

And run their tests with go run ./test/, which would run gotestsum without having to install the binary.

Ref: golang/go#41878

There are just enough changes in the diff that git doesn't the change as a
moved file. This commnit moves main.go first, so that the rest of the
commits are easier to read.
So that it can be run as a library.
@dnephin dnephin merged commit e3cd29c into gotestyourself:master Oct 10, 2020
@dnephin dnephin deleted the move-run branch October 10, 2020 21:20
@dnephin dnephin mentioned this pull request Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant