Repository navigation
Expand file tree
/
Copy pathapp_test.go
More file actions
56 lines (49 loc) · 1.58 KB
/
Copy pathapp_test.go
File metadata and controls
56 lines (49 loc) · 1.58 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
package main
import (
"os/exec"
"strings"
"testing"
)
// runGitIn runs git with args inside dir, failing the test on error.
func runGitIn(t *testing.T, dir string, args ...string) string {
t.Helper()
cmd := exec.Command("git", args...)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("git %s failed: %v\n%s", strings.Join(args, " "), err, out)
}
return strings.TrimSpace(string(out))
}
// initRepo creates a fresh git repo in a temp dir with a usable identity for
// commits. Returns the repo dir.
func initRepo(t *testing.T) string {
t.Helper()
dir := t.TempDir()
runGitIn(t, dir, "init", "-q")
runGitIn(t, dir, "config", "user.email", "test@example.com")
runGitIn(t, dir, "config", "user.name", "Test User")
return dir
}
func TestExplain_NoSelection(t *testing.T) {
initRepo(t)
app := &App{}
_, err := app.Explain("", []string{}, false)
if err == nil {
t.Fatal("Explain: expected error when no files are selected, got nil")
}
if !strings.Contains(err.Error(), "nothing to explain: no files are selected") {
t.Errorf("Explain error = %q, want it to mention %q", err.Error(), "nothing to explain: no files are selected")
}
}
func TestRunCheck_NoSelection(t *testing.T) {
initRepo(t)
app := &App{}
_, err := app.RunCheck("", "language-consistency", []string{})
if err == nil {
t.Fatal("RunCheck: expected error when no files are selected, got nil")
}
if !strings.Contains(err.Error(), "nothing to check: no files are selected") {
t.Errorf("RunCheck error = %q, want it to mention %q", err.Error(), "nothing to check: no files are selected")
}
}