MCPcopy Create free account
hub / github.com/go-task/task / TestWhenDirAttributeItCreatesMissingAndRunsInThatDir

Function TestWhenDirAttributeItCreatesMissingAndRunsInThatDir

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

Source from the content-addressed store, hash-verified

1846}
1847
1848func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) {
1849 t.Parallel()
1850
1851 const expected = "createme"
1852 const dir = "testdata/dir/explicit_doesnt_exist/"
1853 const toBeCreated = dir + expected
1854 const target = "whereami"
1855 var out bytes.Buffer
1856 e := task.NewExecutor(
1857 task.WithDir(dir),
1858 task.WithStdout(&out),
1859 task.WithStderr(&out),
1860 )
1861
1862 // Ensure that the directory to be created doesn't actually exist.
1863 _ = os.RemoveAll(toBeCreated)
1864 if _, err := os.Stat(toBeCreated); err == nil {
1865 t.Errorf("Directory should not exist: %v", err)
1866 }
1867 require.NoError(t, e.Setup())
1868 require.NoError(t, e.Run(t.Context(), &task.Call{Task: target}))
1869
1870 // Normalize path separators for cross-platform compatibility (Windows uses backslashes)
1871 normalized := normalizePathSeparators(out.String())
1872 got := strings.TrimSuffix(filepath.Base(normalized), "\n")
1873 assert.Equal(t, expected, got, "Mismatch in the working directory")
1874
1875 // Clean-up after ourselves only if no error.
1876 _ = os.RemoveAll(toBeCreated)
1877}
1878
1879func TestDynamicVariablesRunOnTheNewCreatedDir(t *testing.T) {
1880 t.Parallel()

Callers

nothing calls this directly

Calls 4

SetupMethod · 0.95
RunMethod · 0.95
normalizePathSeparatorsFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…