@mk-mxp, @axtens
I wrote up a brief description on COBOL CHECK. Should we put it in the Tests page of the COBOL track, it would look like what you see below. Please let me know how you feel about this revision.
Once the revision is done, I can revise the test runner, so that it rejects incomplete tests with an error message pointing to the Tests page.
=================================================
Tests
The tests in the COBOL track use a software called COBOL CHECK created by Dave Nicolette and later improved in collaboration with the Open Mainframe Project. While you can find much detailed information on COBOL CHECK by visiting its GitHub page and following the links provided there, we here only briefly describe how it works to facilitate your maneuver through the exercises. If you are already familier with COBOL CHECK, you can skip to Running the Tests
COBOL CHECK
COBOL CHECK was designed for conveniently testing individual paragraphs in the procedure division. To attain this goal, COBOL CHECK reads a target COBOL program and add several lines of code to it for providing test data, executing paragraphs and checking the results the paragraphs generate.
For example, suppose that you solve an exercise in which you write a paragraph ADD-TWO-NUMBERS that calculates the sum of two numbers. Besides the COBOL program containing the ADD-TWO-NUMBERS paragraph, COBOL CHECK requires a file of test descriptions written in a COBOL-like domain specific language. For example:
TESTSUITE "Add Two Numbers"
TestCase "adding zeros gives zero."
MOVE 0 TO WS-NUMBER-1
MOVE 0 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
EXPECT WS-SUM = 0
TestCase "adding 3 to 5 yields 8."
MOVE 3 TO WS-NUMBER-1
MOVE 5 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
EXPECT WS-SUM = 8
TestCase "adding -8 to 5 yields -3."
MOVE -8 TO WS-NUMBER-1
MOVE 5 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
EXPECT WS-SUM = -3
This file shows:
- Each test passes numbers to data items
XE-NUMBER-1 and XE-NUMBER-2 and expects the result in another data item XE-SUM. So, the three data items must be present in the Data Division of the program to be tested.
- The
ADD-TWO-NUMBERS paragraph has to save the sum it calculates in WS-SUM.
Let’s prepare a solution
IDENTIFICATION DIVISION.
PROGRAM-ID. ADD-TWO-NUMBERS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUMBER-1 PIC S9(4).
01 WS-NUMBER-2 PIC S9(4).
01 WS-SUM PIC S9(4) VALUE 0.
PROCEDURE DIVISION.
ADD-TWO-NUMBERS.
ADD WS-NUMBER-1 TO WS-SUM.
ADD WS-NUMBER-2 TO WS-SUM.
From the test description file and this COBOL program file, COBOL CHECK generates a new COBOL program. Because the actual generated program is pretty complicated and lengthy, a much simplified version is presented here.
IDENTIFICATION DIVISION.
PROGRAM-ID. ADD-TWO-NUMBERS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUMBER-1 PIC S9(4).
01 WS-NUMBER-2 PIC S9(4).
01 WS-SUM PIC S9(4) VALUE 0.
01 CUT-TEST-COUNT PIC 9(3) VALUE 0.
01 CUT-PASS-COUNT PIC 9(3) VALUE 0.
01 CUT-FAIL-COUNT PIC 9(3) VALUE 0.
PROCEDURE DIVISION.
TEST-1.
MOVE 0 TO WS-NUMBER-1
MOVE 0 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
ADD 1 TO CUT-TEST-COUNT
IF WS-SUM = 0
ADD 1 TO CUT-PASS-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' PASSED'
ELSE
ADD 1 TO CUT-FAIL-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' FAILED'
END-IF.
TEST-2.
MOVE 3 TO WS-NUMBER-1
MOVE 5 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
ADD 1 TO CUT-TEST-COUNT
IF WS-SUM = 8
ADD 1 TO CUT-PASS-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' PASSED'
ELSE
ADD 1 TO CUT-FAIL-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' FAILED'
END-IF.
TEST-3.
MOVE -8 TO WS-NUMBER-1
MOVE 5 TO WS-NUMBER-2
PERFORM ADD-TWO-NUMBERS
ADD 1 TO CUT-TEST-COUNT
IF WS-SUM = -3
ADD 1 TO CUT-PASS-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' PASSED'
ELSE
ADD 1 TO CUT-FAIL-COUNT
DISPLAY 'TEST ' CUT-TEST-COUNT ' FAILED'
END-IF.
TEST-SUMMARY.
DISPLAY CUT-TEST-COUNT ' TEST CASES WERE EXECUTED.'
DISPLAY CUT-PASS-COUNT ' PASSED'
DISPLAY CUT-FAIL-COUNT ' FAILED'.
* Your code follows.
ADD-TWO-NUMBERS.
ADD WS-NUMBER-1 TO WS-SUM
ADD WS-NUMBER-2 TO WS-SUM.
This code demonstrates:
- Three tests are performed in execution of a single program. If a data item is modified in the first test, for example, the second test inherits the modified value. You need to be careful about initialization through VALUE clause in the data division. (In the current example, the
ADD-TWO-NUMBERS paragraph fails in the third test, WS-SUM being equal to 8 when it is executed after the second test.)
- MOST IMPORTANTLY, THE
STOP RUN AND GOBACK STATEMENTS CANNOT BE USED IN THE CODE TO BE TESTED, because they prematually terminates the entire testing program.
Running the Tests
Unlike the underlying mechanism discussed above, the actual process of running tests is simple.
Choose your current OS:
Windows
-
Open a Command Prompt.
-
Get the first exercise:
C:\Users\USERNAME> exercism download --exercise hello-world --track cobol
-
Change directory into the exercise folder:
C:\Users\USERNAME> cd C:\Users\USERNAME\exercism\cobol\hello-world
-
Run the tests:
C:\Users\USERNAME\exercism\cobol\hello-world> test.ps1
(Don’t worry if the tests fail when you first run them, this is how you begin each exercise.)
-
Solve the exercise.
Read through the instructions.md and see how to solve the exercise (view on GitHub).
Good luck, have fun and welcome to the COBOL track!
macOS
-
Open a Terminal window.
-
Get the first exercise:
$ exercism download --exercise hello-world --track cobol
-
Change directory into the exercise folder:
$ cd /Users/USERNAME/exercism/cobol/hello-world
-
Run the tests:
$ bash test.sh
(Don’t worry if the tests fail when you first run them, this is how you begin each exercise.)
Hint: If you get a message that basename is missing, you can use brew to install coreutils. (brew install coreutils)
-
Solve the exercise.
Read through the instructions.md and see how to solve the exercise (view on GitHub).
Good luck, have fun and welcome to the COBOL track!
Linux
-
Open a Terminal window.
-
Get the first exercise:
$ exercism download --exercise hello-world --track cobol
-
Change directory into the exercise folder:
$ cd /home/USERNAME/exercism/cobol/hello-world
-
Run the tests:
$ bash test.sh
(Don’t worry if the tests fail when you first run them, this is how you begin each exercise.)
-
Solve the exercise.
Read through the instructions.md and see how to solve the exercise (view on GitHub).
Good luck, have fun and welcome to the COBOL track!