Skip to content

Commit

Permalink
tests: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ALX99 committed Sep 17, 2024
1 parent 2c2cc8e commit 82e4791
Show file tree
Hide file tree
Showing 10 changed files with 35,833 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test runner

on:
push:
pull_request:

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run unit tests
run: go test -v ./...
- name: Run shell tests
run: ./test.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
bin/
61 changes: 61 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -euo pipefail

# Build the go-bcov binary
go build -o bin/go-bcov *.go

# Define an array of repositories and their branches
declare -A repos=(
["https://github.com/jellydator/ttlcache"]="v3.3.0"
["https://github.com/rs/zerolog"]="v1.33.0"
["https://github.com/expr-lang/expr"]="v1.16.9"
)

process_repo() {
local repo="$1"
local branch="$2"
local action="$3"

tmp_dir="$(mktemp -d)"
trap 'rm -rf -- "${tmp_dir:-?}"' EXIT INT TERM HUP

git clone --depth 1 --branch "$branch" "$repo" "${tmp_dir}"

cp bin/go-bcov "${tmp_dir}"
cp "testdata/$(basename "$repo")_coverage.out" "${tmp_dir}/coverage.out" 2>/dev/null || true

pushd "${tmp_dir}"

[[ ! -f coverage.out ]] &&
go test -coverprofile coverage.out -covermode count ./...

./go-bcov -format sonar-cover-report <coverage.out >coverage.xml

popd

if [[ $action == "check" ]]; then
go run tools/xmldiff.go "testdata/$(basename "$repo")_sonar-cover-report.xml" "${tmp_dir}/coverage.xml"
elif [[ $action == "generate" ]]; then
cp "${tmp_dir}/coverage.xml" "testdata/$(basename "$repo")_sonar-cover-report.xml"
cp "${tmp_dir}/coverage.out" "testdata/$(basename "$repo")_coverage.out"
fi
}

check() {
for repo in "${!repos[@]}"; do
process_repo "$repo" "${repos[$repo]}" "check"
done
}

generate_test_data() {
for repo in "${!repos[@]}"; do
process_repo "$repo" "${repos[$repo]}" "generate"
done
}

if [[ ${1:-} == "--generate-test-data" ]]; then
generate_test_data
else
check
fi
10,318 changes: 10,318 additions & 0 deletions testdata/expr_coverage.out

Large diffs are not rendered by default.

17,830 changes: 17,830 additions & 0 deletions testdata/expr_sonar-cover-report.xml

Large diffs are not rendered by default.

