Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude or skip specific directory while running 'go test' [duplicate]

Tags:

testing

go

goland

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?

like image 607
kishorK Avatar asked Mar 18 '19 15:03

kishorK


People also ask

How do I use CP to exclude a specific directory?

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.

How do I copy everything except one folder?

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.

How do I exclude a specific directory in Linux?

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!


1 Answers

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
like image 175
Flimzy Avatar answered Oct 21 '22 08:10

Flimzy