Categorygithub.com/Eun/go-testdoc
modulepackage
0.0.1
Repository: https://github.com/eun/go-testdoc.git
Documentation: pkg.go.dev

# README

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

# Packages

example.go file.
No description provided by the author

# Functions

ParseDoc parses an documentation block and returns an instance to Doc.
TestCodeDocumentation can be used to test documentation for functions, structs, interfaces...

# Structs

Doc represents an documentation block.
Options options for TestCodeDocumentation.

# Type aliases

Import represents an import that should be evaluated.