Skip to content

Commit

Permalink
testTmp
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Dec 9, 2023
1 parent 88aa45d commit d58599d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/bindown/testdata/golden/wrap/bindown-path/runnable
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 19 additions & 1 deletion cmd/bindown/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit d58599d

Please sign in to comment.