@@ -18,6 +18,10 @@ serial_packages=(
1818 " github.com/hyperledger/fabric/gossip/..."
1919)
2020
21+ no_coverage_packages=(
22+ " github.com/hyperledger/fabric/core/handlers/library"
23+ )
24+
2125# packages which need to be tested with build tag pkcs11
2226pkcs11_packages=(
2327 " github.com/hyperledger/fabric/bccsp/factory"
@@ -132,10 +136,18 @@ serial_test_packages() {
132136 fi
133137}
134138
139+ no_coverage_test_packages () {
140+ local filter
141+ filter=$( package_filter " ${no_coverage_packages[@]} " )
142+ if [ -n " $filter " ]; then
143+ join_by $' \n ' " $@ " | grep -E " $filter " || true
144+ fi
145+ }
146+
135147# "go test" the provided packages. Packages that are not present in the serial package list
136148# will be tested in parallel
137149run_tests () {
138- local -a flags=( " -cover " )
150+ local -a flags
139151 if [ -n " ${VERBOSE} " ]; then
140152 flags+=(" -v" )
141153 fi
@@ -153,21 +165,33 @@ run_tests() {
153165 local -a serial
154166 while IFS= read -r pkg; do serial+=(" $pkg " ); done < <( serial_test_packages " $@ " )
155167 if [ " ${# serial[@]} " -ne 0 ]; then
156- go test " ${flags[@]} " -failfast -tags " $GO_TAGS " " ${serial[@]} " -short -p 1 -timeout=20m
168+ go test -cover " ${flags[@]} " -failfast -tags " $GO_TAGS " " ${serial[@]} " -short -p 1 -timeout=20m
157169 fi
158170
159171 local -a parallel
160172 while IFS= read -r pkg; do parallel+=(" $pkg " ); done < <( parallel_test_packages " $@ " )
161173 if [ " ${# parallel[@]} " -ne 0 ]; then
162- go test " ${flags[@]} " " ${race_flags[@]} " -tags " $GO_TAGS " " ${parallel[@]} " -short -timeout=20m
174+ go test -cover " ${flags[@]} " " ${race_flags[@]} " -tags " $GO_TAGS " " ${parallel[@]} " -short -timeout=20m -skip=NoCover
175+ fi
176+
177+ # The -cover flag changes the import table of the test and the plugin
178+ # so that they cannot interact with each other.
179+ # In the name of tests that work with plugins we added the suffix NoCover
180+ # and do not run these tests with the -cover flag.
181+ # We run such tests separately, without the -cover flag.
182+ local -a no_coverage
183+ while IFS= read -r pkg; do no_coverage+=(" $pkg " ); done < <( no_coverage_test_packages " $@ " )
184+ if [ " ${# no_coverage[@]} " -ne 0 ]; then
185+ echo " test with no coverage"
186+ go test " ${flags[@]} " " ${race_flags[@]} " -tags " $GO_TAGS " " ${no_coverage[@]} " -short -timeout=20m -run=NoCover
163187 fi
164188 }
165189}
166190
167191# "go test" the provided packages and generate code coverage reports.
168192run_tests_with_coverage () {
169193 # run the tests serially
170- time go test -p 1 -cover -coverprofile=profile_tmp.cov -tags " $GO_TAGS " " $@ " -timeout=20m
194+ time go test -p 1 -cover -coverprofile=profile_tmp.cov -tags " $GO_TAGS " " $@ " -timeout=20m -skip=NoCover
171195 tail -n +2 profile_tmp.cov >> profile.cov && rm profile_tmp.cov
172196}
173197
0 commit comments