- 1 year ago
Run GO 1.7.x test from batch file and exclude vendor
To run Go 1.7.x tests from a batch file and exclude the vendor
directory, you can use the go test
command with the appropriate flags. Go 1.7.x doesn't have native support for excluding the vendor
directory, but you can achieve this by specifying a test package or file explicitly and excluding the vendor
path using the go list
command.
Here's an example batch file (e.g., run_tests.bat
) that demonstrates how to do this:
batch@echo off
setlocal enabledelayedexpansion
REM Set your Go workspace root path here
set "go_workspace=C:\path\to\your\go\workspace"
REM Get a list of all Go packages/files in the workspace, excluding vendor
for /f "delims=" %%i in ('go list ./... ^| findstr /v /c:"vendor"') do (
set "package=%%i"
REM Run the tests for the current package
echo Running tests for !package!
go test !package!
)
endlocal
Please modify the go_workspace
variable with the path to your Go workspace. This batch file will recursively list all Go packages and files in the workspace, excluding the vendor
directory, and then run tests for each package or file found.
Save the batch file, open a Command Prompt, navigate to the directory where the batch file is saved, and run the batch file:
run_tests.bat
The batch file will execute the go test
command for each package or file found, excluding the vendor
directory from the test coverage.
Keep in mind that Go 1.7.x is an old version of Go, and you should consider upgrading to a more recent version for better performance, security, and language improvements. As of my knowledge cutoff in September 2021, Go 1.7.x is no longer supported by the Go team, and it is recommended to use the latest stable version of Go.