Support #6861
tests for valid and invalid 4GL syntax (parsing)
0%
Related issues
History
#1 Updated by Marian Edu over 3 years ago
Not sure what the plans are for this one, I would imagine really JUnit tests are to be created here for conversion so no 4GL/ABLUnit tests only sample 4GL code that will be used as conversion input... but please correct me if I'm wrong.
#2 Updated by Greg Shah over 3 years ago
- Related to Support #6860: lexer tests added
#3 Updated by Greg Shah over 3 years ago
I think your idea is the correct approach.
#4 Updated by Greg Shah over 1 year ago
- Project changed from Conversion Tools to Testing
- Subject changed from valid and invalid 4GL syntax (parsing) to tests for valid and invalid 4GL syntax (parsing)
After considering this further, I think we need 2 approaches:
1. For valid 4GL syntax, I think we make sure that we enhance our ABLUnit tests to include everything we want to test in the parser. I don't think there is much value in having lots of parsing tests that wouldn't actually work to test the runtime behavior. Doing that might save some time on the parsing test development but it would result is a huge amount of duplication. We already need to write tests that work for all the various functional areas. They should just be used for both purposes.
2. For invalid 4GL syntax, the ABLUnit approach does not work. We will need to come up with a kind of harness or driver for running the ConversionDriver directly and checking against expected parsing/syntax failures.
#5 Updated by Greg Shah over 1 year ago
- Related to Feature #1757: update ANTLR to latest version added
#6 Updated by Greg Shah over 1 year ago
- Related to Feature #3882: changes to allow the front-end to be used for 4GL syntax checking added
#7 Updated by Greg Shah over 1 year ago
- Related to Support #6859: preprocessor tests added
#8 Updated by Greg Shah 6 months ago
Documentation will be in Parser Testcases.
#9 Updated by Paula Păstrăguș 7 days ago
Following #10804-358, here is the proposal for parser tests (#6861). The approach of Lexer Testcases and Preprocessor Testcases works for the parser almost unchanged. The difference is that for the parser we compare the AST, not a token stream or a listing.
Take the fix from rev 16902 (an image phrase without FILE). Its test would look like this.
1. The test file is a plain 4GL source, in valid/ because OE compiles it (code that OE rejects goes in invalid/):
tests/conversion/parser/4gl_testcases/image_phrase/valid/image_size_without_file.p
define button b1 image-up file "a.bmp" image-size 16 by 16 from x 0 y 0 image-down image-size-p 16 by 16 from x 0 y 0 image-insensitive image-size-c 2 by 1. define image im image-size 16 by 16 from x 0 y 0.
2. On OE, a driver.p like the lexer's compiles the file and prints [no] (no errors) or [yes]. Here the OE test expects [no], which confirms that the test itself is valid 4GL. Error numbers and texts are not compared.
ParserTestDriver parses the file and writes two files:
.errwithNO ERRORS, or the position of the first syntax error, orABORTEDwhen the parser crashed (as it did here before the fix, with a NullPointerException)..astwith the tree, one node per line with its text, token type, position and annotations. This shows that IMAGE-SIZE and FROM are where they belong.
4. The harness compares both files with the committed baselines. If image_phrase breaks again, the test fails.
Since OE cannot give us an AST, the .ast baseline comes from FWD and is reviewed by hand, as in the lexer suite. For the #10804 fixes we can also check it against the trunk AST from the ANTLR2 parser.
For each fix, the testcases commit holds the .p, its baselines and the harness XML, which a script generates and adds to the test plan. The Parser Testcases page gets a status row in the same step.
The driver. ParserTestDriver already exists in 7178a (rev 16671, #7178), and the run-parse target in tests/conversion/parser/ already calls it. It is not in trunk and it is written for ANTLR2. I would bring it into 10804b, port it to ANTLR4 and add the AST output, the position of the first error, and the check that the parse reached the end of the file. The #7178 tests would keep working as they do now.
Greg, does this approach work for you, and is it fine to bring ParserTestDriver into 10804b ahead of #7178..?
#10 Updated by Greg Shah 7 days ago
- topics 4GL Parser added
Yes, this works. Good plan.
A few notes:
- It may be required to add some level of "fuzzing" to the AST comparison. For example, IDs are not stable so we don't want to depend on checking the IDs. Our focus should be on the structure and meaning of the tree.
- The file paths for the tests should be organized by the parser rule. This let's us understand the matching of test to actual grammar.
- The status table in the documentation should also have a row per rule.
#11 Updated by Paula Păstrăguș 6 days ago
Following #6861-10, I committed the parser rule tests to testcases (rev 1997), in tests/conversion/parser/:
- 93 tests (69 valid, 24 invalid) for the fixes made on 10804b, organized by parser rule:
rules/<rule>/{valid,invalid}/<name>.p. They cover 66 rules ofProgressParser.g4. - Baselines in
baselines/rules/: the parse outcome (.err) for every test and the AST (.tree) for the valid ones. - The AST comparison leaves out the node IDs, the random
fdefid/frefidUUIDs andtempidx, whose value depends on the order in which symbols are registered. The structure, token types, positions and the other annotations are compared. rules_test_plan.xmlruns the rule tests in FWD,oe_test_plan.xmlchecks on OE that valid tests compile and invalid ones do not. Both plans are generated byutil/generate_rule_tests.py.
All 93 pass in FWD, and OE 11.6 agrees with all 93. Compared with trunk (ANTLR2), 83 give the same result; the other 10 are expected (4 intended behavior changes, 6 with only a different error column).
Next: ParserTestDriver into 10804b, and the per-rule status table on Parser Testcases.
#12 Updated by Paula Păstrăguș 6 days ago
In order to run the suite, 10804b branch is needed (rev 16907).
cd ~/projects/testcases/tests/conversion/parser # replace with your own path in case you don't have the testcases project into ~/projects
ANT_ARGS="-Dfwd.lib.home=/home/pmp/gcd/10804b/build/lib" java -jar ~/projects/harness/build/lib/harness.jar rules_test_plan.xml # run the hole suite
# After that the results should be into ~/projects/testcases/tests/conversion/parser/fwd_results/{date}/index.html file