-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexec_test.go
More file actions
72 lines (64 loc) · 1.79 KB
/
exec_test.go
File metadata and controls
72 lines (64 loc) · 1.79 KB
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
package exec
import (
"errors"
"testing"
"github.com/digineo/texd/tex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type mockDocument struct {
wd string
wdErr error
main string
mainErr error
}
var _ Document = (*mockDocument)(nil)
// methods of tex.Document needed for this test.
func (m *mockDocument) WorkingDirectory() (string, error) { return m.wd, m.wdErr }
func (m *mockDocument) MainInput() (string, error) { return m.main, m.mainErr }
func (*mockDocument) Engine() tex.Engine { return tex.DefaultEngine }
// methods required to satisfy the Document interface.
func (*mockDocument) Image() string { return "" }
func TestBaseExec_extract(t *testing.T) {
dirErr := errors.New("dir error")
mainErr := errors.New("main error")
for _, tc := range []struct {
expectedDir string
expectedError string
mockDocument
}{
{
expectedDir: "",
mockDocument: mockDocument{"", nil, "", nil},
}, {
expectedDir: "/",
mockDocument: mockDocument{"/", nil, "", nil},
}, {
expectedDir: "",
mockDocument: mockDocument{"", nil, "/", nil},
}, {
expectedDir: "a",
mockDocument: mockDocument{"a", nil, "b", nil},
}, {
expectedDir: "/a",
mockDocument: mockDocument{"/a", nil, "b", nil},
}, {
expectedError: "dir error",
mockDocument: mockDocument{"", dirErr, "b", nil},
}, {
expectedError: "main error",
mockDocument: mockDocument{"", dirErr, "b", mainErr},
},
} {
subject := baseExec{&tc.mockDocument}
dir, cmd, err := subject.extract()
if tc.expectedError == "" {
require.NoError(t, err)
assert.Equal(t, tc.expectedDir, dir)
assert.Equal(t, "latexmk", cmd[0])
assert.Equal(t, tc.main, cmd[len(cmd)-1])
} else {
require.EqualError(t, err, tc.expectedError)
}
}
}