Versions Compared

Key

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

...

  • 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.

 Install requirements

setup fruit library

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

Create project files

...

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

module calculator_test
use fruit

contains
subroutine test_calculator
	!use <your_module_name>
	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_module>.f90 and put it into ./scr src directory. This file will be tested by module created in step 3.1.

...

First you need to define setup and teardown routinessubroutines.

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

module calculator_test
use fruit

contains
subroutine setup
	!...
end  subroutine setup
	
subroutine teardown
	!...
end  subroutine teardown

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

...

Now test subroutines calls are moved from test_driver to test_basket. You need to import test_basket module and call its it's main subroutine. In this case it is "fruit_basket" subroutine.

...

This bash code will compile all source codes and run tests described in ./test/calculator_test.f90 file. Just put it into .sh file and run.

Code Block
#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

...