test: github.com/tvastar/test/cmd/testmd Files

Command testmd

Command testmd generates test files out of markdown snippets

$ go get github.com/tvastar/test/cmd/testmd

This is useful when writing tutorials in markdown and making sure all the tutorials remain valid as the code underneath changes

If no output file is specified (via -o), a temporary go file is generated and it is immediately run via `go test`. Any additional arguments are passed through to go test.

If a package name is provided and it does not include '_test', it will be assumed to be a runnable go program and "go run" will be used instead of "go test".

The snippets of code must use the markdown code fence with an info string starting with "go" (i.e. go or golang)

Additional fields on the info string can provide the name of the test:

```golang TestSomething
   ..some stuff here..
```

If the name starts with anything but Test, an empty function with no args is produced which conveniently works for Examples

Global variables can be introduced by using the special name of global:

```golang global
var hidden := flag.Bool("hidden", false, "is it hidden?")
```

Snippets can be marked to be ignored:

```golang skip
   ..some stuff here..
```

A single markdown can be used to generate multiple package entries. A snippet can be designated as being limited to a specific package by using the name of the package:

```golang script_one.global
   ..some stuff here..
```

The snippet above will only be included if the package name is script_one. This is useful when describing multiple main package options in one tutorial.

Snippets can indicate import paths via a comment:

```golang
// import fmt
..some stuf here..
```

Usage:

$ testmd -pkg readme_test -o readme_test.go *.md
$ testmd README.md -v

Note: all options must come before the markdown file names.

Any options provided after the markdown file names will be passed through to `go test` (if no output is specified).

Package Files

testmd.go

Package main imports 7 packages (graph). Updated 2019-04-09. Refresh now. Tools for package owners.