Skip to content

Commit a57b6dd

Browse files
committed
Add test cases for generating debug log output
1 parent 74a1e00 commit a57b6dd

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

src/generate.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,12 @@ int generate_box(sentry_t *thebox)
739739
int rc;
740740
int i;
741741

742+
if (is_debug_logging(MAIN)) {
743+
for (i = 0; i < NUM_SHAPES; i++) {
744+
debug_print_shape(opt.design->shape + i);
745+
}
746+
}
747+
742748
rc = horiz_generate(&(thebox[0]), &(thebox[2]));
743749
if (rc) {
744750
goto err;

src/shape.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ void debug_print_shape(sentry_t *shape)
468468
log_debug(__FILE__, MAIN, "NULL\n");
469469
return;
470470
}
471-
log_debug(__FILE__, MAIN, "Shape %3s (%dx%d): elastic=%s, bl=",
472-
shape_name[shape->name], (int) shape->width, (int) shape->height, shape->elastic ? "true" : "false");
471+
log_debug(__FILE__, MAIN, "Shape %3s (%dx%d): elastic=%s,%s bl=",
472+
shape_name[shape->name], (int) shape->width, (int) shape->height,
473+
shape->elastic ? "true" : "false", shape->elastic ? " " : "");
473474
if (shape->blank_leftward == NULL) {
474475
log_debug_cont(MAIN, "NULL");
475476
}

test/192_logging1.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:DESC
2+
Test case which checks some logging features.
3+
4+
:ARGS
5+
-d dog -x debug:all
6+
:INPUT
7+
foo
8+
:OUTPUT-FILTER
9+
:EXPECTED discard-stderr
10+
__ _,--="=--,_ __
11+
/ \." .-. "./ \
12+
/ ,/ _ : : _ \/` \
13+
\ `| /o\ :_: /o\ |\__/
14+
`-'| :="~` _ `~"=: |
15+
\` (_) `/ jgs
16+
.-"-. \ | / .-"-.
17+
.---{ }--| /,.-'-.,\ |--{ }---.
18+
) (_)_)_) \_/`~-===-~`\_/ (_(_(_) (
19+
( foo )
20+
) (
21+
'---------------------------------------'
22+
:EOF

test/193_logging2.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:DESC
2+
Test case which checks some logging features.
3+
4+
:ARGS
5+
-d headline -x debug:main,regexp,parser,lexer,DISCOVERY
6+
:INPUT
7+
Hello World!
8+
:OUTPUT-FILTER
9+
:EXPECTED discard-stderr
10+
/*****************************/
11+
/* H e l l o W o r l d ! */
12+
/*****************************/
13+
:EOF
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:DESC
2+
Test case 130 with logging turned on.
3+
4+
:ARGS
5+
-f 130_data/B.cfg -d designA -p l1 -a vc -x debug:all
6+
:INPUT
7+
foo
8+
:OUTPUT-FILTER
9+
:EXPECTED discard-stderr
10+
AAA
11+
AAA foo
12+
AAA
13+
:EOF

test/testrunner.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ function arrange_test_fixtures()
232232
if [ $(grep -c "^:EXPECTED-ERROR " ${opt_testCase}) -eq 1 ]; then
233233
expectedReturnCode=$(grep "^:EXPECTED-ERROR " "${opt_testCase}" | sed -e 's/:EXPECTED-ERROR //')
234234
fi
235+
if [ $(grep -c "^:EXPECTED discard-stderr" ${opt_testCase}) -eq 1 ]; then
236+
discardStderr=true
237+
fi
235238

236239
cat "${opt_testCase}" | sed -n '/^:INPUT/,/^:OUTPUT-FILTER/p;' | sed '1d;$d' | tr -d '\r' > "${testInputFile}"
237240
cat "${opt_testCase}" | sed -n '/^:OUTPUT-FILTER/,/^:EXPECTED\b.*$/p;' | sed '1d;$d' | tr -d '\r' > "${testFilterFile}"
@@ -248,9 +251,17 @@ function run_boxes()
248251

249252
echo " Invoking: $(basename $boxesBinary) $boxesArgs"
250253
if [ -z "${BOXES_TEST_XXD:-}" ]; then
251-
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2>&1
254+
if [ ${discardStderr} == true ]; then
255+
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2> "$testErrorFile"
256+
else
257+
eval "$boxesBinary $boxesArgs" < "$testInputFile" > "$testOutputFile" 2>&1
258+
fi
252259
else
253-
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2>&1
260+
if [ ${discardStderr} == true ]; then
261+
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2> "$testErrorFile"
262+
else
263+
eval "$boxesBinary $boxesArgs" < "$testInputFile" | xxd > "$testOutputFile" 2>&1
264+
fi
254265
fi
255266
actualReturnCode=$?
256267
}
@@ -311,7 +322,9 @@ declare -r testInputFile=${opt_testCase/%.txt/.input.tmp}
311322
declare -r testExpectationFile=${opt_testCase/%.txt/.expected.tmp}
312323
declare -r testFilterFile=${opt_testCase/%.txt/.sed.tmp}
313324
declare -r testOutputFile=${opt_testCase/%.txt/.out.tmp}
325+
declare -r testErrorFile=${opt_testCase/%.txt/.err.tmp}
314326
declare -r boxesArgs=$(sed -n '/^:ARGS/,+1p' < "${opt_testCase}" | grep -v ^:INPUT | sed '1d' | tr -d '\r')
327+
declare discardStderr=false
315328

316329
arrange_environment
317330
arrange_test_fixtures
@@ -328,6 +341,7 @@ rm "${testInputFile}"
328341
rm "${testFilterFile}"
329342
rm "${testExpectationFile}"
330343
rm "${testOutputFile}"
344+
rm -f "${testErrorFile}"
331345

332346
echo " OK"
333347
exit 0

0 commit comments

Comments
 (0)