Go测试文件默认缓存位置及各平台官方路径咨询
Great question—you’re totally right that the official Go docs don’t spell out the test cache directories for every platform in a single, easy-to-find spot. But let’s break this down clearly, based on Go’s actual behavior and source code:
- Linux: Your initial guess was spot-on! The test cache lives under
$HOME/.cache/go-build. This is part of Go’s broader build cache, which stores test results, compiled packages, and other build artifacts. - macOS: It follows macOS’s standard cache conventions, sitting at
$HOME/Library/Caches/go-build. - Windows: On Windows systems, the cache directory is
%LocalAppData%\go-build(this typically resolves to a path likeC:\Users\<YourUsername>\AppData\Local\go-build).
How to Verify the Exact Path on Your System
If you want a foolproof way to confirm the cache location for your specific environment (even if you’ve set a custom GOCACHE variable), run this command in your terminal:
go env GOCACHE
This will print the root directory of Go’s build cache, which includes all test result caches. Go manages the internal subdirectory structure automatically, so you don’t need to navigate into those folders directly—go test handles checking and invalidating the cache whenever source files, dependencies, or build flags change.
内容的提问来源于stack exchange,提问作者syscll

