Skip to content

DevHowToTest

wiztigers edited this page Apr 25, 2016 · 1 revision

Feel free to commit some unit tests about syntax recognition anytime (like this), but please follow the recommandations below.

Testing syntactic analysis

The following process allows to write correct unit tests:

  1. Write COBOL source code in one (or more) file(s), and put it in the directory TypeCobol.Test/Compiler/Parser/Samples or one of its subdirectories (excepted the Program subdirectory, see next section). Remember that you can test valid syntax as long as invalid syntax. Don't hesitate to comment the intention behind the code. You don't have to write a COBOL file that compiles, you can just write various statements.
  • If you are able to write an expected result file (see step 2) all by yourself, give to your sample file the .cbl extension and go to step 2.
  • If you want someone else to write the expected result file, DON'T give your file the .cbl extension. You can put your file in a specific directory (named for example TODO), but it's not mandatory as long as you don't use the .cbl file extension. What is mandatory however, is to be clear about wether the statements written in your sample test file should PASS or FAIL. For this, we suggest you simply give your file a clear extension, like .ok (if you wrote appropriate syntax), and .ko (if you wrote syntax errors). Then you can go to step 4.
  1. Write the expected result in one (or more) .txt file(s) put in the directory TypeCobol.Test/Compiler/Parser/ResultFiles or one of its subdirectories and go to step 3.
  2. Run all tests to be sure that your new test is a success and that you didn't broke any other test as a side effect.
  3. Commit. When you commit sample and/or result files for a specific COBOL syntax (or a group thereof), don't forget to reference the appropriate issue(s) by writing issue #<issue number> in your commit comment. Your commit comment will then appear directly in the issue, sparing you the hassle of writing the same thing twice, and allowing everyone better progress tracking.
  4. Optionally, comment your work in the corresponding issue.

You have some examples of language syntax test adding commit here, old style or here, new style.

Testing semantic analysis

The process is the same as writing syntactic analysis tests (see previous section), with the exception below.

  • COBOL source code is put in .pgm files, which are in turn put in the directory TypeCobol.Test/Compiler/Parser/Samples/Program.
  • The corresponding expected result for each xxx.pgm file is xxxPGM.txt file, which is put in the directory TypeCobol.Test/Compiler/Parser/ResultFiles/Program.

Testing code generation

Code generation has its own subproject of the TypeCobol hierarchy: Codegen. All unit tests of this project follow the same schema, which is as follows:

  • Given the root directory Codegen/test/resources, ...
  • and given a configuration file config found in root/config, ...
  • a test parses every file fin found in root/input, ...
  • then compares the code generated for fin with the contents of a file fout which has the same name as fin but is found in root/output.

So, if you want to write a functional test for a specific codegen feature, you have to write the files fin, fout and optionally config and put them in the appropriate folder.

Clone this wiki locally