Debian Codegraph @

util/test-count

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2025 The go-yaml Project Contributors
4 # SPDX-License-Identifier: Apache-2.0
5
6 # Show test count statistics for go-yaml
7
8 set -euo pipefail
9
10 # shellcheck disable=SC1091
11 source "$(dirname "$0")/common.bash"
12
13 main() (
14 echo '=== TEST COUNT SUMMARY ==='
15 echo
16
17 # Count YAML test cases
18 echo 'Data-driven YAML test cases:'
19 decode_count=$(grep -c '^- decode:' testdata/decode.yaml)
20 encode_count=$(grep -c '^- encode:' testdata/encode.yaml)
21 error_count=$(grep -c '^- unmarshal-error:' testdata/unmarshal_errors.yaml)
22 yaml_total=$((decode_count + encode_count + error_count))
23
24 printf ' %-22s %3d\n' 'decode.yaml:' "$decode_count"
25 printf ' %-22s %3d\n' 'encode.yaml:' "$encode_count"
26 printf ' %-22s %3d\n' 'unmarshal_errors.yaml:' "$error_count"
27 printf ' %-22s %3d\n' 'Subtotal:' "$yaml_total"
28 echo
29
30 # Count Go test cases
31 echo 'Go hardcoded test cases:'
32 unmarshal_count=$(awk '/^var unmarshalTests/,/^}$/{if(/^ {$/){count++}}END{print count}' decode_test.go)
33 marshal_count=$(awk '/^var marshalTests/,/^}$/{if(/^ {$/){count++}}END{print count}' encode_test.go)
34 go_total=$((unmarshal_count + marshal_count))
35
36 printf ' %-22s %3d\n' 'unmarshalTests:' "$unmarshal_count"
37 printf ' %-22s %3d\n' 'marshalTests:' "$marshal_count"
38 printf ' %-22s %3d\n' 'Subtotal:' "$go_total"
39 echo
40
41 # Total test cases
42 local case_total
43 case_total=$((yaml_total + go_total))
44 printf '%-24s %3d\n' 'Test case total:' "$case_total"
45 echo
46
47 # Count test executions (requires running tests)
48 echo 'Test executions (running tests to count...):'
49 test_output=$(go test -v . ./internal/... -vet=off 2>&1)
50 run_count=$(<<< "$test_output" grep -c '^=== RUN' || true)
51 pass_count=$(<<< "$test_output" grep -c 'PASS:' || true)
52
53 printf ' %-22s %4d\n' 'Unit test runs:' "$run_count"
54 printf ' %-22s %4d\n' 'Unit test passes:' "$pass_count"
55 echo
56 )
57
58 main "$@"