generated from errata-ai/Hugo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
46 lines (36 loc) · 922 Bytes
/
main_test.go
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
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"github.com/google/go-cmdtest"
)
var update = flag.Bool("update", false, "replace test file contents with output")
func Test(t *testing.T) {
ts, err := cmdtest.Read("testdata")
if err != nil {
t.Fatal(err)
}
ts.Setup = func(_ string) error {
_, testFileName, _, ok := runtime.Caller(0)
if !ok {
return fmt.Errorf("failed get real working directory from caller")
}
projectRootDir := filepath.Join(filepath.Dir(testFileName), "testdata")
if err := os.Setenv("ROOTDIR", projectRootDir); err != nil {
return fmt.Errorf("failed change 'ROOTDIR' to caller working directory: %v", err)
}
return nil
}
path, err := exec.LookPath("vale")
if err != nil {
t.Fatal(err)
}
ts.Commands["vale"] = cmdtest.Program(path)
ts.Commands["cdf"] = cmdtest.InProcessProgram("cdf", cdf)
ts.Run(t, *update)
}