neopragma / cobol-unit-test

Unit testing framework and sample code for batch Cobol programs.
GNU General Public License v3.0
117 stars 36 forks source link

FILE STATUS required when accessing file #87

Open siegling opened 6 years ago

siegling commented 6 years ago

To test a Cobol file, in which external files are accessed, a file status has to be specified for at least one of the in the file-control specified files. If no file status is specified, the precompiler fails with the following error: 003-E ORIGINAL SOURCE FILE SRCPRG STATUS 46 ON READ Steps to reproduce:

Use the following cbl, test and config:

EXAMPLE.CBL

   IDENTIFICATION DIVISION.
   program-id. EXAMPLE.
   ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
       SELECT testFile ASSIGN TO "DD_TESTFILE"
       ORGANIZATION IS LINE SEQUENTIAL
       .

       SELECT testFile1 ASSIGN TO "DD_TESTFILE"
       ORGANIZATION IS LINE SEQUENTIAL
       .

       SELECT testFile2 ASSIGN TO "DD_TESTFILE"
       ORGANIZATION IS LINE SEQUENTIAL
       .

       SELECT testFile3 ASSIGN TO "DD_TESTFILE"
       ORGANIZATION IS LINE SEQUENTIAL
       .

       SELECT testFile4 ASSIGN TO "DD_TESTFILE"
       ORGANIZATION IS LINE SEQUENTIAL
       .

   DATA DIVISION.

   FILE SECTION.

   FD testFile.
   01 test-line                 PIC X(80).

   FD testFile1.
   01 test-line1                 PIC X(80).

   FD testFile2.
   01 test-line2                 PIC X(80).

   FD testFile3.
   01 test-line3                 PIC X(80).

   FD testFile4.
   01 test-line4                 PIC X(80).

   WORKING-STORAGE SECTION.

   77 FS PIC XX.

   01  simple-arithmetics.
       05  first-operand   PIC 9(3).
       05  second-operand  PIC 9(3).
       05  arith-result    PIC 9(6)V9.

   PROCEDURE DIVISION.
   main-procedure.
       DISPLAY "HELLO WORLD"
       PERFORM calculate-proc

       GOBACK
       .
   output-proc.
       OPEN INPUT testFile
       READ testFile
       DISPLAY test-line
       CLOSE testFile

       OPEN INPUT testFile1
       READ testFile1
       DISPLAY test-line1
       CLOSE testFile1

       OPEN INPUT testFile2
       READ testFile2
       DISPLAY test-line2
       CLOSE testFile2

       OPEN INPUT testFile3
       READ testFile3
       DISPLAY test-line3
       CLOSE testFile3

       OPEN INPUT testFile4
       READ testFile4
       DISPLAY test-line4
       CLOSE testFile4
       .

   calculate-proc.
       COMPUTE arith-result = first-operand + second-operand
       .

EXAMPLET:

       TESTSUITE 'test'

       TESTCASE 'case'
       MOVE 4 TO first-operand
       MOVE 12 TO second-operand
       PERFORM calculate-proc
       EXPECT arith-result TO BE NUMERIC 16.0

EXAMPLEC:

ZUTZCWS
EXSAMPLET

Add FILE STATUS IS FS to one of the SELECT-Statment (choose any) and the test runs through.

mmitch commented 5 years ago

FILE STATUS should be optional, bit it seems fail to match the period ending the SELECT statement. I have just run into the same issue.

Adding MOVE 7 TO KEYWORD-OFFSET just before the END-PERFORM in 2800-PROCESS-SELECT seems to fix this.

(@FrankR85: this seems to be our problem with TODOLISTE.CBL combined with the fact that the SELECT has to start at column 8 while ours starts at 10)