Debian Codegraph @

init_test.go

raw symbols SCIP
1 package godo
2
3 import (
4 "fmt"
5 "io/ioutil"
6 "os"
7 "path/filepath"
8 "strconv"
9 "time"
10 )
11
12 // amount of time to wait before a test project is ready
13 var testProjectDelay = 150 * time.Millisecond
14 var testWatchDelay time.Duration
15
16 func init() {
17 // devnull, err := os.Open(os.DevNull)
18 // if err != nil {
19 // panic(err)
20 // }
21 // util.LogWriter = devnull
22
23 // WatchDelay is the time to poll the file system
24 SetWatchDelay(150 * time.Millisecond)
25 //testWatchDelay = watchDelay + 250*time.Millisecond
26 testWatchDelay = watchDelay*2 + 50
27
28 // Debounce should be less han watch delay
29 Debounce = 100 * time.Millisecond
30 verbose = false
31 }
32
33 // Runs a project returning the error value from the task.
34 func runTask(tasksFn func(*Project), name string) (*Project, error) {
35 proj := NewProject(tasksFn, func(status int) {
36 //fmt.Println("exited with", status)
37 panic("exited with code" + strconv.Itoa(status))
38 }, nil)
39 return proj, proj.Run(name)
40 }
41
42 // Runs tasksFn with command line arguments.
43 func execCLI(tasksFn func(*Project), argv []string, customExitFn func(int)) int {
44 var code int
45 var exitFn func(code int)
46 if customExitFn == nil {
47 exitFn = func(status int) {
48 code = status
49 }
50 } else {
51 exitFn = func(status int) {
52 code = status
53 customExitFn(status)
54 }
55 }
56 godoExit(tasksFn, argv, exitFn)
57 return code
58 }
59
60 func touch(path string, delta time.Duration) {
61 if _, err := os.Stat(path); err == nil {
62 tn := time.Now()
63 tn = tn.Add(delta)
64 err := os.Chtimes(path, tn, tn)
65 if err != nil {
66 fmt.Printf("Err touching %s\n", err.Error())
67 }
68 //fmt.Printf("touched %s %s\n", path, time.Now())
69 return
70 }
71 os.MkdirAll(filepath.Dir(path), 0755)
72 ioutil.WriteFile(path, []byte{}, 0644)
73 }
74
75 func touchTil(filename string, timeout time.Duration, cquit chan bool) {
76 filename, _ = filepath.Abs(filename)
77 forloop:
78 for {
79 select {
80 case <-cquit:
81 break forloop
82 case <-time.After(timeout):
83 touch(filename, 1*time.Minute)
84 }
85 }
86 }
87
88 func sliceContains(slice []string, val string) bool {
89 for _, it := range slice {
90 if it == val {
91 return true
92 }
93 }
94 return false
95 }