FRUITPy in 3 minutes - acroucher/FRUITPy GitHub Wiki

Here is an example of using FRUITPy to run the original "FRUIT in 3 minutes" example (located in the "in_3_minutes" directory of your FRUIT install).

A FRUITPy Python script to run the example is:

from FRUIT import *

test_modules = ['calculator_test.f90']
driver = "calculator_test_driver.f90"

suite = test_suite(test_modules)
suite.build_run(driver)
suite.summary()

A makefile to build the test driver program is given below. This example makefile uses gfortran on Linux and assumes FRUIT has been compiled into a shared library in the $(HOME)/lib directory, with FRUIT module files in $(HOME)/include:

FC = gfortran
LIBS = -L$(HOME)/lib -lfruit
INCLS = -I$(HOME)/include
FCFLAGS = -O3 -Wall -ffree-line-length-none

EXE = calculator_test_driver

$(EXE): calculator.o calculator_test.o

%: %.o
	$(FC) $(FCFLAGS) $(LIBS) -o $@ $^
%.o: %.f90
	$(FC) $(FCFLAGS) $(INCLS) -c $<

.PHONY: clean
clean:
	rm -f *.o *.mod $(EXE)

(Note that the -ffree-line-length-none compiler option is needed here because the test subroutine has a very long name ('test_calculator_should_produce_4_when_2_and_2_are_inputs'), which makes one of the lines in the driver program longer than the default maximum 132 characters for free format source in gfortran.)

Running the FRUITPy script produces the following output:

All tests passed.
Hit rate:
  asserts:  1 / 1 (100%)
  cases  :  1 / 1 (100%)

If we edit calculator_test.f90, and change line 15 so that the test asserts that 2 + 2 = 3:

call assert_equals (3, result)

then the FRUITPy output becomes:

Some tests failed:

[test_calculator_should_produce_4_when_2_and_2_are_inputs]: Expected [3], Got [4]

Hit rate:
  asserts:  0 / 1 (  0%)
  cases  :  0 / 1 (  0%)
```