Skip to content

Commit

Permalink
Log execution of fakes functions
Browse files Browse the repository at this point in the history
  • Loading branch information
extsoft committed Dec 15, 2017
1 parent a0dfda8 commit 5d346be
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/test/addons-fake.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ MOCK_DIR="/tmp/elegant-git-mock"
export PATH=$MOCK_DIR:$PATH


fake() {
# @todo #89 Implement logging of commands execution like in addons-git.bash
_log_fake(){
echo "$(basename ${BASH_SOURCE[0]}): $@"
}

_ex_fake() {
_log_fake "$@"
eval "$@"
}

fake() {
# sample: fake <command> <subcommand> <exit> <stdout> <stderr>
BASENAME=$(basename $1)
PROGRAM_PATH="$MOCK_DIR/$BASENAME-app"
FIXTURE_HOME="$PROGRAM_PATH/$(echo "$2" | sed 's/[^0-9a-zA-Z]*//g')"
MOCK="$MOCK_DIR/$BASENAME"

[ -d "$FIXTURE_HOME" ] && rm -r "$FIXTURE_HOME"
mkdir -p "$FIXTURE_HOME"
echo -e "$3" > "$FIXTURE_HOME/exit_code"
echo -e "$4" > "$FIXTURE_HOME/stdout"
echo -e "$5" > "$FIXTURE_HOME/stderr"
_ex_fake mkdir -p "$FIXTURE_HOME"
echo -e "$3" | tee -i "$FIXTURE_HOME/exit_code"
echo -e "$4" | tee -i "$FIXTURE_HOME/stdout"
echo -e "$5" | tee -i "$FIXTURE_HOME/stderr"

[ -e "$MOCK" ] && rm -r "$MOCK"
echo "#!/usr/bin/env bash
Expand All @@ -28,8 +35,8 @@ cat \"\$FIXTURE_HOME/stdout\"
cat \"\$FIXTURE_HOME/stderr\" >&2
read -r exit_code < \"\$FIXTURE_HOME/exit_code\"
exit \$exit_code
" > "$MOCK"
chmod +x "$MOCK"
" | tee -i "$MOCK"
_ex_fake chmod +x "$MOCK"
}

fake-pass() {
Expand Down

0 comments on commit 5d346be

Please sign in to comment.