File: examples_helper_test.go

package info (click to toggle)
golang-github-approvals-go-approval-tests 0.0~git20180620.6ae1ec6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 296 kB
  • sloc: xml: 16; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package approvaltests_test

import (
	"fmt"
	"io/ioutil"
	"log"
	"strings"
)

var (
	// this is a mock testing.T for documentation purposes
	t = &failing{}
)

// failing is a mock struct that is only there for documentation conveniance,
// showing the developer how they would be passing a *testing.T pointer in their
// normal tests.
type failing struct{}

// Fail implements approvaltest.Fail
func (f *failing) Fail() {}

// documentation helper just for the example
func printFileContent(path string) {
	approvedPath := strings.Replace(path, ".received.", ".approved.", 1)
	content, err := ioutil.ReadFile(approvedPath)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("This produced the file %s\n", path)
	fmt.Printf("It will be compared against the %s file\n", approvedPath)
	fmt.Println("and contains the text:")
	fmt.Println()
	// sad sad hack because go examples trim blank middle lines
	fmt.Println(strings.Replace(string(content), "\n\n", "\n", -1))
}