From 97a80e93ae0373ec51d8135a832cc224f72e9a91 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 15 Oct 2015 11:11:41 +0200 Subject: [PATCH 01/14] Add first version of sharness_test_coverage_helper.sh License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 test/sharness_test_coverage_helper.sh diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh new file mode 100755 index 000000000..902200119 --- /dev/null +++ b/test/sharness_test_coverage_helper.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +USAGE="$0 [-h] [-v]" + +usage() { + echo "$USAGE" + echo " Print sharness test coverage" + echo " Options:" + echo " -h|--help: print this usage message and exit" + echo " -v|--verbose: print logs of what happens" + exit 0 +} + +log() { + test -z "$VERBOSE" || echo "->" "$@" +} + +die() { + printf >&2 "fatal: %s\n" "$@" + exit 1 +} + +# get user options +while [ "$#" -gt "0" ]; do + # get options + arg="$1" + shift + + case "$arg" in + -h|--help) + usage ;; + -v|--verbose) + VERBOSE=1 ;; + -*) + die "unrecognised option: '$arg'\n$USAGE" ;; + *) + die "too many arguments\n$USAGE" ;; + esac +done + +log "Create temporary directory" +DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") +TMPDIR=$(mktemp -d "/tmp/coverage_helper.$DATE.XXXXXX") || +die "could not 'mktemp -d /tmp/coverage_helper.$DATE.XXXXXX'" + +log "Grep the sharness tests" +CMDRAW="$TMPDIR/ipfs_cmd_raw.txt" +git grep -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMDRAW" || +die "Could not grep ipfs in the sharness tests" + +log "Remove test_expect_{success,failure} lines" +CMDPROC1="$TMPDIR/ipfs_cmd_proc1.txt" +egrep -v 'test_expect_.*ipfs' "$CMDRAW" >"$CMDPROC1" || +die "Could not remove test_expect_{success,failure} lines" + +log "Remove comments" +CMDPROC2="$TMPDIR/ipfs_cmd_proc2.txt" +egrep -v '^\s*#' "$CMDPROC1" >"$CMDPROC2" || +die "Could not remove comments" + + +log "Print result" +cat "$CMDPROC2" + +# Remove temp directory... From 741c0e5e50870fa73915c29a2062ed46bfb3a3cc Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 15 Oct 2015 16:01:38 +0200 Subject: [PATCH 02/14] coverage_helper: remove more cruft License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 36 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 902200119..3ee339547 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -44,22 +44,44 @@ TMPDIR=$(mktemp -d "/tmp/coverage_helper.$DATE.XXXXXX") || die "could not 'mktemp -d /tmp/coverage_helper.$DATE.XXXXXX'" log "Grep the sharness tests" -CMDRAW="$TMPDIR/ipfs_cmd_raw.txt" -git grep -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMDRAW" || +CMD_RAW="$TMPDIR/ipfs_cmd_raw.txt" +git grep -n -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMD_RAW" || die "Could not grep ipfs in the sharness tests" log "Remove test_expect_{success,failure} lines" -CMDPROC1="$TMPDIR/ipfs_cmd_proc1.txt" -egrep -v 'test_expect_.*ipfs' "$CMDRAW" >"$CMDPROC1" || +CMD_EXPECT="$TMPDIR/ipfs_cmd_expect.txt" +egrep -v 'test_expect_.*ipfs' "$CMD_RAW" >"$CMD_EXPECT" || die "Could not remove test_expect_{success,failure} lines" log "Remove comments" -CMDPROC2="$TMPDIR/ipfs_cmd_proc2.txt" -egrep -v '^\s*#' "$CMDPROC1" >"$CMDPROC2" || +CMD_COMMENT="$TMPDIR/ipfs_cmd_comment.txt" +egrep -v '^\s*#' "$CMD_EXPECT" >"$CMD_COMMENT" || die "Could not remove comments" +log "Remove test_description lines" +CMD_DESC="$TMPDIR/ipfs_cmd_description.txt" +egrep -v 'test_description=' "$CMD_COMMENT" >"$CMD_DESC" || +die "Could not remove test_description lines" + +log "Remove echos lines" +CMD_ECHO="$TMPDIR/ipfs_cmd_echo.txt" +egrep -v '\Wecho\s[^|]*ipfs' "$CMD_DESC" >"$CMD_ECHO" || +die "Could not remove echo lines" + + + +log "Keep ipfs.*/ipfs/" +CMD_IPFS_OK="$TMPDIR/ipfs_cmd_ipfs_ok.txt" +egrep '\Wipfs\W.*/ipfs/' "$CMD_ECHO" >"$CMD_IPFS_OK" || +die "Could not keep 'ipfs.*/ipfs/'" + +log "Remove /ipfs/" +CMD_SLASH="$TMPDIR/ipfs_cmd_slash_ipfs.txt" +egrep -v '/ipfs/' "$CMD_ECHO" >"$CMD_SLASH" || +die "Could not remove /ipfs/" + log "Print result" -cat "$CMDPROC2" +cat "$CMD_SLASH" "$CMD_IPFS_OK" | sort # Remove temp directory... From 5abf294cf7f6933d55f1ca5a41038edd904ca48a Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 15 Oct 2015 16:50:02 +0200 Subject: [PATCH 03/14] coverage_helper: remove .ipfs License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 3ee339547..293ed8e8d 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -55,7 +55,7 @@ die "Could not remove test_expect_{success,failure} lines" log "Remove comments" CMD_COMMENT="$TMPDIR/ipfs_cmd_comment.txt" -egrep -v '^\s*#' "$CMD_EXPECT" >"$CMD_COMMENT" || +egrep -v '^[^:]+:[^:]+:\s*#' "$CMD_EXPECT" >"$CMD_COMMENT" || die "Could not remove comments" log "Remove test_description lines" @@ -65,23 +65,33 @@ die "Could not remove test_description lines" log "Remove echos lines" CMD_ECHO="$TMPDIR/ipfs_cmd_echo.txt" -egrep -v '\Wecho\s[^|]*ipfs' "$CMD_DESC" >"$CMD_ECHO" || +egrep -v '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' "$CMD_DESC" >"$CMD_ECHO" || die "Could not remove echo lines" log "Keep ipfs.*/ipfs/" -CMD_IPFS_OK="$TMPDIR/ipfs_cmd_ipfs_ok.txt" -egrep '\Wipfs\W.*/ipfs/' "$CMD_ECHO" >"$CMD_IPFS_OK" || -die "Could not keep 'ipfs.*/ipfs/'" +CMD_SLASH_OK="$TMPDIR/ipfs_cmd_slash_ok.txt" +egrep '\Wipfs\W.*/ipfs/' "$CMD_ECHO" >"$CMD_SLASH_OK" +# die "Could not keep ipfs.*/ipfs/" + +log "Keep ipfs.*\.ipfs and \.ipfs.*ipfs" +CMD_DOT_OK="$TMPDIR/ipfs_cmd_dot_ok.txt" +egrep -e '\Wipfs\W.*\.ipfs' -e '\.ipfs.*\Wipfs\W' "$CMD_ECHO" >"$CMD_DOT_OK" +# die "Could not keep ipfs.*\.ipfs and \.ipfs.*ipfs" log "Remove /ipfs/" -CMD_SLASH="$TMPDIR/ipfs_cmd_slash_ipfs.txt" +CMD_SLASH="$TMPDIR/ipfs_cmd_slash.txt" egrep -v '/ipfs/' "$CMD_ECHO" >"$CMD_SLASH" || die "Could not remove /ipfs/" +log "Remove .ipfs" +CMD_DOT="$TMPDIR/ipfs_cmd_dot.txt" +egrep -v '\.ipfs' "$CMD_SLASH" >"$CMD_DOT" || +die "Could not remove .ipfs" + log "Print result" -cat "$CMD_SLASH" "$CMD_IPFS_OK" | sort +cat "$CMD_DOT" "$CMD_SLASH_OK" "$CMD_DOT_OK" | sort # Remove temp directory... From 106b8413988c7dd9eb896d0b020572abbf806d85 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 15:02:39 +0200 Subject: [PATCH 04/14] coverage_helper: remove grep commands License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 293ed8e8d..08130d63e 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -63,9 +63,14 @@ CMD_DESC="$TMPDIR/ipfs_cmd_description.txt" egrep -v 'test_description=' "$CMD_COMMENT" >"$CMD_DESC" || die "Could not remove test_description lines" -log "Remove echos lines" +log "Remove grep lines" +CMD_GREP="$TMPDIR/ipfs_cmd_grep.txt" +egrep -v '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' "$CMD_DESC" >"$CMD_GREP" || +die "Could not remove grep lines" + +log "Remove echo lines" CMD_ECHO="$TMPDIR/ipfs_cmd_echo.txt" -egrep -v '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' "$CMD_DESC" >"$CMD_ECHO" || +egrep -v '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' "$CMD_GREP" >"$CMD_ECHO" || die "Could not remove echo lines" @@ -73,12 +78,10 @@ die "Could not remove echo lines" log "Keep ipfs.*/ipfs/" CMD_SLASH_OK="$TMPDIR/ipfs_cmd_slash_ok.txt" egrep '\Wipfs\W.*/ipfs/' "$CMD_ECHO" >"$CMD_SLASH_OK" -# die "Could not keep ipfs.*/ipfs/" log "Keep ipfs.*\.ipfs and \.ipfs.*ipfs" CMD_DOT_OK="$TMPDIR/ipfs_cmd_dot_ok.txt" egrep -e '\Wipfs\W.*\.ipfs' -e '\.ipfs.*\Wipfs\W' "$CMD_ECHO" >"$CMD_DOT_OK" -# die "Could not keep ipfs.*\.ipfs and \.ipfs.*ipfs" log "Remove /ipfs/" CMD_SLASH="$TMPDIR/ipfs_cmd_slash.txt" From 5e3d3895f52f99f7714f306bdd4aa186e0fc37f3 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 16:18:22 +0200 Subject: [PATCH 05/14] coverage_helper: refactor egreps License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 69 ++++++++++++--------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 08130d63e..f30af865c 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -48,53 +48,46 @@ CMD_RAW="$TMPDIR/ipfs_cmd_raw.txt" git grep -n -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMD_RAW" || die "Could not grep ipfs in the sharness tests" -log "Remove test_expect_{success,failure} lines" -CMD_EXPECT="$TMPDIR/ipfs_cmd_expect.txt" -egrep -v 'test_expect_.*ipfs' "$CMD_RAW" >"$CMD_EXPECT" || -die "Could not remove test_expect_{success,failure} lines" +grep_out() { + pattern="$1" + src="$TMPDIR/ipfs_cmd_${2}.txt" + dst="$TMPDIR/ipfs_cmd_${3}.txt" + desc="$4" -log "Remove comments" -CMD_COMMENT="$TMPDIR/ipfs_cmd_comment.txt" -egrep -v '^[^:]+:[^:]+:\s*#' "$CMD_EXPECT" >"$CMD_COMMENT" || -die "Could not remove comments" + log "Remove $desc" + egrep -v "$pattern" "$src" >"$dst" || die "Could not remove $desc" +} -log "Remove test_description lines" -CMD_DESC="$TMPDIR/ipfs_cmd_description.txt" -egrep -v 'test_description=' "$CMD_COMMENT" >"$CMD_DESC" || -die "Could not remove test_description lines" +grep_out 'test_expect_.*ipfs' raw expect "test_expect_{success,failure} lines" +grep_out '^[^:]+:[^:]+:\s*#' expect comment "comments" +grep_out 'test_description=' comment desc "test_description lines" +grep_out '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' desc grep "grep lines" +grep_out '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' grep echo "echo lines" -log "Remove grep lines" -CMD_GREP="$TMPDIR/ipfs_cmd_grep.txt" -egrep -v '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' "$CMD_DESC" >"$CMD_GREP" || -die "Could not remove grep lines" +grep_in() { + pattern="$1" + src="$TMPDIR/ipfs_cmd_${2}.txt" + dst="$TMPDIR/ipfs_cmd_${3}.txt" + desc="$4" -log "Remove echo lines" -CMD_ECHO="$TMPDIR/ipfs_cmd_echo.txt" -egrep -v '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' "$CMD_GREP" >"$CMD_ECHO" || -die "Could not remove echo lines" + log "Keep $desc" + egrep "$pattern" "$src" >"$dst" +} +grep_in '\Wipfs\W.*/ipfs/' echo slash_in1 "ipfs.*/ipfs/" +grep_in '/ipfs/.*\Wipfs\W' echo slash_in2 "/ipfs/.*ipfs" +grep_out '/ipfs/' echo slash "/ipfs/" -log "Keep ipfs.*/ipfs/" -CMD_SLASH_OK="$TMPDIR/ipfs_cmd_slash_ok.txt" -egrep '\Wipfs\W.*/ipfs/' "$CMD_ECHO" >"$CMD_SLASH_OK" - -log "Keep ipfs.*\.ipfs and \.ipfs.*ipfs" -CMD_DOT_OK="$TMPDIR/ipfs_cmd_dot_ok.txt" -egrep -e '\Wipfs\W.*\.ipfs' -e '\.ipfs.*\Wipfs\W' "$CMD_ECHO" >"$CMD_DOT_OK" - -log "Remove /ipfs/" -CMD_SLASH="$TMPDIR/ipfs_cmd_slash.txt" -egrep -v '/ipfs/' "$CMD_ECHO" >"$CMD_SLASH" || -die "Could not remove /ipfs/" - -log "Remove .ipfs" -CMD_DOT="$TMPDIR/ipfs_cmd_dot.txt" -egrep -v '\.ipfs' "$CMD_SLASH" >"$CMD_DOT" || -die "Could not remove .ipfs" +grep_in '\Wipfs\W.*\.ipfs' slash dot_in1 "ipfs.*\.ipfs" +grep_in '\.ipfs.*\Wipfs\W' slash dot_in2 "\.ipfs.*ipfs" +grep_out '\.ipfs' slash dot ".ipfs" log "Print result" -cat "$CMD_DOT" "$CMD_SLASH_OK" "$CMD_DOT_OK" | sort +for f in dot slash_in1 slash_in2 dot_in1 dot_in2 +do + cat "$TMPDIR/ipfs_cmd_${f}.txt" +done | sort | uniq # Remove temp directory... From 33c6df6827be971969be7ed1961049d47f175ca8 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 17:28:59 +0200 Subject: [PATCH 06/14] coverage_helper: get commands from 'ipfs commands' License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index f30af865c..b850a1bed 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -43,7 +43,7 @@ DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") TMPDIR=$(mktemp -d "/tmp/coverage_helper.$DATE.XXXXXX") || die "could not 'mktemp -d /tmp/coverage_helper.$DATE.XXXXXX'" -log "Grep the sharness tests" +log "Grep the sharness tests for ipfs commands" CMD_RAW="$TMPDIR/ipfs_cmd_raw.txt" git grep -n -E '\Wipfs\W' -- sharness/t*-*.sh >"$CMD_RAW" || die "Could not grep ipfs in the sharness tests" @@ -85,9 +85,15 @@ grep_in '\.ipfs.*\Wipfs\W' slash dot_in2 "\.ipfs.*ipfs" grep_out '\.ipfs' slash dot ".ipfs" log "Print result" +CMD_RES="$TMPDIR/ipfs_cmd_result.txt" for f in dot slash_in1 slash_in2 dot_in1 dot_in2 do - cat "$TMPDIR/ipfs_cmd_${f}.txt" -done | sort | uniq + fname="$TMPDIR/ipfs_cmd_${f}.txt" + cat "$fname" || die "Could not cat '$fname'" +done | sort | uniq >"$CMD_RES" || die "Could not write '$CMD_RES'" + +log "Get all the ipfs commands from 'ipfs commands'" +CMD_CMDS="$TMPDIR/commands.txt" +ipfs commands >"$CMD_CMDS" || die "'ipfs commands' failed" # Remove temp directory... From 06c3a21c946c990ab3e9e290fc583b98dcaaaad6 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 18:57:51 +0200 Subject: [PATCH 07/14] coverage_helper: match commands from both sources License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index b850a1bed..3b53fcc55 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -96,4 +96,33 @@ log "Get all the ipfs commands from 'ipfs commands'" CMD_CMDS="$TMPDIR/commands.txt" ipfs commands >"$CMD_CMDS" || die "'ipfs commands' failed" +# Portable function to reverse lines in a file +reverse() { + if type tac >/dev/null + then + tac "$@" + else + tail -r "$@" + fi +} + +log "Math the test line commands with the commands they use" +reverse "$CMD_CMDS" | while read -r ipfs cmd sub1 sub2 +do + if test -n "$sub2" + then + egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1(\W.*)*\W$sub2" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}_${sub1}_${sub2}.txt" + else + if test -n "$sub1" + then + egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}_${sub1}.txt" + else + if test -n "$cmd" + then + egrep "$ipfs(\W.*)*\W$cmd" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}.txt" + fi + fi + fi +done + # Remove temp directory... From 6291662b89655da9711617b6e12adcf584c3d26c Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 19:21:56 +0200 Subject: [PATCH 08/14] coverage_helper: output a result License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 3b53fcc55..ec202d874 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -106,23 +106,36 @@ reverse() { fi } -log "Math the test line commands with the commands they use" +log "Match the test line commands with the commands they use" +GLOBAL_REV="$TMPDIR/global_results_reversed.txt" reverse "$CMD_CMDS" | while read -r ipfs cmd sub1 sub2 do if test -n "$sub2" then - egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1(\W.*)*\W$sub2" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}_${sub1}_${sub2}.txt" + CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}_${sub1}_${sub2}.txt" + egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1(\W.*)*\W$sub2" "$CMD_RES" >"$CMD_OUT" + reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" + echo "$ipfs $cmd $sub1 $sub2" >>"$GLOBAL_REV" else if test -n "$sub1" then - egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}_${sub1}.txt" + CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}_${sub1}.txt" + egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1" "$CMD_RES" >"$CMD_OUT" + reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" + echo "$ipfs $cmd $sub1" >>"$GLOBAL_REV" else if test -n "$cmd" then - egrep "$ipfs(\W.*)*\W$cmd" "$CMD_RES" >"$TMPDIR/res_${ipfs}_${cmd}.txt" + CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}.txt" + egrep "$ipfs(\W.*)*\W$cmd" "$CMD_RES" >"$CMD_OUT" + reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" + echo "$ipfs $cmd" >>"$GLOBAL_REV" fi fi fi done +log "Print results" +reverse "$GLOBAL_REV" + # Remove temp directory... From 46394ce45253daa8b160d1e3d6793bf60e9d17c1 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 16 Oct 2015 22:59:31 +0200 Subject: [PATCH 09/14] coverage_helper: exclude variables definitions License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index ec202d874..a3b13fddf 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -61,7 +61,8 @@ grep_out() { grep_out 'test_expect_.*ipfs' raw expect "test_expect_{success,failure} lines" grep_out '^[^:]+:[^:]+:\s*#' expect comment "comments" grep_out 'test_description=' comment desc "test_description lines" -grep_out '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' desc grep "grep lines" +grep_out '^[^:]+:[^:]+:\s*\w+="[^"]*"\s*(\&\&)?\s*$' desc def "variable definition lines" +grep_out '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' def grep "grep lines" grep_out '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' grep echo "echo lines" grep_in() { From 292ef427d0be1cf675c9202542e4799c97a2ebff Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 Oct 2015 13:06:23 +0200 Subject: [PATCH 10/14] coverage_helper: refactor matching commands License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index a3b13fddf..3f1e0425f 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -111,28 +111,29 @@ log "Match the test line commands with the commands they use" GLOBAL_REV="$TMPDIR/global_results_reversed.txt" reverse "$CMD_CMDS" | while read -r ipfs cmd sub1 sub2 do - if test -n "$sub2" + if test -n "$cmd" then - CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}_${sub1}_${sub2}.txt" - egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1(\W.*)*\W$sub2" "$CMD_RES" >"$CMD_OUT" - reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" - echo "$ipfs $cmd $sub1 $sub2" >>"$GLOBAL_REV" - else + CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}" + PATTERN="$ipfs(\W.*)*\W$cmd" + NAME="$ipfs $cmd" + if test -n "$sub1" then - CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}_${sub1}.txt" - egrep "$ipfs(\W.*)*\W$cmd(\W.*)*\W$sub1" "$CMD_RES" >"$CMD_OUT" - reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" - echo "$ipfs $cmd $sub1" >>"$GLOBAL_REV" - else - if test -n "$cmd" + CMD_OUT="${CMD_OUT}_${sub1}" + PATTERN="$PATTERN(\W.*)*\W$sub1" + NAME="$NAME $sub1" + + if test -n "$sub2" then - CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}.txt" - egrep "$ipfs(\W.*)*\W$cmd" "$CMD_RES" >"$CMD_OUT" - reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" - echo "$ipfs $cmd" >>"$GLOBAL_REV" + CMD_OUT="${CMD_OUT}_${sub2}" + PATTERN="$PATTERN(\W.*)*\W$sub2" + NAME="$NAME $sub2" fi fi + + egrep "$PATTERN" "$CMD_RES" >"$CMD_OUT" + reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" + echo "$NAME" >>"$GLOBAL_REV" fi done From e1ef4d6f54483514a18abffac7c178cb5c376580 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 Oct 2015 16:30:51 +0200 Subject: [PATCH 11/14] coverage_helper: log found commands License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 3f1e0425f..7140cc983 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -63,7 +63,9 @@ grep_out '^[^:]+:[^:]+:\s*#' expect comment "comments" grep_out 'test_description=' comment desc "test_description lines" grep_out '^[^:]+:[^:]+:\s*\w+="[^"]*"\s*(\&\&)?\s*$' desc def "variable definition lines" grep_out '^[^:]+:[^:]+:\s*e?grep\W[^|]*\Wipfs' def grep "grep lines" -grep_out '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' grep echo "echo lines" +grep_out '^[^:]+:[^:]+:\s*cat\W[^|]*\Wipfs' grep cat "cat lines" +grep_out '^[^:]+:[^:]+:\s*rmdir\W[^|]*\Wipfs' cat rmdir "rmdir lines" +grep_out '^[^:]+:[^:]+:\s*echo\W[^|]*\Wipfs' cat echo "echo lines" grep_in() { pattern="$1" @@ -131,12 +133,19 @@ do fi fi - egrep "$PATTERN" "$CMD_RES" >"$CMD_OUT" - reverse "$CMD_OUT" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" + egrep "$PATTERN" "$CMD_RES" >"$CMD_OUT.txt" + reverse "$CMD_OUT.txt" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" echo "$NAME" >>"$GLOBAL_REV" fi done +# The following will allow us to check that +# we are properly excuding enough stuff using: +# diff -u ipfs_cmd_result.txt cmd_found.txt +log "Get all the line commands that matched" +CMD_FOUND="$TMPDIR/cmd_found.txt" +cat $TMPDIR/res_*.txt | sort -n | uniq >"$CMD_FOUND" + log "Print results" reverse "$GLOBAL_REV" From c321f0626a445277524df803065f543789e4cb55 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 24 Oct 2015 07:54:15 +0200 Subject: [PATCH 12/14] coverage_helper: use 'ipfs commands --flags' License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 7140cc983..102f41c5f 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -97,7 +97,7 @@ done | sort | uniq >"$CMD_RES" || die "Could not write '$CMD_RES'" log "Get all the ipfs commands from 'ipfs commands'" CMD_CMDS="$TMPDIR/commands.txt" -ipfs commands >"$CMD_CMDS" || die "'ipfs commands' failed" +ipfs commands --flags >"$CMD_CMDS" || die "'ipfs commands' failed" # Portable function to reverse lines in a file reverse() { @@ -111,8 +111,14 @@ reverse() { log "Match the test line commands with the commands they use" GLOBAL_REV="$TMPDIR/global_results_reversed.txt" -reverse "$CMD_CMDS" | while read -r ipfs cmd sub1 sub2 -do + +process_command() { + ipfs="$1" + cmd="$2" + sub1="$3" + sub2="$4" + sub3="$5" + if test -n "$cmd" then CMD_OUT="$TMPDIR/res_${ipfs}_${cmd}" @@ -130,6 +136,13 @@ do CMD_OUT="${CMD_OUT}_${sub2}" PATTERN="$PATTERN(\W.*)*\W$sub2" NAME="$NAME $sub2" + + if test -n "$sub3" + then + CMD_OUT="${CMD_OUT}_${sub3}" + PATTERN="$PATTERN(\W.*)*\W$sub3" + NAME="$NAME $sub3" + fi fi fi @@ -137,6 +150,20 @@ do reverse "$CMD_OUT.txt" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" echo "$NAME" >>"$GLOBAL_REV" fi +} + +reverse "$CMD_CMDS" | while read -r line +do + LONG_CMD=$(echo "$line" | cut -d/ -f1) + SHORT_CMD=$(expr "$line" : "[^/]*/*\(.*\)") + + log "Processing $LONG_CMD" + process_command $LONG_CMD + + log "Processing $SHORT_CMD" + process_command $SHORT_CMD + + echo >>"$GLOBAL_REV" done # The following will allow us to check that From 891b4c569e52c7d125e758117815d4c248b6aec0 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 24 Oct 2015 11:22:53 +0200 Subject: [PATCH 13/14] coverage_helper: better group long and short options License: MIT Signed-off-by: Christian Couder --- test/sharness_test_coverage_helper.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/sharness_test_coverage_helper.sh b/test/sharness_test_coverage_helper.sh index 102f41c5f..99bcb7dbf 100755 --- a/test/sharness_test_coverage_helper.sh +++ b/test/sharness_test_coverage_helper.sh @@ -148,7 +148,6 @@ process_command() { egrep "$PATTERN" "$CMD_RES" >"$CMD_OUT.txt" reverse "$CMD_OUT.txt" | sed -e 's/^sharness\///' | cut -d- -f1 | uniq -c >>"$GLOBAL_REV" - echo "$NAME" >>"$GLOBAL_REV" fi } @@ -159,10 +158,14 @@ do log "Processing $LONG_CMD" process_command $LONG_CMD + LONG_NAME="$NAME" log "Processing $SHORT_CMD" process_command $SHORT_CMD + SHORT_NAME="$NAME" + test -n "$SHORT_CMD" && echo "$SHORT_NAME" >>"$GLOBAL_REV" + test "$LONG_CMD" != "ipfs" && echo "$LONG_NAME" >>"$GLOBAL_REV" echo >>"$GLOBAL_REV" done From d5da16faf62e8fd4e0eebf26a3e5f7ad259bd0b4 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 24 Oct 2015 12:34:40 +0200 Subject: [PATCH 14/14] test/Makefile: add coverage target License: MIT Signed-off-by: Christian Couder --- test/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Makefile b/test/Makefile index 16bc415fc..06df935ed 100644 --- a/test/Makefile +++ b/test/Makefile @@ -67,6 +67,11 @@ test_race: verify_gofmt cd 3nodetest && make GOFLAGS=-race cd dependencies && make GOFLAGS=-race +coverage: coverage_sharness + +coverage_sharness: + ./sharness_test_coverage_helper.sh + IPFS-BUILD-OPTIONS: FORCE @bin/checkflags '$@' '$(GOFLAGS)' '*** new Go flags ***'