Skip to content

Commit 8fb4e12

Browse files
committed
Adopt the assert script helper from pulp-cli-deb
1 parent 733c80f commit 8fb4e12

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

cookiecutter/ci/{{ cookiecutter.__project_name }}/tests/scripts/config.source

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,28 @@ expect_deny () {
8080
fi
8181
}
8282

83+
# Expects the provided test to pass
84+
# Supresses all output, which is redirected to ASSERTION_OUTPUT and
85+
# ASSERTION_ERROUTPUT so as not to overwrite the latest OUTPUT and ERROUTPUT.
86+
# That way we can test several assertions in a row.
87+
# Reports verbosely on failure.
88+
assert () {
89+
if {
90+
[[ "$@" ]]
91+
} 1>log.out 2>log.err
92+
then
93+
echo "SUCCESS [$@]" >&3
94+
ASSERTION_OUTPUT="$(cat log.out)"
95+
ASSERTION_ERROUTPUT="$(cat log.err)"
96+
else
97+
echo "FAILURE [$@]" >&3
98+
echo "=== STDOUT ===" >&3
99+
cat log.out >&3
100+
echo "=== STDERR ===" >&3
101+
cat log.err >&3
102+
echo "==============" >&3
103+
false
104+
fi
105+
}
106+
83107
set -eu

tests/scripts/config.source

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,28 @@ expect_deny () {
8080
fi
8181
}
8282

83+
# Expects the provided test to pass
84+
# Supresses all output, which is redirected to ASSERTION_OUTPUT and
85+
# ASSERTION_ERROUTPUT so as not to overwrite the latest OUTPUT and ERROUTPUT.
86+
# That way we can test several assertions in a row.
87+
# Reports verbosely on failure.
88+
assert () {
89+
if {
90+
[[ "$@" ]]
91+
} 1>log.out 2>log.err
92+
then
93+
echo "SUCCESS [$@]" >&3
94+
ASSERTION_OUTPUT="$(cat log.out)"
95+
ASSERTION_ERROUTPUT="$(cat log.err)"
96+
else
97+
echo "FAILURE [$@]" >&3
98+
echo "=== STDOUT ===" >&3
99+
cat log.out >&3
100+
echo "=== STDERR ===" >&3
101+
cat log.err >&3
102+
echo "==============" >&3
103+
false
104+
fi
105+
}
106+
83107
set -eu

0 commit comments

Comments
 (0)