-
Notifications
You must be signed in to change notification settings - Fork 39
/
cli_test.go
68 lines (50 loc) · 1.48 KB
/
cli_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"os"
"testing"
"github.com/bradleyjkemp/cupaloy"
)
func setupTest(args []string) (*bytes.Buffer, func()) {
buf := &bytes.Buffer{}
oldStderr := stderr
oldArgs := os.Args
stderr = buf
os.Args = args
return buf, func() {
stderr = oldStderr
os.Args = oldArgs
}
}
var cliTests = map[string][]string{
// Test that help is printed if no files are given
"TranspileNoFilesHelp": {"test", "transpile"},
// Test that help is printed if help flag is set, even if file is given
"TranspileHelpFlag": {"test", "transpile", "-h"},
// Test that help is printed if no files are given
"AstNoFilesHelp": {"test", "ast"},
// Test that help is printed if help flag is set, even if file is given
"AstHelpFlag": {"test", "ast", "-h"},
// Test that help is printed if no files are given
"DebugNoFilesHelp": {"test", "debug"},
// Test that help is printed if help flag is set, even if file is given
"DebugHelpFlag": {"test", "debug", "-h"},
"UnusedNoFilesHelp": {"test", "unused"},
"UnusedHelpFlag": {"test", "unused", "-h"},
// Test that version is printed
"Version": {"test", "version"},
}
func TestCLI(t *testing.T) {
snapshotter := cupaloy.New(cupaloy.SnapshotSubdirectory("tests"))
for testName, args := range cliTests {
t.Run(testName, func(t *testing.T) {
output, teardown := setupTest(args)
defer teardown()
runCommand()
err := snapshotter.SnapshotMulti(testName, output)
if err != nil {
t.Fatalf("error: %s", err)
}
})
}
}