Skip to content

Commit

Permalink
Merge pull request #231 from sideeffffect/smoketest-complexity
Browse files Browse the repository at this point in the history
Add complexity check to smoke_test.sh
  • Loading branch information
eed3si9n authored May 24, 2023
2 parents c4f0634 + f35b110 commit 2a5b9ba
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions script/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,7 +26,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"
Expand All @@ -34,7 +35,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%"
Expand All @@ -44,10 +45,39 @@ 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
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
if (( failed > 0 )); then
exit 1
fi

0 comments on commit 2a5b9ba

Please sign in to comment.