-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
cliphist_test.go
61 lines (54 loc) · 1.59 KB
/
cliphist_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
package main
import (
"crypto/rand"
"fmt"
"image"
"image/gif"
"image/jpeg"
"image/png"
"io"
mathrand "math/rand"
"os"
"strconv"
"testing"
"github.com/rogpeppe/go-internal/testscript"
"golang.org/x/image/bmp"
"golang.org/x/image/tiff"
)
func TestMain(m *testing.M) {
testImage := image.NewRGBA(image.Rectangle{Max: image.Point{20, 20}})
os.Exit(testscript.RunMain(m, map[string]func() int{
"cliphist": func() int { main(); return 0 },
"rand": func() int {
size, _ := strconv.Atoi(os.Args[1])
_, _ = io.CopyN(os.Stdout, rand.Reader, int64(size))
return 0
},
"randstr": func() int {
size, _ := strconv.Atoi(os.Args[1])
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, size)
for i := range b {
b[i] = letterBytes[mathrand.Intn(len(letterBytes))]
}
os.Stdout.Write(b)
return 0
},
"gif": func() int { _ = gif.Encode(os.Stdout, testImage, nil); return 0 },
"jpg": func() int { _ = jpeg.Encode(os.Stdout, testImage, nil); return 0 },
"png": func() int { _ = png.Encode(os.Stdout, testImage); return 0 },
"bmp": func() int { _ = bmp.Encode(os.Stdout, testImage); return 0 },
"tiff": func() int { _ = tiff.Encode(os.Stdout, testImage, nil); return 0 },
}))
}
func TestScripts(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata",
RequireExplicitExec: true,
Setup: func(env *testscript.Env) error {
env.Vars = append(env.Vars, fmt.Sprintf("HOME=%s", env.WorkDir))
env.Vars = append(env.Vars, fmt.Sprintf("XDG_CACHE_HOME=%s", env.WorkDir))
return nil
},
})
}