Fruit could be use along with Ruby pre-processor as part of the simple standalone FORTRAN approach. The advantage of using the pre-processor is it removes the need to maintain the basket and driver files and keep them up to date.
1. Example project structure
. ├── mod ├── src │ └── <your_module>.f90 ├── test │ ├── <your_module>_test.f90 │ ├── fruit_generator.rb | └── fruit.f90 └── rake_base.rb
2. Install requirements
2.1. FRUIT source code
cd <project_dir>/test wget https://github.com/mortele/FRUIT/blob/master/src/fruit.f90
2.2. Ruby
sudo apt install ruby-full ruby --version
2.3. Rake
sudo gem install rake
2.4. Fruit_processor_gem
2.4.1. Download fruit_processog_gem direcotry from FRUIT repository
This could be downloaded anywhere, just to install additional ruby package.
https://github.com/mortele/FRUIT/tree/master/fruit_processor_gem
NOTE: you will need to download whole repository, or download one folder from github online editor.
To do this:
- Open in your browser
https://github.dev/mortele/FRUIT/tree/master/fruit_processor_gem
- Login if asked
- Right click fruit_processor_gem directory on project explorer panel and click download.
2.4.2. Install fruit_processog_gem
cd ./fruit_processor_gem sudo rake install
2.5. rake_base.rb
You will need to download rake_base.rb file from FRUIT repository in order to run fruit_generator script
cd <project_dir> wget https://raw.githubusercontent.com/mortele/FRUIT/master/rake_base.rb
3. Create project files
!file <project_directory>/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
!file <project_directory>/test/calculator_test.f90 module calculator_test use fruit contains subroutine setup print *, "setup subroutine ran" end subroutine setup subroutine teardown print *, "teardown subroutine ran" 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
NOTE: in order to autogenerate test_driver and test_bucket files, you need to follow naming convention:
- files containing tests must be named: *_test.f90
- test module must be named: *_test
- test subroutines must be named: test_*
4. Create driving files
4.1. fruit_generator.rb
#file <project_dir>/test/fruit_generator.rb require 'rubygems' require 'fruit_processor' load "../rake_base.rb" $build_dir = "" $goal = "fruit_driver_dummy" fp = FruitProcessor.new fp.pre_process
5. Configuration
You may need to change your compiler from gfortran to other. To do this modify below lines in rake_base.rb file:
$compiler = 'gfortran' $option = "-Wall -Wextra -pedantic -fbounds-check " + "-Wuninitialized -O -g -Wno-unused-parameter -cpp"