diff --git a/script/test b/script/test
index e582929a..90066137 100755
--- a/script/test
+++ b/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 "" > index.html
- $cmd "${args[@]}" 2> >(grep -v 'Assertion failed' | dot -Tsvg >> index.html)
- echo "Wrote index.html"
+ function write_log_file {
+ echo "" > 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)
diff --git a/test/integration/real_grammars.cc b/test/integration/real_grammars.cc
index a972aa27..13256364 100644
--- a/test/integration/real_grammars.cc
+++ b/test/integration/real_grammars.cc
@@ -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([&]() {
diff --git a/test/integration/test_grammars.cc b/test/integration/test_grammars.cc
index ded662df..9dbefcd8 100644
--- a/test/integration/test_grammars.cc
+++ b/test/integration/test_grammars.cc
@@ -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);