Make it easier to run tests with debug graphs
This commit is contained in:
parent
eee3db08d2
commit
6304a3bcd1
3 changed files with 24 additions and 9 deletions
24
script/test
24
script/test
|
|
@ -26,8 +26,7 @@ OPTIONS
|
|||
|
||||
-s set the seed used to control random behavior
|
||||
|
||||
-z pipe tests' stderr to \`dot(1)\` to render an SVG log
|
||||
|
||||
-D pipe tests' stderr to \`dot(1)\` to render an SVG log
|
||||
|
||||
EOF
|
||||
}
|
||||
|
|
@ -46,7 +45,7 @@ if [ "$(uname -s)" == "Darwin" ]; then
|
|||
export LINK="clang++ -fsanitize=address"
|
||||
fi
|
||||
|
||||
while getopts "bdf:s:gGhpvS" option; do
|
||||
while getopts "bdf:s:gGhpvD" option; do
|
||||
case ${option} in
|
||||
h)
|
||||
usage
|
||||
|
|
@ -74,7 +73,8 @@ while getopts "bdf:s:gGhpvS" option; do
|
|||
s)
|
||||
export TREE_SITTER_SEED=${OPTARG}
|
||||
;;
|
||||
S)
|
||||
D)
|
||||
export TREE_SITTER_ENABLE_DEBUG_GRAPHS=1
|
||||
mode=SVG
|
||||
;;
|
||||
b)
|
||||
|
|
@ -123,9 +123,19 @@ case ${mode} in
|
|||
;;
|
||||
|
||||
SVG)
|
||||
echo "<!DOCTYPE html><style>svg { width: 100%; margin-bottom: 20px; }</style>" > index.html
|
||||
$cmd "${args[@]}" 2> >(grep -v 'Assertion failed' | dot -Tsvg >> index.html)
|
||||
echo "Wrote index.html"
|
||||
function write_log_file {
|
||||
echo "<!DOCTYPE html><style>svg { width: 100%; margin-bottom: 20px; }</style>" > log.html
|
||||
line_count=$(grep -n '^$' log.dot | tail -1 | cut -f1 -d:)
|
||||
head -n $line_count log.dot | dot -Tsvg >> log.html
|
||||
echo "Wrote log.html ($line_count lines)"
|
||||
}
|
||||
|
||||
function handle_sigint { echo; write_log_file; }
|
||||
trap handle_sigint SIGINT
|
||||
|
||||
$cmd "${args[@]}" 2> log.dot || export status=$?
|
||||
write_log_file
|
||||
exit $status
|
||||
;;
|
||||
|
||||
normal)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ for (auto &language_name : test_languages) {
|
|||
ts_document_set_language(document, load_real_language(language_name));
|
||||
|
||||
// ts_document_set_logger(document, stderr_logger_new(true));
|
||||
// ts_document_print_debugging_graphs(document, true);
|
||||
if (getenv("TREE_SITTER_ENABLE_DEBUG_GRAPHS")) {
|
||||
ts_document_print_debugging_graphs(document, true);
|
||||
}
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
|
|
|
|||
|
|
@ -54,8 +54,11 @@ for (auto &language_name : test_languages) {
|
|||
ts_document_set_language(document, language);
|
||||
ts_document_set_input_string_with_length(document, entry.input.c_str(), entry.input.size());
|
||||
|
||||
// ts_document_set_logger(document, stderr_logger_new(true));
|
||||
// ts_document_print_debugging_graphs(document, true);
|
||||
if (getenv("TREE_SITTER_ENABLE_DEBUG_GRAPHS")) {
|
||||
ts_document_print_debugging_graphs(document, true);
|
||||
}
|
||||
|
||||
ts_document_parse(document);
|
||||
|
||||
TSNode root_node = ts_document_root_node(document);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue