-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
74 lines (60 loc) · 1.22 KB
/
parser_test.go
File metadata and controls
74 lines (60 loc) · 1.22 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"strings"
"testing"
)
func TestParser(t *testing.T) {
file, err := ParseString(`
ENV= production
task_is-yes: # Comment
echo $ENV`)
if err != nil {
t.Fatal(err)
}
// Vars
val, err := file.GetVar("ENV")
if err != nil {
t.Error("ENV was not defined")
} else if val != "production" {
t.Error("ENV was not production. Was ", val)
}
//Tasks
if len(file.Tasks) != 1 {
t.Fatal("task was not define")
}
task := file.Tasks[0]
if task.Comment != "Comment" {
t.Errorf("Comment was not defined. It was: %q", task.Comment)
}
if strings.Join(task.Script, "\n") != "\techo $ENV" {
t.Errorf("Script was not defined. It was: %q", strings.Join(task.Script, "\n"))
}
}
func TestParser_Dependencies(t *testing.T) {
p, err := ParseString(`
a: # Hola
echo hola
b: a ## Comment
echo b`)
if err != nil {
t.Fatal(err)
}
b := &Task{}
for _, task := range p.Tasks {
if task.Name == "b" {
b = task
}
}
if b == nil {
t.Fatal("Task not found")
}
if len(b.Deps) != 1 {
t.Fatal("Expecting b to have dependencies")
}
if b.Deps[0] != "a" {
t.Error("Expecting b to depend on a. Got", b.Deps)
}
if b.Comment != "Comment" {
t.Fatal("expecting b comment. Got", b.Comment)
}
}