Skip to content

Eun/go-testdoc

Repository files navigation

go-testdoc Actions Status Coverage Status PkgGoDev GoDoc go-report

go-testdoc runs your code documentation examples during normal test time.

go get -u github.com/Eun/go-testdoc

Example

This example will run the go code inside the Example and Examples section using yaegi.

// example.go file
package example

// IsLoggedIn returns true if the current user has access to the service.
//
// Example:
//     if IsLoggedIn() {
//         fmt.Println("You are logged in")
//     }
func IsLoggedIn() bool {
	return true
}

// CurrentUser returns the current username of the logged in user.
//
// Examples:
//     fmt.Println(CurrentUser())
//
//     if IsLoggedIn() {
//         fmt.Println(CurrentUser())
//     }
func CurrentUser() string {
	return "Joe Doe"
}
// example_test.go file
package example_test

import (
	"testing"

	"github.com/Eun/go-testdoc"
)

func TestDocumentation(t *testing.T) {
	testdoc.TestCodeDocumentation(t, &testdoc.Options{
		// Test for this folder
		Path: ".",

		// Test the `example` package
		PkgName: "example",

		// Execute code inside the `Example` and `Examples` sections
		Sections: []string{"Example", "Examples"},

		Imports: []testdoc.Import{
			// Import some standard packages we need
			{Name: "", Path: "fmt"},

			// Import the current package so we can call the functions.
			{Name: ".", Path: "./"},
		},
	})
}

See also

Testing your README.md file

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages