From 28a0d2121c9b2564eba7fc5e4b21361d88c9b422 Mon Sep 17 00:00:00 2001 From: Ondra Pelech Date: Wed, 24 May 2023 23:58:09 +0200 Subject: [PATCH 1/2] Shellcheck --- script/smoke_test.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/script/smoke_test.sh b/script/smoke_test.sh index 84cea89638..66252b172f 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -25,7 +25,7 @@ run_tree_sitter () { cmd="npm exec -c 'tree-sitter parse $source_dir/**/*.scala --quiet --stat' | sort | sed 's%$source_dir%%g'" echo echo "Parse $source_dir: $cmd" - out=$((eval $cmd) || true) + out=$( (eval "$cmd") || true) if [ ! -e "$PRODUCE_REPORTS" ]; then local report_file="report-$name.txt" @@ -34,7 +34,7 @@ run_tree_sitter () { fi actual=$(echo "$out" | grep 'success percentage:' | rev | cut -d' ' -f1 | rev | sed 's/%//g' ) - echo $actual + echo "$actual" if (( $(echo "$actual >= $expected" |bc -l) )); then # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-creating-an-annotation-for-an-error echo -e "::notice file=grammar.js,line=1::ok, ${source_dir}: ${actual}%, expected at least $expected%" @@ -44,10 +44,10 @@ run_tree_sitter () { fi } -run_tree_sitter $SCALA_SCALA_DIR/src/library/ $SCALA_SCALA_LIBRARY_EXPECTED scala2-library -run_tree_sitter $SCALA_SCALA_DIR/src/compiler/ $SCALA_SCALA_COMPILER_EXPECTED scala2-compiler -run_tree_sitter $DOTTY_DIR/compiler/ $DOTTY_COMPILER_EXPECTED dotty-compiler +run_tree_sitter "$SCALA_SCALA_DIR/src/library/" $SCALA_SCALA_LIBRARY_EXPECTED scala2-library +run_tree_sitter "$SCALA_SCALA_DIR/src/compiler/" $SCALA_SCALA_COMPILER_EXPECTED scala2-compiler +run_tree_sitter "$DOTTY_DIR/compiler/" $DOTTY_COMPILER_EXPECTED dotty-compiler -if (( $failed > 0 )); then +if (( failed > 0 )); then exit 1 fi From f35b1102e7c72de8306eeae7bbd22c4585d78846 Mon Sep 17 00:00:00 2001 From: Ondra Pelech Date: Thu, 25 May 2023 00:37:52 +0200 Subject: [PATCH 2/2] Add complexity check to smoke_test.sh --- script/smoke_test.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/script/smoke_test.sh b/script/smoke_test.sh index 66252b172f..f2c5496128 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -5,6 +5,7 @@ SCALA_SCALA_LIBRARY_EXPECTED=100 SCALA_SCALA_COMPILER_EXPECTED=84 DOTTY_COMPILER_EXPECTED=71 +SYNTAX_COMPLEXITY_CEILING=3000 if [ ! -d "$SCALA_SCALA_DIR" ]; then echo "\$SCALA_SCALA_DIR must be set" @@ -44,10 +45,39 @@ run_tree_sitter () { fi } +check_complexity () { + local expected=$1 + name="complexity" + cmd="npm exec -c 'tree-sitter generate --report-states-for-rule compilation_unit' 2>&1" + echo + echo "Checking syntax complexity: $cmd" + out=$( (eval "$cmd") || true) + + if [ ! -e "$PRODUCE_REPORTS" ]; then + local report_file="report-$name.txt" + echo "$out" > "report-$name.txt" + echo "Report written to $report_file" + fi + + top=$(echo "$out" | head -n 1 | sed 's/ \+/ /g') + top_definition=$(echo "$top" | cut -d' ' -f1) + actual=$(echo "$top" | cut -d' ' -f2) + echo "$top_definition $actual" + if (( $(echo "$actual < $expected" |bc -l) )); then + # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-creating-an-annotation-for-an-error + echo -e "::notice file=grammar.js,line=1::ok, complexity of definition ${top_definition}: ${actual}, lower than $expected" + else + echo -e "::error file=grammar.js,line=1::complexity for definition ${top_definition}: expected at most ${expected}, but got ${actual} instead" + failed=$((failed + 1)) + fi +} + run_tree_sitter "$SCALA_SCALA_DIR/src/library/" $SCALA_SCALA_LIBRARY_EXPECTED scala2-library run_tree_sitter "$SCALA_SCALA_DIR/src/compiler/" $SCALA_SCALA_COMPILER_EXPECTED scala2-compiler run_tree_sitter "$DOTTY_DIR/compiler/" $DOTTY_COMPILER_EXPECTED dotty-compiler +check_complexity $SYNTAX_COMPLEXITY_CEILING + if (( failed > 0 )); then exit 1 fi