MCPcopy
hub / github.com/go-task/task / TestStatusTimestamp

Function TestStatusTimestamp

task_test.go:561–605  ·  view source on GitHub ↗

TestStatusTimestamp is a regression test for https://github.com/go-task/task/issues/1230. When using method: timestamp, deleting a generated file should cause the task to re-run, not be skipped because the timestamp file is still present.

(t *testing.T)

Source from the content-addressed store, hash-verified

559// When using method: timestamp, deleting a generated file should cause the task to re-run,
560// not be skipped because the timestamp file is still present.
561func TestStatusTimestamp(t *testing.T) { // nolint:paralleltest // cannot run in parallel
562 const dir = "testdata/timestamp"
563
564 generatedFile := filepathext.SmartJoin(dir, "generated.txt")
565 tempDir := task.TempDir{
566 Remote: filepathext.SmartJoin(dir, ".task"),
567 Fingerprint: filepathext.SmartJoin(dir, ".task"),
568 }
569
570 // Clean up any state from previous runs.
571 _ = os.Remove(generatedFile)
572 _ = os.RemoveAll(filepathext.SmartJoin(dir, ".task"))
573
574 var buff bytes.Buffer
575 e := task.NewExecutor(
576 task.WithDir(dir),
577 task.WithStdout(&buff),
578 task.WithStderr(&buff),
579 task.WithTempDir(tempDir),
580 )
581 require.NoError(t, e.Setup())
582
583 // First run: task should execute and create generated.txt.
584 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
585 _, err := os.Stat(generatedFile)
586 require.NoError(t, err, "generated.txt should exist after first run")
587 buff.Reset()
588
589 // Second run: task should be up to date.
590 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
591 assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
592 buff.Reset()
593
594 // Delete the generated file (simulate a clean), but leave the timestamp file.
595 require.NoError(t, os.Remove(generatedFile))
596 _, err = os.Stat(generatedFile)
597 require.Error(t, err, "generated.txt should be gone")
598
599 // Third run: task MUST re-run because generated.txt is missing.
600 // This is the regression: previously the task was incorrectly skipped.
601 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
602 assert.NotContains(t, buff.String(), "is up to date", "task should re-run when generated file is missing")
603 _, err = os.Stat(generatedFile)
604 require.NoError(t, err, "generated.txt should be recreated after third run")
605}
606
607// TestStatusChecksumMissingGenerated is a regression test for https://github.com/go-task/task/issues/1230.
608// When using method: checksum, deleting a generated file should cause the task to re-run,

Callers

nothing calls this directly

Calls 5

SetupMethod · 0.95
RunMethod · 0.95
SmartJoinFunction · 0.92
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…