198 changes: 198 additions & 0 deletions testdata/ttlcache_coverage.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
mode: count
github.com/jellydator/ttlcache/v3/cache.go:61.66,75.2 9 4
github.com/jellydator/ttlcache/v3/cache.go:81.73,84.33 2 35
github.com/jellydator/ttlcache/v3/cache.go:84.33,86.3 1 32
github.com/jellydator/ttlcache/v3/cache.go:88.2,88.11 1 35
github.com/jellydator/ttlcache/v3/cache.go:88.11,90.3 1 17
github.com/jellydator/ttlcache/v3/cache.go:90.8,92.3 1 18
github.com/jellydator/ttlcache/v3/cache.go:94.2,97.93 2 35
github.com/jellydator/ttlcache/v3/cache.go:97.93,99.3 1 14
github.com/jellydator/ttlcache/v3/cache.go:101.2,109.30 2 21
github.com/jellydator/ttlcache/v3/cache.go:109.30,113.10 1 6
github.com/jellydator/ttlcache/v3/cache.go:114.32,115.14 1 6
github.com/jellydator/ttlcache/v3/cache.go:115.14,117.5 1 3
github.com/jellydator/ttlcache/v3/cache.go:118.11,118.11 0 0
github.com/jellydator/ttlcache/v3/cache.go:125.2,125.22 1 21
github.com/jellydator/ttlcache/v3/cache.go:131.74,132.23 1 17
github.com/jellydator/ttlcache/v3/cache.go:132.23,134.3 1 4
github.com/jellydator/ttlcache/v3/cache.go:136.2,137.17 2 17
github.com/jellydator/ttlcache/v3/cache.go:137.17,144.3 4 7
github.com/jellydator/ttlcache/v3/cache.go:146.2,146.82 1 10
github.com/jellydator/ttlcache/v3/cache.go:146.82,149.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:151.2,151.33 1 10
github.com/jellydator/ttlcache/v3/cache.go:151.33,153.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:156.2,166.44 9 10
github.com/jellydator/ttlcache/v3/cache.go:166.44,168.3 1 12
github.com/jellydator/ttlcache/v3/cache.go:169.2,171.13 2 10
github.com/jellydator/ttlcache/v3/cache.go:179.81,181.17 2 38
github.com/jellydator/ttlcache/v3/cache.go:181.17,183.3 1 20
github.com/jellydator/ttlcache/v3/cache.go:185.2,186.47 2 18
github.com/jellydator/ttlcache/v3/cache.go:186.47,188.3 1 2
github.com/jellydator/ttlcache/v3/cache.go:190.2,192.27 2 16
github.com/jellydator/ttlcache/v3/cache.go:192.27,195.3 2 5
github.com/jellydator/ttlcache/v3/cache.go:197.2,197.13 1 16
github.com/jellydator/ttlcache/v3/cache.go:209.94,217.17 3 15
github.com/jellydator/ttlcache/v3/cache.go:217.17,219.3 1 8
github.com/jellydator/ttlcache/v3/cache.go:221.2,223.17 2 15
github.com/jellydator/ttlcache/v3/cache.go:223.17,225.3 1 8
github.com/jellydator/ttlcache/v3/cache.go:227.2,227.17 1 15
github.com/jellydator/ttlcache/v3/cache.go:227.17,232.43 4 10
github.com/jellydator/ttlcache/v3/cache.go:232.43,234.4 1 4
github.com/jellydator/ttlcache/v3/cache.go:236.3,236.13 1 6
github.com/jellydator/ttlcache/v3/cache.go:239.2,243.33 4 5
github.com/jellydator/ttlcache/v3/cache.go:251.76,252.20 1 12
github.com/jellydator/ttlcache/v3/cache.go:252.20,258.24 5 10
github.com/jellydator/ttlcache/v3/cache.go:258.24,264.45 5 11
github.com/jellydator/ttlcache/v3/cache.go:264.45,266.5 1 17
github.com/jellydator/ttlcache/v3/cache.go:268.3,270.9 2 10
github.com/jellydator/ttlcache/v3/cache.go:273.2,278.38 5 2
github.com/jellydator/ttlcache/v3/cache.go:278.38,281.44 2 6
github.com/jellydator/ttlcache/v3/cache.go:281.44,283.4 1 12
github.com/jellydator/ttlcache/v3/cache.go:285.2,289.47 4 2
github.com/jellydator/ttlcache/v3/cache.go:296.37,298.17 2 3
github.com/jellydator/ttlcache/v3/cache.go:298.17,300.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:302.2,302.38 1 2
github.com/jellydator/ttlcache/v3/cache.go:313.74,318.2 3 4
github.com/jellydator/ttlcache/v3/cache.go:324.68,326.2 1 8
github.com/jellydator/ttlcache/v3/cache.go:330.37,335.2 3 2
github.com/jellydator/ttlcache/v3/cache.go:338.39,344.2 4 3
github.com/jellydator/ttlcache/v3/cache.go:353.90,358.17 4 4
github.com/jellydator/ttlcache/v3/cache.go:358.17,360.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:362.2,369.20 4 3
github.com/jellydator/ttlcache/v3/cache.go:379.85,383.17 3 3
github.com/jellydator/ttlcache/v3/cache.go:383.17,391.28 4 2
github.com/jellydator/ttlcache/v3/cache.go:391.28,394.4 2 1
github.com/jellydator/ttlcache/v3/cache.go:396.3,396.20 1 1
github.com/jellydator/ttlcache/v3/cache.go:399.2,402.19 3 1
github.com/jellydator/ttlcache/v3/cache.go:406.35,410.2 3 1
github.com/jellydator/ttlcache/v3/cache.go:413.39,417.32 3 8
github.com/jellydator/ttlcache/v3/cache.go:417.32,419.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:421.2,422.46 2 7
github.com/jellydator/ttlcache/v3/cache.go:422.46,425.33 2 6
github.com/jellydator/ttlcache/v3/cache.go:425.33,426.9 1 3
github.com/jellydator/ttlcache/v3/cache.go:430.3,430.26 1 3
github.com/jellydator/ttlcache/v3/cache.go:437.36,441.2 3 1
github.com/jellydator/ttlcache/v3/cache.go:444.33,449.16 4 4
github.com/jellydator/ttlcache/v3/cache.go:449.16,451.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:454.2,454.29 1 3
github.com/jellydator/ttlcache/v3/cache.go:454.29,461.30 3 3
github.com/jellydator/ttlcache/v3/cache.go:461.30,463.4 1 1
github.com/jellydator/ttlcache/v3/cache.go:465.3,466.18 2 2
github.com/jellydator/ttlcache/v3/cache.go:466.18,471.28 4 28
github.com/jellydator/ttlcache/v3/cache.go:471.28,473.21 2 43
github.com/jellydator/ttlcache/v3/cache.go:473.21,474.11 1 14
github.com/jellydator/ttlcache/v3/cache.go:477.5,478.31 2 29
github.com/jellydator/ttlcache/v3/cache.go:478.31,480.6 1 26
github.com/jellydator/ttlcache/v3/cache.go:483.3,483.13 1 2
github.com/jellydator/ttlcache/v3/cache.go:486.2,486.31 1 3
github.com/jellydator/ttlcache/v3/cache.go:490.34,495.38 4 1
github.com/jellydator/ttlcache/v3/cache.go:495.38,496.50 1 4
github.com/jellydator/ttlcache/v3/cache.go:496.50,498.4 1 3
github.com/jellydator/ttlcache/v3/cache.go:501.2,501.12 1 1
github.com/jellydator/ttlcache/v3/cache.go:506.49,511.38 4 1
github.com/jellydator/ttlcache/v3/cache.go:511.38,513.45 2 4
github.com/jellydator/ttlcache/v3/cache.go:513.45,515.4 1 3
github.com/jellydator/ttlcache/v3/cache.go:518.2,518.14 1 1
github.com/jellydator/ttlcache/v3/cache.go:523.61,527.28 2 2
github.com/jellydator/ttlcache/v3/cache.go:527.28,530.3 2 1
github.com/jellydator/ttlcache/v3/cache.go:532.2,532.89 1 1
github.com/jellydator/ttlcache/v3/cache.go:532.89,537.25 4 3
github.com/jellydator/ttlcache/v3/cache.go:537.25,539.4 1 1
github.com/jellydator/ttlcache/v3/cache.go:541.3,541.25 1 2
github.com/jellydator/ttlcache/v3/cache.go:541.25,543.4 1 2
github.com/jellydator/ttlcache/v3/cache.go:549.70,553.28 2 2
github.com/jellydator/ttlcache/v3/cache.go:553.28,556.3 2 1
github.com/jellydator/ttlcache/v3/cache.go:558.2,558.89 1 1
github.com/jellydator/ttlcache/v3/cache.go:558.89,563.25 4 4
github.com/jellydator/ttlcache/v3/cache.go:563.25,565.4 1 1
github.com/jellydator/ttlcache/v3/cache.go:567.3,567.25 1 3
github.com/jellydator/ttlcache/v3/cache.go:567.25,569.4 1 3
github.com/jellydator/ttlcache/v3/cache.go:574.41,579.2 3 1
github.com/jellydator/ttlcache/v3/cache.go:584.31,585.34 1 2
github.com/jellydator/ttlcache/v3/cache.go:585.34,590.64 3 7
github.com/jellydator/ttlcache/v3/cache.go:590.64,592.14 2 4
github.com/jellydator/ttlcache/v3/cache.go:592.14,595.5 1 1
github.com/jellydator/ttlcache/v3/cache.go:597.4,597.12 1 3
github.com/jellydator/ttlcache/v3/cache.go:600.3,600.24 1 3
github.com/jellydator/ttlcache/v3/cache.go:600.24,602.4 1 2
github.com/jellydator/ttlcache/v3/cache.go:604.3,604.19 1 1
github.com/jellydator/ttlcache/v3/cache.go:607.2,608.17 2 2
github.com/jellydator/ttlcache/v3/cache.go:608.17,609.20 1 10
github.com/jellydator/ttlcache/v3/cache.go:609.20,611.11 1 5
github.com/jellydator/ttlcache/v3/cache.go:612.19,612.19 0 0
github.com/jellydator/ttlcache/v3/cache.go:613.12,613.12 0 5
github.com/jellydator/ttlcache/v3/cache.go:618.2,620.6 2 2
github.com/jellydator/ttlcache/v3/cache.go:620.6,621.10 1 10
github.com/jellydator/ttlcache/v3/cache.go:622.19,623.10 1 2
github.com/jellydator/ttlcache/v3/cache.go:624.31,626.18 2 3
github.com/jellydator/ttlcache/v3/cache.go:627.18,630.26 3 5
github.com/jellydator/ttlcache/v3/cache.go:637.30,639.2 1 2
github.com/jellydator/ttlcache/v3/cache.go:650.81,658.54 4 2
github.com/jellydator/ttlcache/v3/cache.go:658.54,660.13 2 2
github.com/jellydator/ttlcache/v3/cache.go:660.13,663.4 2 2
github.com/jellydator/ttlcache/v3/cache.go:665.2,668.16 3 2
github.com/jellydator/ttlcache/v3/cache.go:668.16,676.3 5 2
github.com/jellydator/ttlcache/v3/cache.go:688.96,696.71 4 3
github.com/jellydator/ttlcache/v3/cache.go:696.71,698.13 2 2
github.com/jellydator/ttlcache/v3/cache.go:698.13,701.4 2 2
github.com/jellydator/ttlcache/v3/cache.go:703.2,706.16 3 3
github.com/jellydator/ttlcache/v3/cache.go:706.16,714.3 5 3
github.com/jellydator/ttlcache/v3/cache.go:734.67,736.2 1 9
github.com/jellydator/ttlcache/v3/cache.go:748.119,749.18 1 2
github.com/jellydator/ttlcache/v3/cache.go:749.18,751.3 1 1
github.com/jellydator/ttlcache/v3/cache.go:753.2,756.3 1 2
github.com/jellydator/ttlcache/v3/cache.go:764.74,774.62 2 4
github.com/jellydator/ttlcache/v3/cache.go:774.62,776.18 2 2
github.com/jellydator/ttlcache/v3/cache.go:776.18,778.4 1 1
github.com/jellydator/ttlcache/v3/cache.go:780.3,780.19 1 1
github.com/jellydator/ttlcache/v3/cache.go:782.2,782.16 1 4
github.com/jellydator/ttlcache/v3/cache.go:782.16,784.3 1 2
github.com/jellydator/ttlcache/v3/cache.go:786.2,786.26 1 2
github.com/jellydator/ttlcache/v3/expiration_queue.go:13.70,17.2 3 61
github.com/jellydator/ttlcache/v3/expiration_queue.go:20.47,22.2 1 58
github.com/jellydator/ttlcache/v3/expiration_queue.go:25.60,27.2 1 19
github.com/jellydator/ttlcache/v3/expiration_queue.go:31.58,33.2 1 191
github.com/jellydator/ttlcache/v3/expiration_queue.go:37.60,39.2 1 12
github.com/jellydator/ttlcache/v3/expiration_queue.go:42.42,44.2 1 346
github.com/jellydator/ttlcache/v3/expiration_queue.go:48.52,50.30 2 192
github.com/jellydator/ttlcache/v3/expiration_queue.go:50.30,52.3 1 7
github.com/jellydator/ttlcache/v3/expiration_queue.go:54.2,54.30 1 185
github.com/jellydator/ttlcache/v3/expiration_queue.go:54.30,56.3 1 5
github.com/jellydator/ttlcache/v3/expiration_queue.go:58.2,58.48 1 180
github.com/jellydator/ttlcache/v3/expiration_queue.go:62.47,66.2 3 68
github.com/jellydator/ttlcache/v3/expiration_queue.go:69.53,73.2 3 192
github.com/jellydator/ttlcache/v3/expiration_queue.go:76.51,85.2 7 13
github.com/jellydator/ttlcache/v3/item.go:43.110,50.28 2 166
github.com/jellydator/ttlcache/v3/item.go:50.28,52.3 1 166
github.com/jellydator/ttlcache/v3/item.go:54.2,56.13 2 166
github.com/jellydator/ttlcache/v3/item.go:60.60,67.23 4 10
github.com/jellydator/ttlcache/v3/item.go:67.23,69.3 1 3
github.com/jellydator/ttlcache/v3/item.go:72.2,72.33 1 10
github.com/jellydator/ttlcache/v3/item.go:72.33,74.3 1 2
github.com/jellydator/ttlcache/v3/item.go:76.2,81.20 3 8
github.com/jellydator/ttlcache/v3/item.go:85.33,90.2 3 173
github.com/jellydator/ttlcache/v3/item.go:94.39,95.19 1 181
github.com/jellydator/ttlcache/v3/item.go:95.19,97.3 1 6
github.com/jellydator/ttlcache/v3/item.go:99.2,99.43 1 175
github.com/jellydator/ttlcache/v3/item.go:104.42,109.2 3 3
github.com/jellydator/ttlcache/v3/item.go:113.48,114.19 1 73
github.com/jellydator/ttlcache/v3/item.go:114.19,116.3 1 4
github.com/jellydator/ttlcache/v3/item.go:118.2,118.42 1 69
github.com/jellydator/ttlcache/v3/item.go:122.33,127.2 3 11
github.com/jellydator/ttlcache/v3/item.go:130.35,135.2 3 1
github.com/jellydator/ttlcache/v3/item.go:138.45,143.2 3 1
github.com/jellydator/ttlcache/v3/item.go:146.47,151.2 3 1
github.com/jellydator/ttlcache/v3/item.go:156.41,161.2 3 1
github.com/jellydator/ttlcache/v3/options.go:14.55,16.2 1 25
github.com/jellydator/ttlcache/v3/options.go:28.80,29.22 1 28
github.com/jellydator/ttlcache/v3/options.go:29.22,31.3 1 18
github.com/jellydator/ttlcache/v3/options.go:36.63,37.52 1 3
github.com/jellydator/ttlcache/v3/options.go:37.52,39.3 1 3
github.com/jellydator/ttlcache/v3/options.go:44.67,45.52 1 7
github.com/jellydator/ttlcache/v3/options.go:45.52,47.3 1 10
github.com/jellydator/ttlcache/v3/options.go:53.65,54.52 1 2
github.com/jellydator/ttlcache/v3/options.go:54.52,56.3 1 2
github.com/jellydator/ttlcache/v3/options.go:62.67,63.52 1 4
github.com/jellydator/ttlcache/v3/options.go:63.52,65.3 1 5
github.com/jellydator/ttlcache/v3/options.go:73.64,74.52 1 3
github.com/jellydator/ttlcache/v3/options.go:74.52,76.3 1 4
Loading

0 comments on commit 82e4791

Please # to comment.