1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

Updated test for file watcher interval param

Updated Interval Setting Priority
This commit is contained in:
ilewin
2022-09-19 20:31:24 +02:00
parent d8dc091267
commit c2f20465ab
3 changed files with 11 additions and 10 deletions

View File

@@ -1503,9 +1503,6 @@ Hello, World!
assert.NoError(t, e.Setup()) assert.NoError(t, e.Setup())
buff.Reset() buff.Reset()
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
err := os.MkdirAll(dir+"/src", 0755) err := os.MkdirAll(dir+"/src", 0755)
assert.NoError(t, err) assert.NoError(t, err)
@@ -1514,6 +1511,9 @@ Hello, World!
t.Fatal(err) t.Fatal(err)
} }
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
go func(ctx context.Context) { go func(ctx context.Context) {
for { for {
select { select {
@@ -1535,9 +1535,10 @@ Hello, World!
} }
time.Sleep(70 * time.Millisecond) time.Sleep(70 * time.Millisecond)
cancel() cancel()
assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String())) assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String()))
buff.Reset() buff.Reset()
err = os.RemoveAll(dir + "/.task") err = os.RemoveAll(dir + "/.task")
assert.NoError(t, err) assert.NoError(t, err)
err = os.RemoveAll(dir + "/src")
assert.NoError(t, err)
} }

View File

@@ -5,7 +5,7 @@ version: '3'
vars: vars:
GREETING: Hello, World! GREETING: Hello, World!
interval: "50ms" interval: "30ms"
tasks: tasks:
default: default:

View File

@@ -39,17 +39,17 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
var watchIntervalString string var watchIntervalString string
if e.Taskfile.Interval != "" { if e.Interval != "" {
watchIntervalString = e.Taskfile.Interval
} else if e.Interval != "" {
watchIntervalString = e.Interval watchIntervalString = e.Interval
} else if e.Taskfile.Interval != "" {
watchIntervalString = e.Taskfile.Interval
} }
watchInterval := defaultWatchInterval watchInterval := defaultWatchInterval
if watchIntervalString != "" { if watchIntervalString != "" {
var err error var err error
watchInterval, err = parsedWatchInterval(watchIntervalString) watchInterval, err = parseWatchInterval(watchIntervalString)
if err != nil { if err != nil {
e.Logger.Errf(logger.Red, "%v", err) e.Logger.Errf(logger.Red, "%v", err)
} }
@@ -185,7 +185,7 @@ func shouldIgnoreFile(path string) bool {
return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules") return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
} }
func parsedWatchInterval(watchInterval string) (time.Duration, error) { func parseWatchInterval(watchInterval string) (time.Duration, error) {
v, err := time.ParseDuration(watchInterval) v, err := time.ParseDuration(watchInterval)
if err != nil { if err != nil {
return 0, fmt.Errorf(`task: Could not parse watch interval "%s": %v`, watchInterval, err) return 0, fmt.Errorf(`task: Could not parse watch interval "%s": %v`, watchInterval, err)