Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sympl
Sympl Testing Suite
Commits
a66c367c
Commit
a66c367c
authored
Apr 16, 2021
by
Paul Cammish
Browse files
Fix output to properly support --cron, -q and -v
parent
c383e213
Changes
1
Hide whitespace changes
Inline
Side-by-side
sympl-tests
View file @
a66c367c
...
...
@@ -17,6 +17,7 @@ _debug() {
_warn
()
{
echo
-e
"
\0
33[1m
\0
33[33m WARN:
\0
33[0m
$@
"
_log
" WARN:
$@
"
}
_error
()
{
...
...
@@ -31,13 +32,11 @@ _stop() {
}
_echo
()
{
if
[
$DEBUG
]
;
then
echo
-e
" INFO:
$@
"
elif
[
$VERBOSE
]
;
then
_debug
" INFO: (
$VERBOSITY
)
$@
"
if
[
$VERBOSITY
-gt
2
]
;
then
echo
-e
"
$@
"
else
_log
"
$@
"
fi
fi
_log
"
$@
"
}
_log
()
{
...
...
@@ -45,61 +44,91 @@ _log() {
}
_pass
()
{
if
[
$
QUIET
]
||
[
$QUIETQUIET
]
;
then
if
[
$
VERBOSITY
-eq
1
]
||
[
$VERBOSITY
-eq
2
]
;
then
echo
-ne
"
\0
33[32m.
\0
33[0m"
_centre_logonly -
"
\0
33[1m
\0
33[32m
$script
\0
33[0m"
_log
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre_logonly -
"
\0
33[1m
\0
33[32mPASS
\0
33[0m
\0
33[2m"
else
_centre -
"
\0
33[1m
\0
33[32m
$script
\0
33[0m"
_echo
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre -
"
\0
33[1m
\0
33[32mPASS
\0
33[0m
\0
33[2m"
fi
}
_fail
()
{
if
[
$
QUIETQUIET
]
;
then
if
[
$
VERBOSITY
-eq
1
]
;
then
echo
-ne
"
\0
33[1m
\0
33[31mF
\0
33[0m"
elif
[
$QUIET
]
;
then
echo
VERBOSE
=
true
_centre -
"
$script
"
cat
/dev/shm/sympl-tests_stdout
_centre -
"
\0
33[1m
\0
33[31mFAIL
\0
33[0m"
unset
VERBOSE
_centre_logonly -
"
\0
33[1m
\0
33[31m
$script
\0
33[0m"
_log
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre_logonly -
"
\0
33[1m
\0
33[31mFAIL
\0
33[0m"
else
cat
/dev/shm/sympl-tests_stdout
_centre -
"
\0
33[1m
\0
33[31mFAIL
\0
33[0m
\0
33[2m"
_loud
_echo
_centre -
"
\0
33[1m
\0
33[31m
$script
\0
33[0m"
_echo
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre -
"
\0
33[1m
\0
33[31mFAIL
\0
33[0m"
_quiet
fi
}
_test_error
()
{
if
[
$
QUIETQUIET
]
;
then
if
[
$
VERBOSITY
-eq
1
]
;
then
echo
-ne
"
\0
33[1m
\0
33[1m
\0
33[33mX
\0
33[0m"
elif
[
$QUIET
]
;
then
echo
VERBOSE
=
true
_centre -
"
$script
"
cat
/dev/shm/sympl-tests_stdout
_centre -
"
\0
33[1m
\0
33[5m
\0
33[33m[TEST ERROR]
\0
33[0m"
unset
VERBOSE
_centre_logonly -
"
\0
33[1m
\0
33[33m
$script
\0
33[0m"
_log
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre_logonly -
"
\0
33[1m
\0
33[5m
\0
33[33m[TEST ERROR]
\0
33[0m"
else
cat
/dev/shm/sympl-tests_stdout
_loud
_echo
_centre -
"
\0
33[1m
\0
33[33m
$script
\0
33[0m"
_echo
"
$(
cat
/dev/shm/sympl-tests_stdout
)
"
_centre -
"
\0
33[1m
\0
33[5m
\0
33[33m[TEST ERROR]
\0
33[0m"
_quiet
fi
}
_centre
()
{
_debug
"(
$VERBOSITY
) Centre
$1$1
$2
$1$1
"
spacer
=
"
$1
"
line
=
"
$2
"
stripped_line
=
"
$(
echo
$line
|
sed
's|\\033[[0-9;]*m||g'
)
"
if
[
$VERBOSE
]
;
then
if
[
$VERBOSITY
-gt
1
]
;
then
# as cut can't ignore the control codes, we need to work out of we need to add anything to the output to make it line up
# in other cases we can just use cut to trim it down
if
((
${#
stripped_line
}
% 2
))
;
then
extra_char
=
$spacer
;
else
extra_char
=
""
;
fi
col
=
"
$(
tput cols
)
"
||
col
=
80
col
=
$((
col
-
3
))
len
=
$((
(
col
/
2
)
-
(
(
${#
stripped_line
}
+
1
)
/
2
)
))
echo
-e
"
\0
33[2m
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
\0
33[0m
$line
\0
33[2m
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
\0
33[0m"
echo
-e
"
\0
33[2m
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
\0
33[0m
$line
\0
33[2m
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$extra_char
\0
33[0m"
fi
col
=
78
len
=
$((
(
col
/
2
)
-
(
(
${#
stripped_line
}
+
1
)
/
2
)
))
_log
"
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$stripped_line
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
"
|
cut
-c
1-
$((
col
))
_log
"
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$stripped_line
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$spacer
"
|
cut
-c
1-
$((
col
))
}
_centre_logonly
()
{
_debug
"(
$VERBOSITY
) Centre
$1$1
$2
$1$1
"
spacer
=
"
$1
"
line
=
"
$2
"
stripped_line
=
"
$(
echo
$line
|
sed
's|\\033[[0-9;]*m||g'
)
"
col
=
78
len
=
$((
(
col
/
2
)
-
(
(
${#
stripped_line
}
+
1
)
/
2
)
))
_log
"
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$stripped_line
$(
for
each
in
$(
seq
1
$len
)
;
do
printf
"
$spacer
"
;
done
)
$spacer
"
|
cut
-c
1-
$((
col
))
}
_loud
()
{
_debug turning up VERBOSITY from
$VERBOSITY
to
$((
VERBOSITY+10
))
VERBOSITY
=
$((
VERBOSITY+10
))
}
_quiet
()
{
_debug turning down VERBOSITY from
$VERBOSITY
to
$((
VERBOSITY-10
))
VERBOSITY
=
$((
VERBOSITY-10
))
}
#############################################################################
# Set Defaults #
#############################################################################
...
...
@@ -107,6 +136,16 @@ _centre() {
TIMESTAMP
=
"
$(
date
+%s
)
"
TEST_PATH
=
"
$(
dirname
$0
)
/tests.d"
VERBOSE
=
true
# VERBOSITY is now chatty stdout is:
# 3+ Verbose, output from each test
# 2 Quiet, output from failed/errored tests, dots for others
# 1 Very Quiet, output only dots and letters
# 0 Silent, no output, only log
# add & remove 10 to verbosity to make things loud when needed
VERBOSITY
=
3
LOG
=
"./sympl-tests.log"
#############################################################################
...
...
@@ -136,9 +175,11 @@ while [ $# -gt 0 ]; do
;;
--cron
)
unset
VERBOSE
VERBOSITY
=
0
shift
;;
--quiet
)
--quiet
|
-q
)
VERBOSITY
=
$((
VERBOSITY-1
))
unset
VERBOSE
if
[
$QUIET
]
;
then
QUIETQUIET
=
true
...
...
@@ -147,7 +188,8 @@ while [ $# -gt 0 ]; do
fi
shift
;;
--verbose
)
--verbose
|
-v
)
VERBOSITY
=
$((
VERBOSITY+1
))
VERBOSE
=
true
shift
;;
...
...
@@ -162,6 +204,7 @@ _debug "Command line variables:
------------------------------------------
UNKNOWN |
$PARAMETERS
VERBOSE |
$VERBOSE
VERBOSITY |
$VERBOSITY
LOG |
$LOG
TEST_PATH |
$TEST_PATH
DEBUG |
$DEBUG
...
...
@@ -174,18 +217,22 @@ TIMESTAMP="$(date +%s)"
if
[
-f
"
$LOG
"
]
;
then
rm
"
$LOG
"
;
fi
#_echo "Starting run at $(date ; if [ "$TEST_PATH" != "./tests.d" ] ; then echo -n ", test path: '$TEST_PATH'" ; fi )"
if
[
$VERBOSITY
-ne
1
]
;
then
_echo
"Starting run at
$(
date
;
if
[
"
$TEST_PATH
"
!=
"./tests.d"
]
;
then
echo
-n
", test path: '
$TEST_PATH
'"
;
fi
)
"
fi
_centre
=
Starting
TOTAL
=
$(
find
$TEST_PATH
-type
f
-executable
|
wc
-l
)
for
script
in
$(
find
$TEST_PATH
-type
f
-executable
|
sort
)
;
do
_echo
_centre -
"
$script
"
#
_centre - "$script"
echo
-n
>
/dev/shm/sympl-tests_stdout
# trap "_error $script failed! ; cat /dev/shm/sympl-tests_stdout_$TIMESTAMP /dev/shm/sympl-tests_stderr_$TIMESTAMP" ERR
$script
>
/dev/shm/sympl-tests_stdout 2>&1
exitcode
=
$?
# _echo "$( cat /dev/shm/sympl-tests_stdout )"
if
[
$exitcode
==
0
]
;
then
PASS
=
$((
PASS+1
))
_pass
...
...
@@ -198,10 +245,31 @@ for script in $( find $TEST_PATH -type f -executable | sort ) ; do
fi
rm
/dev/shm/sympl-tests_stdout
done
_echo
_centre
=
Summary
_echo
"Test run completed at
$(
date
)
"
_echo
"Passed:
$PASS
/
$TOTAL
$(
printf
%.2f%%
"
$((
10
**
3
*
100
*
$PASS
/
$TOTAL
))
e-3"
)
Failed:
$FAIL
Errors:
$ERROR
"
_centre
=
"End"
#run-parts tests.d/00-system -a ~/git/sympl-tests/sympl-tests
if
[
$VERBOSITY
-gt
1
]
;
then
_loud
fi
_echo
_centre
=
Summary
_echo
"Test run completed at
$(
date
)
"
_echo
"Passed:
\0
33[1m
\0
33[32m
$PASS
\0
33[0m/
$TOTAL
(
\0
33[1m
\0
33[32m
$(
printf
%.2f%%
"
$((
10
**
3
*
100
*
$PASS
/
$TOTAL
))
e-3"
)
\0
33[0m) Failed:
\0
33[1m
\0
33[31m
$FAIL
\0
33[0m Errors:
\0
33[1m
\0
33[33m
$ERROR
\0
33[0m"
_centre
=
"End"
if
[
$VERBOSITY
-eq
1
]
;
then
echo
fi
if
[
$ERROR
-gt
0
]
;
then
#grep output the fails and errors from the log to stdout
exit
255
elif
[
$FAIL
-gt
0
]
;
then
#grep output the fails from the log to stdout
exit
$FAIL
elif
[
$PASS
-eq
$TOTAL
]
;
then
exit
0
else
exit
255
fi
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment