You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/01/03 21:00:48 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #3768: Codecov

ocket8888 commented on a change in pull request #3768: Codecov
URL: https://github.com/apache/trafficcontrol/pull/3768#discussion_r362959470
 
 

 ##########
 File path: traffic_monitor/tests/gocover.bash
 ##########
 @@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#----------------------------------------
+set -e
+
+coverage_out=()
+i=1
+
+for d in $(go list ./... ../lib/... | grep -v vendor); do
+	file="$i.out"
+	go test -v -coverprofile="$file" "$d"
+	if [ -f "$file" ]; then
+		coverage_out+=($file)
+	fi
+	((i++))
+done
+
+gocovmerge ${coverage_out[*]} > coverage.out
+go tool cover -func=coverage.out
+go-junit-report --package-name=golang.test.tm --set-exit-code > /junit/golang.test.tm.xml
+touch coverage_out1
+for pkg in $(go list ./... ../lib/... | grep -v ); do
+	tmp="$(mktemp)"
+	go test -v -coverprofile covProfile "$pkg" > "$tmp"
+	mv -f "$tmp" coverage_out1
+done
 
 Review comment:
   It looks like you're now building the coverage profiles twice but only reading the results once, and you're no longer writing anything into `result.txt` (which might be okay - is it?). My script that I posted in a comment on my earlier review wasn't meant as a verbatim example of how to accomplish what you're trying to do, merely show that the two ways of getting a coverage profile would produce equivalent results.
   
   All you gotta do here is take that bottom `for` loop and paste it over the top one, I think. But it is missing some things, including a line which I missed in my comment originally (which I think is why). The actual loop should look like:
   
   ```bash
   touch coverage_out
   covtmp="$(mktemp)"
   covMergeTmp="$(mktemp)"
   for pkg in $(go list $@ | grep -v vendor); do
   	tmp="$(mktemp)"
   	go test -v -coverprofile "$covtmp" | tee -a result.txt
   	gocovmerge coverage_out "$covtmp" > "$covMergeTmp"
   	mv -f "$covMergeTmp" coverage_out
   done;
   ```
   which gets you what you're looking for in `result.txt` as well as `coverage_out`.
   Then, of course, there's no need to initialize `coverage_out` as a variable (since it's a file now) or `i`, and the `gocovmerge` line can be deleted.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services