sdd icon indicating copy to clipboard operation
sdd copied to clipboard

Use bash errexit option to abort failing commands

Open pylipp opened this issue 6 years ago • 1 comments

pylipp avatar Jul 14 '19 09:07 pylipp

Experimented, but to no avail.

index 9381623..0d5b740 100644
--- a/lib/sdd/framework/utils.bash
+++ b/lib/sdd/framework/utils.bash
@@ -167,9 +167,11 @@ _install_single_app() {
         if [ ! -f "$appfilepath" ]; then continue; fi
 
         unset -f sdd_install 2> /dev/null || true
-        source "$appfilepath"
 
-        if sdd_install "$version" && [ $success = False ]; then
+        ( set -e; source "$appfilepath"; sdd_install "$version" )
+        rc=$?
+
+        if [ $rc -eq 0 ] && [ $success = False ]; then
             success=True
 
             # Record installed app and version (can be empty)
diff --git a/test/framework/bin.bats b/test/framework/bin.bats
index 3d20a5e..b48eda7 100644
--- a/test/framework/bin.bats
+++ b/test/framework/bin.bats
@@ -203,6 +203,15 @@ teardown() {
   [ "$(tail -n1 $appsrecordfilepath)" = "valid_app=1.1" ]
 }
 
+@test "invoking install command with erroneous app fails" {
+  echo "sdd_install() { echo 1; false; echo 2; }" > $invalidappfilepath
+
+  run sdd install invalid_app
+  assert_failure
+  assert_line -n 0 'Failed to install "invalid_app".'
+  assert_equal ${#lines[@]} 1
+}
+
 @test "invoking uninstall command without argument fails" {
   run sdd uninstall
   [ "$status" -eq 1 ]

pylipp avatar Feb 15 '20 18:02 pylipp