Skip to content

Commit

Permalink
lib/testing: Move common functions into a scaffold (test_scaffold)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
  • Loading branch information
justaugustus committed Aug 20, 2019
1 parent 336d176 commit 1c78f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 1 addition & 11 deletions lib/common_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ set -o errexit
set -o pipefail

TEST_run_stateful() {
tmpDir="$( mktemp -d )"
trap 'rm -rf -- "$tmpDir"' EXIT

# override some vars and func to not clutter output
common::timestamp() { :; }
# shellcheck disable=SC2034
PROGSTATE="${tmpDir}/whats-a-progstate-even.txt" \
LOGFILE="${tmpDir}/some-log-file.log" \
HR='' \
TPUT[BOLD]='' \
TPUT[OFF]=''
test_scaffold

assert_equal_content \
<( common::run_stateful --strip-args 'printf %s\n%s arg1 arg2' ) \
Expand Down
15 changes: 15 additions & 0 deletions lib/testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ test_main() {
done
}

test_scaffold() {
func_name="${FUNCNAME[1]}"
tmpDir="$(mktemp -d "${func_name}.XXXXXX")"
trap 'rm -rf -- "$tmpDir"' EXIT

# override some vars and func to not clutter output
common::timestamp() { :; }
# shellcheck disable=SC2034
PROGSTATE="${tmpDir}/${func_name}-state.txt" \
LOGFILE="${tmpDir}/${func_name}.log" \
HR='' \
TPUT[BOLD]='' \
TPUT[OFF]=''
}

assert_equal_content() {
local actual_file="$1"
local expected_file="$2"
Expand Down

0 comments on commit 1c78f0c

Please sign in to comment.