-
Notifications
You must be signed in to change notification settings - Fork 158
/
cli_test.go
53 lines (41 loc) · 1.07 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
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", "foo.c"},
// 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", "foo.c"},
}
func TestCLI(t *testing.T) {
for testName, args := range cliTests {
t.Run(testName, func(t *testing.T) {
output, teardown := setupTest(args)
defer teardown()
runCommand()
err := cupaloy.SnapshotMulti(testName, output)
if err != nil {
t.Fatalf("error: %s", err)
}
})
}
}