Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
.
├── fruit
│   └── fruit.f90
├── mod
├── src
│   └── main
│       └── <your_module>.f90
└── test 
    ├── <your_module>_test.f90
    └── fruit_driver.f90
  • fruit.f90 - fruit source code.
  • mod - directory used to store .mod files.
  • <your_module>.f90 - your actual module.
  • <your_module>_test.f90 - file with unit tests for your module.
  • fruit_driver.f90 - file with test driving program. You can change this file name, but remember to modify Makefile, so it could find it.

 Install requirements

...

Load gfortran

Code Block
module load itm-gcc/7.3.0

Setup fruit library

Download fruit.f90 https://github.com/mortele/FRUIT/blob/master/src/fruit.f90 into  .<project_dir>/fruit directory.

...

Code Block
!file: <project_dir>/test/fruit_driver.f90

program fruit_driver
	use fruit
	use calculator_test
	call init_fruit

	!if you want to generate XML result
	!call init_fruit_xml

	call test_calculator

	!call fruit_summary_xml
	call fruit_summary
end program fruit_driver

 Create Create your module

Create file named <your_module>.f90 and put it into ./src directory. This file will be tested by module created in step 3.1.

Code Block
!file: <project_dir>/src/calculator.f90

module calculator
implicit none
contains
	subroutine add(a,b,output)
		integer, intent (in) :: a,b
		integer, intent (out) :: output
		output=a+b
	end subroutine add

end module calculator

 Create your main program

Create file named main.f90 and put it into ./src directory. We won't use this file, but it is needed to compile and build calculator executable.

Code Block
!file: <project_dir>/src/main.f90
program main
use calculator

...


        integer :: result
        call add(2,2,result)
end program main

Finalization

Create mod directory

This directory will contains built modules. Unlikely GNU make will not create it itself.

Code Block
cd <project_dir>
mkdir mod

Create Makefile

It is a build instruction that makes compiling your project easy. 

...

Code Block
!file: <project_dir>/test/fruit_basket.f90

module fruit_basket
  use fruit
contains
  subroutine calculator_test_all_tests
    use calculator_test

    call setup
    write (*, *) "  ..running test: test_calculator"
    call set_unit_name('test_calculator')
    call run_test_case (test_calculator, "test_calculator")
    if (.not. is_case_passed()) then
      write(*,*) 
      write(*,*) '  Un-satisfied spec:'
      write(*,*) '  -- calculator'
      write(*,*) 
      call case_failed_xml("test_calculator", &
      & "calculator_test")
    else
      call case_passed_xml("test_calculator", &
      & "calculator_test")
    end if
    call teardown

  end subroutine calculator_test_all_tests

  subroutine fruit_basketbasket1
    call calculator_test_all_tests
  end subroutine fruit_basketbasket1

end module fruit_basket


Pay attention to code lines presented below. They come from code above. You can use them to call tests from desired test module.

...

Code Block
!file: <project_dir>/test/fruit_driver.f90

program fruit_driver
	use fruit
	use fruit_basket
	call init_fruit

	call fruit_basketbasket1

	call fruit_summary
end program fruit_driver

...

 Output created with project described above

Image RemovedImage Added

Output created with different project

...