-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_test.go
105 lines (88 loc) · 2.74 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"github.com/DeNA/unity-meta-check/util/cli"
"github.com/DeNA/unity-meta-check/util/testutil"
"github.com/google/go-cmp/cmp"
"path/filepath"
"testing"
)
func TestValid(t *testing.T) {
main := NewMain()
stdout := testutil.SpyWriteCloser(nil)
stderr := testutil.SpyWriteCloser(nil)
procInout := cli.ProcessInout{
Stdin: nil,
Stdout: stdout,
Stderr: stderr,
}
projectPath := filepath.Join("testdata", "ValidProject")
actualExitStatus := main([]string{"-debug", projectPath}, procInout, cli.AnyEnv())
expectedExitStatus := cli.ExitNormal
if actualExitStatus != expectedExitStatus {
t.Logf("stdout:\n%s", stdout.Captured.String())
t.Logf("stderr:\n%s", stderr.Captured.String())
t.Error(cmp.Diff(expectedExitStatus, actualExitStatus))
return
}
actualStdout := stdout.Captured.String()
expectedStdout := ""
if actualStdout != expectedStdout {
t.Logf("stderr:\n%s", stderr.Captured.String())
t.Error(cmp.Diff(expectedStdout, actualStdout))
return
}
}
func TestInvalid(t *testing.T) {
main := NewMain()
stdout := testutil.SpyWriteCloser(nil)
stderr := testutil.SpyWriteCloser(nil)
procInout := cli.ProcessInout{
Stdin: nil,
Stdout: stdout,
Stderr: stderr,
}
projectPath := filepath.Join("testdata", "InvalidProject")
actualExitStatus := main([]string{"-debug", projectPath}, procInout, cli.AnyEnv())
expectedExitStatus := cli.ExitAbnormal
if actualExitStatus != expectedExitStatus {
t.Logf("stdout:\n%s", stdout.Captured.String())
t.Logf("stderr:\n%s", stderr.Captured.String())
t.Error(cmp.Diff(expectedExitStatus, actualExitStatus))
return
}
actualStdout := stdout.Captured.String()
expectedStdout := `missing Assets/AssetsMissing.meta
missing Assets/Plugins/SpecialFolder.framework.meta
missing Assets/SubDir/SubDirFile.meta
missing LocalPackages/com.example.local.pkg/LocalPkgMissing.meta
missing Packages/com.example.pkg/PkgMissing.meta
dangling Assets/AssetsDangling.meta
dangling Assets/Dangling.meta
dangling Assets/Dangling/Dangling.meta
dangling LocalPackages/com.example.local.pkg/LocalPkgDangling.meta
dangling Packages/com.example.pkg/PkgDangling.meta
`
if actualStdout != expectedStdout {
t.Logf("stderr:\n%s", stderr.Captured.String())
t.Error(cmp.Diff(expectedStdout, actualStdout))
return
}
}
func TestVersion(t *testing.T) {
main := NewMain()
procInout := cli.AnyProcInout()
status := main([]string{"-version"}, procInout, cli.AnyEnv())
if status != cli.ExitNormal {
t.Errorf("want %d, got %d", cli.ExitNormal, status)
return
}
}
func TestHelp(t *testing.T) {
main := NewMain()
procInout := cli.AnyProcInout()
status := main([]string{"-help"}, procInout, cli.AnyEnv())
if status != cli.ExitAbnormal {
t.Errorf("want %d, got %d", cli.ExitNormal, status)
return
}
}