* [PATCH olang v1] tests: show test name into test execution output
@ 2024-10-11 12:26 Carlos Maniero
2024-10-11 12:26 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-11 17:06 ` [PATCH olang v1] tests: show test name into test execution output Johnny Richard
0 siblings, 2 replies; 3+ messages in thread
From: Carlos Maniero @ 2024-10-11 12:26 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero
The test output was printing a bunch of dots *.* during the test
execution. Now the tests are printing in the following format:
./0002_binary_operator_addition.ol [ OK ] [ 222ms ]
./0005_binary_operator_reminder.ol [ OK ] [ 264ms ]
./0004_binary_operator_division.ol [ OK ] [ 259ms ]
./0003_binary_operator_multiplication.ol [ OK ] [ 252ms ]
./0006_binary_operator_subtraction.ol [ OK ] [ 260ms ]
./0008_binary_operator_lt.ol [ OK ] [ 231ms ]
The script changed from multiple printf calls into a single call to make
sure the scripts can be executed in parallel without breaking the
output.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
tests/olc/run.sh | 59 +++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 28 deletions(-)
diff --git a/tests/olc/run.sh b/tests/olc/run.sh
index 503f960..033ab5b 100755
--- a/tests/olc/run.sh
+++ b/tests/olc/run.sh
@@ -28,7 +28,6 @@ TEST_INVOCATION=""
TEST_LINE_NUMBER=""
TEST_CONTENTS_PATH=""
TEST_ARGS=""
-TEST_SOME_PASSED=""
# UI
COLOR_RED=1
@@ -37,17 +36,21 @@ COLOR_YELLOW=3
COLOR_CYAN=6
COLOR_GRAY=7
+if [ -t 1 ]; then
+ if tput setaf 1 > /dev/null 2>&1; then
+ HAS_COLORS=1
+ fi
+fi
+
colored() {
text="$1"
- if [ -t 1 ]; then
- if tput setaf 1 > /dev/null 2>&1; then
- color=$(tput setaf "$2")
- reset=$(tput sgr0)
+ if [ -n "$HAS_COLORS" ]; then
+ color=$(tput setaf "$2")
+ reset=$(tput sgr0)
- printf "%s%s%s" "$color" "$text" "$reset"
- return
- fi
+ printf "%s%s%s" "$color" "$text" "$reset"
+ return
fi
printf "%s" "$text"
@@ -58,22 +61,12 @@ colored() {
print_failed() {
reason="$1"
- if [ -n "$TEST_SOME_PASSED" ]; then
- echo
- fi
-
- colored "$TEST_FILE:$TEST_LINE_NUMBER:1: " $COLOR_GRAY
- colored "[$TEST_INVOCATION] " $COLOR_CYAN
- colored "failed" $COLOR_RED
- if [ -n "$reason" ]; then
- printf ": %s" "$reason"
- fi
- echo
-}
-
-print_passed() {
- colored "." $COLOR_GREEN
- TEST_SOME_PASSED="true"
+ printf "%s:%s:1: %s %s: %s\n" \
+ "$TEST_FILE" \
+ "$TEST_LINE_NUMBER" \
+ "$(colored "failed" "$COLOR_RED")" \
+ "$(colored "$TEST_INVOCATION" "$COLOR_CYAN")" \
+ "$reason"
}
# end test output
@@ -88,9 +81,9 @@ expect_output_contains() {
if [ "$(grep "$(printf "%s" "$expected_line" | sed 's/\\/\\\\/g')" "$actual_file" | wc -c)" = "0" ]; then
print_failed
- colored "(not found) $expected_line" $COLOR_YELLOW
+ colored "(not found) $expected_line" "$COLOR_YELLOW"
echo
- colored "$(awk '{print "(actual) " $0}' "$actual_file")" $COLOR_GRAY
+ colored "$(awk '{print "(actual) " $0}' "$actual_file")" "$COLOR_GRAY"
echo
exit 1
fi
@@ -119,6 +112,8 @@ cleanup() {
main() {
all_test_end="$(grep -n "# END" "$TEST_FILE" | awk -F: '{print $1}')"
+ ts=$(date +%s%N)
+
grep -n "# TEST " "$TEST_FILE" | while read -r line ; do
TEST_LINE_NUMBER="$(echo "$line" | awk -F: '{ print $1 }')"
TEST_INVOCATION="$(echo "$line" | awk -F: '{ print $2 }' | sed 's/^\# TEST //' | sed 's/ WITH$//')"
@@ -147,14 +142,22 @@ main() {
if type "$TEST_NAME" | grep -q 'function'; then
"$TEST_NAME"
- print_passed
else
print_failed "test not implemented"
fi
done || exit 1;
+ elapsed=$((($(date +%s%N) - ts)/1000000))
+
+ padsize=$((59 - ${#TEST_FILE}))
+
+ printf "%s %*s [ %s ] [ % 4dms ]\n" \
+ "$TEST_FILE" \
+ $(( padsize > 0 ? padsize : 0 )) "" \
+ "$(colored "OK" "$COLOR_GREEN")"\
+ $elapsed
+
cleanup
- echo
}
get_test_args() {
base-commit: 3a988ec943cd6b97d9fd6ff255dcdc387f80516c
--
2.46.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [olang/patches/.build.yml] build success
2024-10-11 12:26 [PATCH olang v1] tests: show test name into test execution output Carlos Maniero
@ 2024-10-11 12:26 ` builds.sr.ht
2024-10-11 17:06 ` [PATCH olang v1] tests: show test name into test execution output Johnny Richard
1 sibling, 0 replies; 3+ messages in thread
From: builds.sr.ht @ 2024-10-11 12:26 UTC (permalink / raw)
To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel
olang/patches/.build.yml: SUCCESS in 29s
[tests: show test name into test execution output][0] from [Carlos Maniero][1]
[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/55436
[1]: mailto:carlos@maniero.me
✓ #1348789 SUCCESS olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1348789
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH olang v1] tests: show test name into test execution output
2024-10-11 12:26 [PATCH olang v1] tests: show test name into test execution output Carlos Maniero
2024-10-11 12:26 ` [olang/patches/.build.yml] build success builds.sr.ht
@ 2024-10-11 17:06 ` Johnny Richard
1 sibling, 0 replies; 3+ messages in thread
From: Johnny Richard @ 2024-10-11 17:06 UTC (permalink / raw)
To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel
Great work! the output looks great! applied.
To git.sr.ht:~johnnyrichard/olang
3a988ec..dae4440 main -> main
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-11 15:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-11 12:26 [PATCH olang v1] tests: show test name into test execution output Carlos Maniero
2024-10-11 12:26 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-11 17:06 ` [PATCH olang v1] tests: show test name into test execution output Johnny Richard
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox