Add test cases for generating debug log output

This commit is contained in:
Thomas Jensen 2024-09-27 22:31:44 +02:00
parent 83fc460a49
commit a71e1b875c
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
6 changed files with 73 additions and 4 deletions

View File

@ -739,6 +739,12 @@ int generate_box(sentry_t *thebox)
int rc; int rc;
int i; int i;
if (is_debug_logging(MAIN)) {
for (i = 0; i < NUM_SHAPES; i++) {
debug_print_shape(opt.design->shape + i);
}
}
rc = horiz_generate(&(thebox[0]), &(thebox[2])); rc = horiz_generate(&(thebox[0]), &(thebox[2]));
if (rc) { if (rc) {
goto err; goto err;

View File

@ -468,8 +468,9 @@ void debug_print_shape(sentry_t *shape)
log_debug(__FILE__, MAIN, "NULL\n"); log_debug(__FILE__, MAIN, "NULL\n");
return; return;
} }
log_debug(__FILE__, MAIN, "Shape %3s (%dx%d): elastic=%s, bl=", log_debug(__FILE__, MAIN, "Shape %3s (%dx%d): elastic=%s,%s bl=",
shape_name[shape->name], (int) shape->width, (int) shape->height, shape->elastic ? "true" : "false"); shape_name[shape->name], (int) shape->width, (int) shape->height,
shape->elastic ? "true" : "false", shape->elastic ? " " : "");
if (shape->blank_leftward == NULL) { if (shape->blank_leftward == NULL) {
log_debug_cont(MAIN, "NULL"); log_debug_cont(MAIN, "NULL");
} }

22
test/192_logging1.txt Normal file
View File

@ -0,0 +1,22 @@
:DESC
Test case which checks some logging features.
:ARGS
-d dog -x debug:all
:INPUT
foo
:OUTPUT-FILTER
:EXPECTED discard-stderr
__ _,--="=--,_ __
/ \." .-. "./ \
/ ,/ _ : : _ \/` \
\ `| /o\ :_: /o\ |\__/
`-'| :="~` _ `~"=: |
\` (_) `/ jgs
.-"-. \ | / .-"-.
.---{ }--| /,.-'-.,\ |--{ }---.
) (_)_)_) \_/`~-===-~`\_/ (_(_(_) (
( foo )
) (
'---------------------------------------'
:EOF

13
test/193_logging2.txt Normal file
View File

@ -0,0 +1,13 @@
:DESC
Test case which checks some logging features.
:ARGS
-d headline -x debug:main,regexp,parser,lexer,DISCOVERY
:INPUT
Hello World!
:OUTPUT-FILTER
:EXPECTED discard-stderr
/*****************************/
/* H e l l o W o r l d ! */
/*****************************/
:EOF

View File

@ -0,0 +1,13 @@
:DESC
Test case 130 with logging turned on.
:ARGS
-f 130_data/B.cfg -d designA -p l1 -a vc -x debug:all
:INPUT
foo
:OUTPUT-FILTER
:EXPECTED discard-stderr
AAA
AAA foo
AAA
:EOF

View File

@ -232,6 +232,9 @@ function arrange_test_fixtures()
if [ $(grep -c "^:EXPECTED-ERROR " ${opt_testCase}) -eq 1 ]; then if [ $(grep -c "^:EXPECTED-ERROR " ${opt_testCase}) -eq 1 ]; then
expectedReturnCode=$(grep "^:EXPECTED-ERROR " "${opt_testCase}" | sed -e 's/:EXPECTED-ERROR //') expectedReturnCode=$(grep "^:EXPECTED-ERROR " "${opt_testCase}" | sed -e 's/:EXPECTED-ERROR //')
fi fi
if [ $(grep -c "^:EXPECTED discard-stderr" ${opt_testCase}) -eq 1 ]; then
discardStderr=true
fi
cat "${opt_testCase}" | sed -n '/^:INPUT/,/^:OUTPUT-FILTER/p;' | sed '1d;$d' | tr -d '\r' > "${testInputFile}" cat "${opt_testCase}" | sed -n '/^:INPUT/,/^:OUTPUT-FILTER/p;' | sed '1d;$d' | tr -d '\r' > "${testInputFile}"
cat "${opt_testCase}" | sed -n '/^:OUTPUT-FILTER/,/^:EXPECTED\b.*$/p;' | sed '1d;$d' | tr -d '\r' > "${testFilterFile}" cat "${opt_testCase}" | sed -n '/^:OUTPUT-FILTER/,/^:EXPECTED\b.*$/p;' | sed '1d;$d' | tr -d '\r' > "${testFilterFile}"
@ -248,9 +251,17 @@ function run_boxes()
echo " Invoking: $(basename $boxesBinary) $boxesArgs" echo " Invoking: $(basename $boxesBinary) $boxesArgs"
if [ -z "${BOXES_TEST_XXD:-}" ]; then if [ -z "${BOXES_TEST_XXD:-}" ]; then
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2>&1 if [ ${discardStderr} == true ]; then
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2> "$testErrorFile"
else
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2>&1
fi
else else
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2>&1 if [ ${discardStderr} == true ]; then
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2> "$testErrorFile"
else
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2>&1
fi
fi fi
actualReturnCode=$? actualReturnCode=$?
} }
@ -311,7 +322,9 @@ declare -r testInputFile=${opt_testCase/%.txt/.input.tmp}
declare -r testExpectationFile=${opt_testCase/%.txt/.expected.tmp} declare -r testExpectationFile=${opt_testCase/%.txt/.expected.tmp}
declare -r testFilterFile=${opt_testCase/%.txt/.sed.tmp} declare -r testFilterFile=${opt_testCase/%.txt/.sed.tmp}
declare -r testOutputFile=${opt_testCase/%.txt/.out.tmp} declare -r testOutputFile=${opt_testCase/%.txt/.out.tmp}
declare -r testErrorFile=${opt_testCase/%.txt/.err.tmp}
declare -r boxesArgs=$(sed -n '/^:ARGS/,+1p' < "${opt_testCase}" | grep -v ^:INPUT | sed '1d' | tr -d '\r') declare -r boxesArgs=$(sed -n '/^:ARGS/,+1p' < "${opt_testCase}" | grep -v ^:INPUT | sed '1d' | tr -d '\r')
declare discardStderr=false
arrange_environment arrange_environment
arrange_test_fixtures arrange_test_fixtures
@ -328,6 +341,7 @@ rm "${testInputFile}"
rm "${testFilterFile}" rm "${testFilterFile}"
rm "${testExpectationFile}" rm "${testExpectationFile}"
rm "${testOutputFile}" rm "${testOutputFile}"
rm -f "${testErrorFile}"
echo " OK" echo " OK"
exit 0 exit 0