Skip to content

Latest commit

 

History

History

cobol

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CI Ubuntu GnuCOBOL CobolCheck

COBOL

COBOL testing with cobol-check

Show me the code

Implementation

  1. Create a program HELLO-CONSOLE in HELLO-CONSOLE.CBL:
  • Declare an alpha-numeric parameter MSG
  • Program will just display MSG
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-CONSOLE.

DATA DIVISION.
LINKAGE SECTION.
01 MSG PIC A(20).

PROCEDURE DIVISION USING MSG.
    DISPLAY MSG.
  1. Create a program HELLO in HELLO.CBL:
  • Declare an alpha-numeric variable MSG
  • Create HELLO-MESSAGE paragraph that sets a value to MSG variable
  • Create HELLO paragraph calling:
    • HELLO-MESSAGE paragraph
    • HELLO-CONSOLE program
  • Create MAIN paragraph just calling the HELLO paragraph

💡 We use a paragraph for HELLO-MESSAGE and a program for HELLO-CONSOLE just to show two different options and how to mock them in the tests.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 MSG PIC A(20).

PROCEDURE DIVISION.

MAIN.
    PERFORM HELLO.
    STOP RUN.

HELLO.
    PERFORM HELLO-MESSAGE.
    CALL 'HELLO-CONSOLE' USING MSG.

HELLO-MESSAGE.
    MOVE 'HELLO WORLD!' TO MSG.

Test

Following A Brief Example, Mock a paragraph and Mock a CALL statement guides ...

In HELLO.cut file:

  1. Test HELLO-MESSAGE paragraph:
TestSuite "HELLO-MESSAGE"

TestCase "SHOULD RETURN HELLO WORLD"
  MOVE "" TO MSG
  PERFORM HELLO-MESSAGE
  Expect MSG = "HELLO WORLD!"
  1. Test HELLO paragraph mocking HELLO-MESSAGE and HELLO-CONSOLE:
TestSuite "HELLO"

TestCase "SHOULD DISPLAY HELLO MESSAGE"
  * 2.1 Mock HELLO-MESSAGE
  MOCK PARAGRAPH HELLO-MESSAGE
      MOVE "HELLO TEST!" TO MSG
  END-MOCK

  * 2.2 Mock HELLO-CONSOLE
  MOCK CALL 'HELLO-CONSOLE' USING MSG
      CONTINUE
  END-MOCK

  * 2.3 Execute the paragraph we want to test
  PERFORM HELLO

  * 2.4 Verify MSG has the expected value
  Expect MSG = "HELLO TEST!"
  * 2.5 Verify HELLO-MESSAGE has been called once
  VERIFY PARAGRAPH HELLO-MESSAGE HAPPENED ONCE
  * 2.6 Verify HELLO-CONSOLE has been called once
  VERIFY CALL 'HELLO-CONSOLE' USING MSG HAPPENED ONCE
  1. Test output should look like:
TESTSUITE:
HELLO-MESSAGE
     PASS:   1. SHOULD RETURN HELLO WORLD
TESTSUITE:
HELLO
     PASS:   2. SHOULD DISPLAY HELLO MESSAGE
     PASS:   3. VERIFY EXACT 1 ACCESS TO PARAGRAPH HELLO-MESSAGE
     PASS:   4. VERIFY EXACT 1 ACCESS TO CALL 'HELLO-CONSOLE'

  4 TEST CASES WERE EXECUTED
  4 PASSED
  0 FAILED
  0 CALLS NOT MOCKED
================================================

I have no idea how to unit test HELLO-CONSOLE program as it seems cobol-check does not support PROCEDURE DIVISION USING X section so I created this issue 🤞

Run this project using 🐳 docker

  • Execute ./docker-run.sh
  • Once inside the container:
    • Test with ./cobolcheck -p HELLO
    • Build HELLO-CONSOLE.so with cobc src/main/cobol/HELLO-CONSOLE.CBL
    • Build HELLO with cobc -x src/main/cobol/HELLO.CBL
    • Run with ./HELLO

Run this project locally

Pre-requisites

  • Java 8 required to run cobol-check 0.2.8
  • You can try to build GnuCOBOL from scratch or ...
  • Install any pre-built GnuCOBOL package:
    • on Ubuntu sudo apt-get update && sudo apt-get install -y gnucobol
    • on Fedora sudo dnf -y install gnucobol
    • ...

Run locally

  • Test with ./cobolcheck -p HELLO
  • Build HELLO-CONSOLE.so with cobc src/main/cobol/HELLO-CONSOLE.CBL
  • Build HELLO with cobc -x src/main/cobol/HELLO.CBL
  • Run with ./HELLO

Create project from scratch

  • Get cobol-check and unzip it locally
  • If needed customize config.properties
  • Remove samples and place your own files under src/main/cobol and src/test/cobol