starlog/test_paths_test.go

33 lines
592 B
Go
Raw Permalink Normal View History

2026-03-19 16:37:57 +08:00
package starlog
import (
"os"
"path/filepath"
"strings"
"testing"
)
func sanitizeTestName(name string) string {
replacer := strings.NewReplacer(
"/", "_",
"\\", "_",
":", "_",
" ", "_",
"\t", "_",
".", "_",
)
return replacer.Replace(name)
}
func testBinDir(t *testing.T) string {
t.Helper()
dir := filepath.Join("bin", "tests", sanitizeTestName(t.Name()))
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("cleanup test bin dir failed: %v", err)
}
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatalf("create test bin dir failed: %v", err)
}
return dir
}