Add first version of sharness_test_coverage_helper.sh
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
Oct 15, 2015 at 11:11 UTC
97a80e93ae0373ec51d8135a832cc224f72e9a91
1 file changed
+65
test/sharness_test_coverage_helper.sh
new
+65
@@ -0,0 +1,65 @@
1
+#!/bin/sh
2
+
3
+USAGE="$0 [-h] [-v]"
4
+
5
+usage() {
6
+ echo "$USAGE"
7
+ echo " Print sharness test coverage"
8
+ echo " Options:"
9
+ echo " -h|--help: print this usage message and exit"
10
+ echo " -v|--verbose: print logs of what happens"
11
+ exit 0
12
+}
13
+
14
+log() {
15
+ test -z "$VERBOSE" || echo "->" "$@"
16
+}
17
+
18
+die() {
19
+ printf >&2 "fatal: %s\n" "$@"
20
+ exit 1
21
+}
22
+
23
+# get user options
24
+while [ "$#" -gt "0" ]; do
25
+ # get options
26
+ arg="$1"
27
+ shift
28
+
29
+ case "$arg" in
30
+ -h|--help)
31
+ usage ;;
32
+ -v|--verbose)
33
+ VERBOSE=1 ;;
34
+ -*)
35
+ die "unrecognised option: '$arg'\n$USAGE" ;;
36
+ *)
37
+ die "too many arguments\n$USAGE" ;;
38
+ esac
39
+done
40
+
41
+log "Create temporary directory"
42
+DATE=$(date +"%Y-%m-%dT%H:%M:%SZ")
43
+TMPDIR=$(mktemp -d "/tmp/coverage_helper.$DATE.XXXXXX") ||
44
+die "could not 'mktemp -d /tmp/coverage_helper.$DATE.XXXXXX'"
45
+
46
+log "Grep the sharness tests"
47
+CMDRAW="$TMPDIR/ipfs_cmd_raw.txt"
48
+git grep -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMDRAW" ||
49
+die "Could not grep ipfs in the sharness tests"
50
+
51
+log "Remove test_expect_{success,failure} lines"
52
+CMDPROC1="$TMPDIR/ipfs_cmd_proc1.txt"
53
+egrep -v 'test_expect_.*ipfs' "$CMDRAW" >"$CMDPROC1" ||
54
+die "Could not remove test_expect_{success,failure} lines"
55
+
56
+log "Remove comments"
57
+CMDPROC2="$TMPDIR/ipfs_cmd_proc2.txt"
58
+egrep -v '^\s*#' "$CMDPROC1" >"$CMDPROC2" ||
59
+die "Could not remove comments"
60
+
61
+
62
+log "Print result"
63
+cat "$CMDPROC2"
64
+
65
+# Remove temp directory...