go test $(go list ./... | grep -v /vendor/) -coverprofile .testCoverage.txt
I am using the above command to test the files but there is 1 folder with the name "Store" that I want to exclude from tests. How it can be done?
You can use --exclude multiples times. Note that the dir thefoldertoexclude after --exclude option is relative to the sourcefolder , i.e., sourcefolder/thefoldertoexclude . Also you can add -n for dry run to see what will be copied before performing real operation, and if everything is ok, remove -n from command line.
We can also use cp command to copy folders from one location to another excluding specific directories. Go your source directory i.e ostechnix in our case. The above command will copy all contents of the current folder ostechnix except the sub-directory dir2 and saves them to /home/sk/backup/ directory.
Method 1 : Using the option “-prune -o” We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!
You're already doing it:
$(go list ./... | grep -v /vendor/)
The grep -v /vendor/
part is to exclude the /vendor/
directory. So just do the same for your Store
directory:
go test $(go list ./... | grep -v /Store/) -coverprofile .testCoverage.txt
Note that excluding /vendor/
this way is not necessary (unless you're using a really old version of Go). If you are using an old version of Go, you can combine them:
go test $(go list ./... | grep -v /vendor/ | grep -v /Store/) -coverprofile .testCoverage.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With