Introduce COBOL Sections in the transformed code
Closed this issue · 5 comments
We use COBOL SECTIONs in our source COBOL codes.
In principle, when COBOL SECTIONSs are present, the Procedure Division should start with a SECTION.
The COBOL code introduced by the Cobol Check tool does not use SECTIONs.
However, it would be easy to declare a SECTION at the start of the insert code, and a SECTION at the end just before the original code.
For example:
DIVISION PROCEDURE.
UT-CHECK SECTION.
PERFORM UT-INITIALIZE
....
UT-END.
EXIT.
UT-PROBLEM SECTION.
original code
This will also have implications for the Generator. It needs logic added to recognize Section headers in the source file. Note the word "Section" may appear after more than one blank space. I think this work should be included with this issue, as the functionality is closely related.
It is not necessary to know whether or not the original source code contains sections and to adapt to them.
All it takes is for the injected test code to start with a section statement and end with a section statement.
Yes, that's technically true. We also have a request from a company that uses the proof-of-concept project on which Cobol Check is based, and their production code uses Sections. They want to be able to mock Sections as well as Paragraphs, so these changes would be needed to enable that functionality. So I think it's a good idea to go ahead and make the change in the Generator as well. We're planning to introduce mock support in the next release (0.2.0) so this is a good time.
We haven't implemented Cobol Check yet, but this is something we need to investigate as we move from traditional development to DevOps development.
So I find it hard to understand the difficulty of referencing Sections rather than Paragraphs in test cases.
From what I understand, the test case execution routines call the code to be tested by PERFORM (which assumes that the code is structured in Paragraphs, or Sections, with no GO TO leaving the Paragraph or Section, and therefore that it is not a linear code).
Syntaxically, a PERFORM Paragraph and a PERFORM Section are identical at the COBOL language level. The only difference is that a PERFORM section will chain the execution of all the Paragraphs in the Section.
There would only be a problem if the same Paragraph name appeared in more than one Section, and had to be called by a test case, requiring an expression of the form "PERFORM Paragraph IN | OF Section" to be used. But in this case "Paragraph IN | OF Section" is only a character string, the particularity of which is to contain spaces.
What could be useful would be to introduce the call to several Paragraphs or Section, so a call of the form "PERFORM entry-label THRU exit-label".
This is something we do, with GO TOs or EXIT PARAPGRAPH / EXIT SECTION between the entry-label and the exit-label, (what I name "early exit").
Sample code:
PERFORM F10-100-RU THRU F10-100-RU-FN.
[...]
*--- Lecture ressource RU avec rupture ---------------------------
F10-100-RU.
MOVE RU-DE TO RU-PE
MOVE NRD TO NRP
IF RU-FI = '1'
MOVE '1' TO RU-FT
EXIT PARAGRAPH
END-IF
MOVE RU00 TO 1-RU00
ADD 1 TO 5-RU00-CPTENR
READ RU-FICHIER
AT END
MOVE '1' TO RU-FI
END-READ
.
F10-100-RU-FN.
EXIT PARAGRAPH.
Yes, you are correct about all of this. It's just a question of doing the work to support the variations.