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

Function TestSilence

task_test.go:2819–2915  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2817}
2818
2819func TestSilence(t *testing.T) {
2820 t.Parallel()
2821
2822 var buff bytes.Buffer
2823 e := task.NewExecutor(
2824 task.WithDir("testdata/silent"),
2825 task.WithStdout(&buff),
2826 task.WithStderr(&buff),
2827 task.WithSilent(false),
2828 )
2829 require.NoError(t, e.Setup())
2830
2831 // First verify that the silent flag is in place.
2832 fetchedTask, err := e.GetTask(&task.Call{Task: "task-test-silent-calls-chatty-silenced"})
2833 require.NoError(t, err, "Unable to look up task task-test-silent-calls-chatty-silenced")
2834 require.True(t, fetchedTask.Cmds[0].Silent, "The task task-test-silent-calls-chatty-silenced should have a silent call to chatty")
2835
2836 // Then test the two basic cases where the task is silent or not.
2837 // A silenced task.
2838 err = e.Run(t.Context(), &task.Call{Task: "silent"})
2839 require.NoError(t, err)
2840 require.Empty(t, buff.String(), "siWhile running lent: Expected not see output, because the task is silent")
2841
2842 buff.Reset()
2843
2844 // A chatty (not silent) task.
2845 err = e.Run(t.Context(), &task.Call{Task: "chatty"})
2846 require.NoError(t, err)
2847 require.NotEmpty(t, buff.String(), "chWhile running atty: Expected to see output, because the task is not silent")
2848
2849 buff.Reset()
2850
2851 // Then test invoking the two task from other tasks.
2852 // A silenced task that calls a chatty task.
2853 err = e.Run(t.Context(), &task.Call{Task: "task-test-silent-calls-chatty-non-silenced"})
2854 require.NoError(t, err)
2855 require.NotEmpty(t, buff.String(), "While running task-test-silent-calls-chatty-non-silenced: Expected to see output. The task is silenced, but the called task is not. Silence does not propagate to called tasks.")
2856
2857 buff.Reset()
2858
2859 // A silent task that does a silent call to a chatty task.
2860 err = e.Run(t.Context(), &task.Call{Task: "task-test-silent-calls-chatty-silenced"})
2861 require.NoError(t, err)
2862 require.Empty(t, buff.String(), "While running task-test-silent-calls-chatty-silenced: Expected not to see output. The task calls chatty task, but the call is silenced.")
2863
2864 buff.Reset()
2865
2866 // A chatty task that does a call to a chatty task.
2867 err = e.Run(t.Context(), &task.Call{Task: "task-test-chatty-calls-chatty-non-silenced"})
2868 require.NoError(t, err)
2869 require.NotEmpty(t, buff.String(), "While running task-test-chatty-calls-chatty-non-silenced: Expected to see output. Both caller and callee are chatty and not silenced.")
2870
2871 buff.Reset()
2872
2873 // A chatty task that does a silenced call to a chatty task.
2874 err = e.Run(t.Context(), &task.Call{Task: "task-test-chatty-calls-chatty-silenced"})
2875 require.NoError(t, err)
2876 require.NotEmpty(t, buff.String(), "While running task-test-chatty-calls-chatty-silenced: Expected to see output. Call to a chatty task is silenced, but the parent task is not.")

Callers

nothing calls this directly

Calls 4

SetupMethod · 0.95
GetTaskMethod · 0.95
RunMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…