If the project that is being ported contains a test target or any form of automated testing or test scripts, the first step will again be to run the traditional test step and record the commands used. For the Vim project, the place to start is src/testdir/Makefile. It will probably make sense to define tests on the CMake side close to src/testdir/Makefile and the test scripts, and we will choose to define tests in src/testdir/CMakeLists.txt. To process such a file, we must reference it in src/CMakeLists.txt:
add_subdirectory(testdir)
We should also enable the test target in the top-level CMakeLists.txt, right before processing src/CMakeLists.txt:
# enable the test target
enable_testing()
# process src/CMakeLists.txt in its own scope
add_subdirectory(src)
So far, the test target is empty before we populate src/testdir/CMakeLists.txt with add_test directives. The minimum to specify in add_test is a test name and a command to run. The command can be any script written in any language. The essential part for CMake is that the script returns zero if the test is successful and non-zero if the test fails. For more details, we refer the reader to Chapter 4, Creating and Running Tests. In the case of Vim, we will need a bit more to accommodate multi-step tests, which we will discuss in the next section.