Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] Add testing for grammar ambiguity. #4276

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest]
test: [ useless-parens, format ]
test: [ useless-parens, format, ambiguity ]
steps:
- name: Info
shell: bash
Expand Down
49 changes: 49 additions & 0 deletions _scripts/templates/CSharp/st.test-ambiguity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated from trgen <version>

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# Get a list of test files from the test directory. Do not include any
# .errors or .tree files. Pay close attention to remove only file names
# that end with the suffix .errors or .tree.
files2=`dotnet trglob -- '../<example_files_unix>' | grep -v '.errors$' | grep -v '.tree$'`
files=()
for f in $files2
do
if [ -d "$f" ]; then continue; fi
dotnet triconv -- -f utf-8 $f > /dev/null 2>&1
if [ "$?" = "0" ]
then
files+=( $f )
fi
done

# People often specify a test file directory, but sometimes no
# tests are provided. Git won't check in an empty directory.
# Test if there are no test files.
if [ ${#files[@]} -eq 0 ]
then
echo "No test cases provided."
exit 0
fi

# Parse all input files.
<if(individual_parsing)>
# Individual parsing: NOT SUPPORTED!
<else>
# Group parsing.
echo "${files[*]}" | dotnet trwdog -- dotnet trperf -- -x -c ar | grep -v '^0' | awk '{print $2}' | sort -u
status=$?
<endif>

# trwdog returns 255 if it cannot spawn the process. This could happen
# if the environment for running the program does not exist, or the
# program did not build.
if [ "$status" = "255" ]
then
echo "Test failed."
exit 1
fi

rm -f $old/updated.txt $old/new_errors2.txt $old/new_errors.txt
exit 0
18 changes: 17 additions & 1 deletion _scripts/test-static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fi

if [ ${#targets[@]} -eq 0 ]
then
targets=( useless-parens format )
targets=( useless-parens format ambiguity )
fi

echo grammars = ${grammars[@]}
Expand Down Expand Up @@ -376,6 +376,22 @@ do
fi
fi

if [ "$target" == "ambiguity" ]
then
dotnet trgen -- -t CSharp --template-sources-directory "$full_path_templates" --antlr-tool-path $antlr4jar
if [ $? -ne 0 ]
then
echo "::warning file=$testname,line=0,col=0,endColumn=0::Cannot test ambiguity, non-zero return from trgen."
elif [ ! -d Generated-CSharp ]
then
echo "::warning file=$testname,line=0,col=0,endColumn=0::Cannot test ambiguity, no Generated-CSharp directory."
else
cd Generated-CSharp
bash build.sh
bash test-ambiguity.sh
fi
fi

popd > /dev/null
done

Expand Down
Loading