Sovereign 8s.is mirror of standardgalactic/test
  • Go 95.7%
  • Shell 4.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
rameshvk 84aa581ec8
Merge pull request #18 from tvastar/wip
update json marshal to disable html escaping
2019-09-22 18:09:24 -07:00
cmd/testmd Add support for processing multiple markdown files 2019-04-08 14:21:09 -07:00
testdata Add test to verify non-go info strings are ignored 2019-03-30 16:15:48 -07:00
x Add Artifact support 2019-09-22 16:17:37 -07:00
.gitignore Initial commit 2019-03-23 14:47:37 -07:00
.travis.yml Fix travis build 2019-09-22 16:25:38 -07:00
artifact.go update json marshal to disable html escaping 2019-09-22 18:02:53 -07:00
artifact_test.go Add Artifact support 2019-09-22 16:17:37 -07:00
CODE_OF_CONDUCT.md Initial change 2019-03-23 17:37:53 -07:00
CONTRIBUTING.md Initial change 2019-03-23 17:37:53 -07:00
file.go Add Artifact support 2019-09-22 16:17:37 -07:00
file_test.go Add Artifact support 2019-09-22 16:17:37 -07:00
go.mod Add Artifact support 2019-09-22 16:17:37 -07:00
go.sum Add Artifact support 2019-09-22 16:17:37 -07:00
LICENSE Initial commit 2019-03-23 14:47:37 -07:00
markdown.go Use go modules and switch to google-cmp 2019-09-22 13:27:08 -07:00
markdown_test.go Add support for processing multiple markdown files 2019-04-08 14:21:09 -07:00
README.md Add Artifact support 2019-09-22 16:17:37 -07:00

Test

Status GoDoc codecov Go Report Card

Test is a simple golang test utils package.

test.Artifact

test.Artifact allows a simple way to test artifacts against recorded golden files.

The golden files are stored in testdata/ folder of the caller of the API and are expected to contain the JSON version of the value being tested. The go-cmp package is used for better quality diffs.

test.File

This is deprecated in favor of test.Artifact.

test.Markdown

Markdown() converts a set of code snippets in markdown into test cases. For example:

```go
if len("hello") != 5 {
	fmt.Println("This should not happen")
}

// Output:
```

The above snippet is converted to an ExampleXXX() which runs the code.

Snippets can also be named, with ability to import code from elsewhere:

```go  TestBoo
// import runtime
_, fname, _, _ := runtime.Caller(1)
if fname == "" {
	t.Error("Could not find caller info")
}
```

The name of the snippet must be TestXYZ or ExampleXYZ or just a plain function (presumably for use in other snippets). Two sepcial cases are "skip" to indicate the fence block should not be considered testable and "global" to indicate the fence block is a global variable:

```go skip
   // this has sample code that is not expected to compile
   booya
```
```go global
func stranger() string {
	return "stranger"
}
```
```go Example_UsingSomethingDefinedInGlobal
fmt.Println("ok", stranger())

// Output: ok stranger
```

If the info name has a dot in it, the word before the dot is compared to the package name. If they don't match the fence block is skipped. This allows a single markdown to have multiple fence blocks destined for different packages:

```go firstPackage.DoSomething
...
```

```go secondPackage.
...
```