Skip to content

Commit c7b03a6

Browse files
authored
Merge branch 'main' into refactor-reorganize-auth-and-credential
2 parents 6599ee9 + a683e9a commit c7b03a6

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
File renamed without changes.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
test: vendor check-encoding
1616
go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
1717

18+
.PHONY: test-coverage
19+
test-coverage: ## look at code coverage
20+
@echo
21+
@echo "==> Running unit tests with coverage: $(PKG) <=="
22+
@ ./scripts/coverage.sh $(PKG)
23+
1824
.PHONY: covhtml
1925
covhtml:
2026
open .cover/coverage.html

scripts/coverage.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The ORAS Authors.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -euo pipefail
17+
18+
covermode=${COVERMODE:-atomic}
19+
coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX)
20+
trap 'rm -rf "${coverdir}"' EXIT
21+
profile="${coverdir}/cover.out"
22+
html=false
23+
target="./..." # by default the whole repository is tested
24+
for arg in "$@"; do
25+
case "${arg}" in
26+
--html)
27+
html=true
28+
;;
29+
*)
30+
target="${arg}"
31+
;;
32+
esac
33+
done
34+
35+
generate_cover_data() {
36+
for d in $(go list "$target"); do
37+
(
38+
local output="${coverdir}/${d//\//-}.cover"
39+
go test -coverprofile="${output}" -covermode="$covermode" "$d"
40+
)
41+
done
42+
43+
echo "mode: $covermode" >"$profile"
44+
grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile"
45+
}
46+
47+
generate_cover_data
48+
go tool cover -func "${profile}"
49+
50+
if [ "${html}" = "true" ] ; then
51+
go tool cover -html "${profile}"
52+
fi
53+

0 commit comments

Comments
 (0)