You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

1. Example project structure

.
├── fruit
│   └── fruit.f90
├── mod
├── src
│   └── <your_module>.f90
└── test 
    ├── <your_module>_test.f90
    └── <your_driver_name>.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
  • <your_driver_name>.f90 - file with test driving program. Filename could be anything, just remember it so you can use it while compiling and running project.

1.1.  Setup fruit

Download fruit.f90 https://github.com/mortele/FRUIT/blob/master/src/fruit.f90 and put it into ./fruit directory.

1.2.  Create test module

Create file named <your_module>_test.f90 and put it into ./test directory.

Your module may looks like:

!filename: calculator_test.f90

module calculator_test
use fruit

contains
subroutine test_calculator
	use calculator
	integer :: result

	!test add subroutine
	call add (2,2,result)
	call assert_equals(4,result)

end subroutine test_calculator
end module calculator_test

Create file named <your_driver_name>.f90 and put it into ./test directory.

test driver is actual program that runs tests.

!filename: 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

2.  Create module that will be tested

Create file named <your_module>.f90 and put it into ./scr directory.

!filename: 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

3.  Run tests

This bash code will compile all source codes and run tests described in ./test/calculator_test.f90 file.

#filename: build_run_and_clean.sh
#create mod directory if not exists
mkdir -p mod

#compile source files
# -J specifies where .mod files will be generated, and add this path in compiler search location
gfortran -c ./src/*.f90 -J ./mod
gfortran -c ./fruit/*.f90 -J ./mod
gfortran -c ./test/*.f90 -J ./mod

# create executable file
gfortran -o fruit_driver *.o

#run tests
./fruit_driver

#clean
find . -name "*.o" -type f -delete
find . -name "*.mod" -type f -delete

4. Example output

4.1.  Output created with project described above

4.2. Output created with different project

NOTE: Fruits prints "." for every assert passed and "F" for every assert failed, not for every procedure call.


  • No labels