-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
81 lines (70 loc) · 1.94 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
package main_test
import (
"io/ioutil"
"os/exec"
"path/filepath"
"regexp"
"testing"
)
func TestVgsassc(t *testing.T) {
tmpDir := t.TempDir()
vgsasscExe := filepath.Join(tmpDir, "vgsassc")
b, err := exec.Command("go", "build", "-o", vgsasscExe, ".").CombinedOutput()
if err != nil {
t.Logf("go build output:\n%s", b)
t.Fatal(err)
}
t.Run("001-simple", func(t *testing.T) {
outPath := filepath.Join(tmpDir, "001-out.css")
mustRun(t, exec.Command(vgsasscExe, "-o", outPath, "testdata/001-simple.scss"))
bstr := string(mustRead(t, outPath))
restrmatch(t, "some comment here", bstr)
//t.Logf("out: %s", b)
})
t.Run("001a-simple-min", func(t *testing.T) {
outPath := filepath.Join(tmpDir, "001-out.min.css")
mustRun(t, exec.Command(vgsasscExe, "-m", "-o", outPath, "testdata/001-simple.scss"))
bstr := string(mustRead(t, outPath))
restrmatch(t, `^\.test1\{color:green\}\.test1 \.test2\{color:red\}\s*$`, bstr)
})
t.Run("002-use", func(t *testing.T) {
outPath := filepath.Join(tmpDir, "002-out.min.css")
mustRun(t, exec.Command(vgsasscExe, "-m", "-o", outPath, "-I", "testdata", "testdata/002-use.scss"))
bstr := string(mustRead(t, outPath))
restrmatch(t, `^\.include-a\{color:purple\}`, bstr)
})
}
func restrmatch(t *testing.T, re string, shouldMatch string) {
t.Helper()
r, err := regexp.Compile(re)
if err != nil {
t.Fatal(err)
}
if !r.MatchString(shouldMatch) {
t.Errorf("regexp match failure for: %s\nshould have matched: %s", re, shouldMatch)
}
}
func mustRead(t *testing.T, p string) []byte {
t.Helper()
b, err := ioutil.ReadFile(p)
if err != nil {
t.Fatalf("error while reading %q: %v", p, err)
}
return b
}
func mustRun(t *testing.T, cmd *exec.Cmd) {
t.Helper()
b, err := cmd.CombinedOutput()
if err != nil {
t.Logf("output:\n%s", b)
t.Fatal(err)
}
}
func mustRunShow(t *testing.T, cmd *exec.Cmd) {
t.Helper()
b, err := cmd.CombinedOutput()
t.Logf("output:\n%s", b)
if err != nil {
t.Fatal(err)
}
}