0

我有一个使用水果进行测试的项目(fortran 代码)。这是我的代码。

计算器.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

还有我的测试calculator_test.f90

module calculator_test
   use fruit
   contains
   subroutine test_5_2_2
      use calculator, only: add
      integer :: result
      call add(2,2,result)
      call assertEquals(4,result)
   end subroutine test_5_2_2

   subroutine test_5_2_3
      use calculator, only: add
      integer :: result
      call add(2,3,result)
      call assertEquals(5,result)
   end subroutine test_5_2_3
end module

现在我想使用 Cmake 来构建和运行我的测试(由 jenkins 触发),所以我的问题是:我需要更改测试还是可以只运行我通过 cmake 编写的测试,如果又怎样?我在网上搜索了很多,但所有使用 cmake 的测试似乎都是用 c++ 完成的,然后使用可执行的 testfiles 文件。

谢谢!-明德

4

1 回答 1

1

您可以按原样运行您编写的测试,您只需要告诉 CMake 如何运行它们。这就是COMMAND论证的ADD_TEST目的。

ENABLE_TESTING()
ADD_TEST(NAME "YourTest" 
    WORKING_DIRECTORY ${TEST_DIRECTORY}
    COMMAND ${TEST_DIRECTORY}/test_dim)

通常,您会看到类似上述示例的示例,其中命令是可执行文件(如您在 c++ 示例中所见)。但不一定是这样。例如,我正在通过 CMake 运行 python 测试,我添加测试如下:

ADD_TEST(NAME PythonTests 
    WORKING_DIRECTORY ${TEST_DIRECTORY}
    COMMAND ${PYTHON_EXECUTABLE} setup.py test

因此,要运行您的 Fruit 测试,您将调用为您创建 Fruit 测试运行器的命令(我相信这是一个rake命令......我将在下面假设这是正确的,但您应该替换您实际调用的任何内容命令行来运行你的测试):

ADD_TEST(NAME FruitTests 
    WORKING_DIRECTORY ${TEST_DIRECTORY}
    COMMAND rake test) # Or whatever the command is.

当您make test在命令行上运行时,它应该告诉您“FruitTests”是失败还是成功。

注意 一点 CMake 是通过程序的退出代码来决定测试的成败。默认情况下,Fortran 程序没有退出代码(或者如果有,则始终为 0)。当我使用 Fruit 和 CMake 进行 Fortran 测试时,我自己编写测试运行程序并使用call exit(exit_code)内置子例程来确保将退出代码返回给 CMake。我不确定 Fruit 的自动测试运行程序创建者是否这样做;您必须自己验证这一点。

于 2013-07-12T06:13:17.313 回答