(t *testing.T)
| 1846 | } |
| 1847 | |
| 1848 | func 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 | |
| 1879 | func TestDynamicVariablesRunOnTheNewCreatedDir(t *testing.T) { |
| 1880 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…