forked from stathissideris/ditaa
-
Notifications
You must be signed in to change notification settings - Fork 5
/
run-testimgs.go
58 lines (51 loc) · 968 Bytes
/
run-testimgs.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
// +build none
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
)
var (
forceAll = flag.Bool("a", false, "run all tests even in case of errors")
)
func main() {
err := run()
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
}
func run() error {
flag.Parse()
const (
sources = "testdata/"
results = "tmp/testimgs"
)
os.MkdirAll(results, 0777)
err := filepath.Walk(sources, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() || filepath.Ext(path) != ".txt" {
return nil
}
return RunDitaa(path, filepath.Join(results, info.Name()+".png"))
})
if err != nil {
return err
}
return nil
}
func RunDitaa(src, dst string) error {
os.Remove(dst)
fmt.Println("\nDITAA", src, "->", dst)
cmd := exec.Command("ditaa", src, dst)
out, err := cmd.CombinedOutput()
os.Stdout.Write(out)
if err != nil && !*forceAll {
return err
}
return nil
}