From 305c90090134b26a79290392180ac4e290188e5a Mon Sep 17 00:00:00 2001 From: Jason Goodsell Date: Wed, 3 Jul 2019 20:37:35 +1000 Subject: [PATCH 1/7] Fixed issue with parsing input arguments. There was an issue when calling the function from a sub processors and the input arguments were not working so well. --- placebo | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/placebo b/placebo index 3664d15..893b84a 100644 --- a/placebo +++ b/placebo @@ -170,7 +170,7 @@ _save_func() { if [[ ! $contains ]] ; then local s="$a() { - _check_response \$(source "$RES_PATH" "\$@") \$? + _check_response -r \$(source "$RES_PATH" "\$@") -c \$? } " echo $s | cat - $COMMAND_PATH > temp && mv temp $COMMAND_PATH @@ -220,18 +220,26 @@ _create_new() { if [[ "$a" == "-c" ]] ; then cat >> "$f" < Date: Wed, 3 Jul 2019 20:38:53 +1000 Subject: [PATCH 2/7] Changed argument parsing approach in pill_detach. --- placebo | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/placebo b/placebo index 893b84a..3ae08ef 100644 --- a/placebo +++ b/placebo @@ -81,8 +81,12 @@ pill_log() { } pill_detach() { - [[ "$1" == "-h" ]] && \ - _usage detach && return + while test $# -gt 0; do + case "$1" in + -h) _usage detach; return;; + *) break;; + esac + done local f funcs funcs="_usage From 8bb651ee47db7077d32fb9ea29150361804fdd19 Mon Sep 17 00:00:00 2001 From: Jason Goodsell Date: Fri, 5 Jul 2019 13:24:07 +1000 Subject: [PATCH 3/7] Fixed issue when generating `function.sh`. --- placebo | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/placebo b/placebo index 3ae08ef..41f0f25 100644 --- a/placebo +++ b/placebo @@ -229,18 +229,18 @@ list() { } _check_response() { - while test $# -gt 0; do - case "$1" in - -r) shift; RES=$1; shift;; - -c) shift; CODE=$1; shift;; + while test "\$#" -gt 0; do + case "\$1" in + -r) shift; RES="\$1"; shift;; + -c) shift; CODE="\$1"; shift;; *) break;; esac done - if [[ $CODE -ne 0 ]]; then - exit $CODE + if [[ "\$CODE" -ne 0 ]]; then + exit "\$CODE" else - echo $RES + echo "\$RES" fi } From 8018495a7d5fdceec97865c6b7772c2b6b0f2598 Mon Sep 17 00:00:00 2001 From: Jason Goodsell Date: Fri, 5 Jul 2019 13:37:11 +1000 Subject: [PATCH 4/7] Wrap around quotes. --- placebo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/placebo b/placebo index 41f0f25..7248ee9 100644 --- a/placebo +++ b/placebo @@ -174,7 +174,7 @@ _save_func() { if [[ ! $contains ]] ; then local s="$a() { - _check_response -r \$(source "$RES_PATH" "\$@") -c \$? + _check_response -r "\$(source "$RES_PATH" "\$@")" -c "\$?" } " echo $s | cat - $COMMAND_PATH > temp && mv temp $COMMAND_PATH From ece1d9942a84c8202ef6f78bbf575affe4a12d6a Mon Sep 17 00:00:00 2001 From: Jason Goodsell Date: Fri, 5 Jul 2019 13:47:42 +1000 Subject: [PATCH 5/7] Fixed quote escaping. --- placebo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/placebo b/placebo index 7248ee9..6993cca 100644 --- a/placebo +++ b/placebo @@ -174,7 +174,7 @@ _save_func() { if [[ ! $contains ]] ; then local s="$a() { - _check_response -r "\$(source "$RES_PATH" "\$@")" -c "\$?" + _check_response -r \"\$(source "$RES_PATH" "\$@")\" -c \"\$?\" } " echo $s | cat - $COMMAND_PATH > temp && mv temp $COMMAND_PATH From b5b2cbae78fafcd0b987e1175819ef8a14d92f9d Mon Sep 17 00:00:00 2001 From: Jason Goodsell Date: Fri, 5 Jul 2019 20:43:54 +1000 Subject: [PATCH 6/7] Fixed build pipeline. Build pipeline should now fail if any of the tests fail. --- azure-pipelines.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index 06fdf53..cc8112f 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -21,9 +21,13 @@ steps: gem install simplecov-cobertura displayName: 'Installing Dependencies' -- script: | - bashcov --skip-uncovered test/placebo.sh +- task: Bash@3 displayName: 'Running Unit Test' + inputs: + targetType: 'inline' + script: | + bashcov --skip-uncovered "test/placebo.sh" + exit $? - task: PublishCodeCoverageResults@1 displayName: 'Publish code coverage' From 8cab4e34de6add8f91ea32d34575e7cb7947997c Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Thu, 25 Jul 2019 10:27:10 +1000 Subject: [PATCH 7/7] Correction in README.md (#6) The upstream project no longer differs from this project in that regard. The major difference is now the way the commands to mock are chosen. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c17d028..ececab0 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ This repository is a fork of alexharv074's [bash_placebo](https://github.com/alexharv074/bash_placebo). -Major difference between the two projects is this project is built to generate mock commands for unit testing with any bash command while the original is built specifically to mock `aws` cli commands. - ## Installation The tool can be installed just by copying the script from the master branch into your path somewhere. E.g.