Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
32 changes: 22 additions & 10 deletions placebo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,7 +174,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
Expand Down Expand Up @@ -220,18 +224,26 @@ _create_new() {
if [[ "$a" == "-c" ]] ; then
cat >> "$f" <<EOD

list() {
declare -f | awk '/ \(\) $/ && !/^list / {print \$1}'
}

_check_response() {
if [[ $2 -ne 0 ]]; then
exit $2
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"
else
echo $1
echo "\$RES"
fi
}

list() {
declare -f | awk '/ \(\) $/ && !/^list / {print \$1}'
}

if [[ "\$1" == "-l" ]] ; then
list
true
Expand Down