mirror of
https://github.com/go-task/task.git
synced 2025-02-03 13:22:11 +02:00
Write tests for variables
This commit is contained in:
parent
edd338097e
commit
e28b0bc646
41
task_test.go
41
task_test.go
@ -1,9 +1,11 @@
|
||||
package task_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -43,3 +45,42 @@ func TestDeps(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVars(t *testing.T) {
|
||||
const dir = "testdata/vars"
|
||||
|
||||
files := []struct {
|
||||
file string
|
||||
content string
|
||||
}{
|
||||
{"foo.txt", "foo"},
|
||||
{"bar.txt", "bar"},
|
||||
{"foo2.txt", "foo2"},
|
||||
{"bar2.txt", "bar2"},
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
_ = os.Remove(filepath.Join(dir, f.file))
|
||||
}
|
||||
|
||||
c := exec.Command("task")
|
||||
c.Dir = dir
|
||||
|
||||
if err := c.Run(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
d, err := ioutil.ReadFile(filepath.Join(dir, f.file))
|
||||
if err != nil {
|
||||
t.Errorf("Error reading %s: %v", f.file, err)
|
||||
}
|
||||
s := string(d)
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
if s != f.content {
|
||||
t.Errorf("File content should be %s but is %s", f.content, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
testdata/vars/.gitignore
vendored
Normal file
1
testdata/vars/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.txt
|
12
testdata/vars/Taskfile.yml
vendored
Normal file
12
testdata/vars/Taskfile.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
default:
|
||||
deps: [hello]
|
||||
|
||||
hello:
|
||||
cmds:
|
||||
- echo {{.FOO}} > foo.txt
|
||||
- echo {{.BAR}} > bar.txt
|
||||
- echo {{.FOO2}} > foo2.txt
|
||||
- echo {{.BAR2}} > bar2.txt
|
||||
vars:
|
||||
FOO: foo
|
||||
BAR: $echo bar
|
2
testdata/vars/Taskvars.yml
vendored
Normal file
2
testdata/vars/Taskvars.yml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
FOO2: foo2
|
||||
BAR2: $echo bar2
|
Loading…
x
Reference in New Issue
Block a user