diff mbox

[Cbuildv2/get_source,06/17] lib/common.sh: find_snapshot should return list of found snapshots even on error.

Message ID 1382129579-5777-7-git-send-email-ryan.arnold@linaro.org
State New
Headers show

Commit Message

Ryan S. Arnold Oct. 18, 2013, 8:52 p.m. UTC
From: "Ryan S. Arnold" <ryan.arnold@linaro.org>

Added a new test which tries to find an ambiguous snapshot.  This exposed a bug
in find_snapshot where it wasn't echoing the snapshots to stdout when there was
an error (such as too many matching snapshots).  This patches adds the new test
and fixes this error case.

This test also causes a return of '1' if too many matching snapshots were found
but one wasn't chosen, whereas in the past it would erroneously return '0'.
---
 lib/common.sh     | 21 ++++++++++++++-------
 testsuite/test.sh |  8 ++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/lib/common.sh b/lib/common.sh
index 1e3bc9f..1fcc06b 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -323,6 +323,7 @@  find_snapshot()
     if test x"${snapshot}" != x; then
 	if test `echo "${snapshot}" | grep -c $1` -gt 1; then
 	    warning "Too many results for $1!"
+	    echo "${snapshot}"
 	    return 1
 	fi
 	echo "${snapshot}"
@@ -336,6 +337,7 @@  find_snapshot()
     fi
     if test `echo "${snapshot}" | grep -c $1` -gt 1; then
 	warning "Too many results for $1!"
+	echo "${snapshot}"
 	return 1
     fi
 
@@ -367,7 +369,7 @@  get_source()
 	snapshot=`find_snapshot $1`
 	if test $? -gt 0; then
 	    if test x"${interactive}" = x"yes"; then
-	     	notice "Pick a unique snapshot name from this list: "
+	     	echo "Pick a unique snapshot name from this list: " 1>&2
 		for i in ${snapshot}; do
 		    echo "	$i" 1>&2
 		done
@@ -379,15 +381,20 @@  get_source()
 		    # If there is a config file for this toolchain component,
 		    # see if it has a latest version set. If so, we use that.
 		    if test x"${latest}"  != x; then
+		        fixme "explicit snapshot listed in latest." 1>&2
 			local url=`find_snapshot ${latest}`
 			return $?
 		    fi
-		    notice "Pick a unique snapshot name from this list and try again: "
-		    for i in ${snapshot}; do
-			echo "	$i" 1>&2
-		    done
-		    list_URL $1
-		    return 0
+		    # Technically 'notice' and 'get_URL' already suppress without
+		    # verbose being set but no reason to do unnecessary work.
+		    if test "${verbose}" -gt 0; then
+		        notice "Pick a unique snapshot name from this list and try again: "
+			for i in ${snapshot}; do
+			    echo "	$i" 1>&2
+			done
+		        list_URL $1
+		    fi
+		    return 1
 		fi
 	    fi
 	fi
diff --git a/testsuite/test.sh b/testsuite/test.sh
index 3859c0e..37b0f2a 100755
--- a/testsuite/test.sh
+++ b/testsuite/test.sh
@@ -363,6 +363,14 @@  else
     fixme "get_source returned \"${out}\""
 fi
 
+in="gcc-linaro"
+out="`get_source ${in} 2>/dev/null`"
+if test $? -eq 1; then
+    pass "get_source: Too many snapshot matches."
+else
+    fail "get_source: Too many snapshot matches."
+    fixme "get_source returned ${out}"
+fi
 
 # ----------------------------------------------------------------------------------