From d58599dddfc68510bd8295d80af8f5a5b944a4b8 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Sat, 9 Dec 2023 17:44:57 -0600 Subject: [PATCH] testTmp --- .../golden/wrap/bindown-path/runnable | 2 +- cmd/bindown/testutil_test.go | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/bindown/testdata/golden/wrap/bindown-path/runnable b/cmd/bindown/testdata/golden/wrap/bindown-path/runnable index 1fbacc4..f34a546 100644 --- a/cmd/bindown/testdata/golden/wrap/bindown-path/runnable +++ b/cmd/bindown/testdata/golden/wrap/bindown-path/runnable @@ -6,7 +6,7 @@ set -e bindown_bin="$( CDPATH="" cd -- "$(dirname -- "$0")" - "../../../../../../../../../Users/wroden/repos/WillAbides/bindown/tmp/_test/bindown" install "runnable" \ + "../../bindown" install "runnable" \ --to-cache \ --configfile "../.bindown.yaml" \ --cache "../cache" diff --git a/cmd/bindown/testutil_test.go b/cmd/bindown/testutil_test.go index 7b0fadc..4a073fe 100644 --- a/cmd/bindown/testutil_test.go +++ b/cmd/bindown/testutil_test.go @@ -38,7 +38,7 @@ type cmdRunner struct { func newCmdRunner(t testing.TB) *cmdRunner { t.Helper() - dir := t.TempDir() + dir := testTmp(t) cacheDir := filepath.Join(dir, "cache") configfile := filepath.Join(dir, ".bindown.yaml") runner := &cmdRunner{ @@ -243,6 +243,24 @@ func testInDir(t testing.TB, dir string) { assert.NoError(t, os.Chdir(dir)) } +// testTmp is like t.TempDir but it uses a directory in this repo's tmp directory. +// This is useful so that there can be a relative path from the resulting directory to +// directories in this repo. +func testTmp(t testing.TB) string { + t.Helper() + tmpDir := filepath.FromSlash("../../tmp/_test") + err := os.MkdirAll(tmpDir, 0o777) + require.NoError(t, err) + dir, err := os.MkdirTemp(tmpDir, "") + require.NoError(t, err) + t.Cleanup(func() { + assert.NoError(t, os.RemoveAll(dir)) + }) + abs, err := filepath.Abs(dir) + require.NoError(t, err) + return abs +} + func testdataPath(f string) string { return filepath.Join( filepath.FromSlash("../../internal/bindown/testdata"),