Ver código fonte

ENH: add a test for a target name with the same name as the output of a custom command

Bill Hoffman 19 anos atrás
pai
commit
31a576abe6

+ 12 - 0
Source/CMakeLists.txt

@@ -390,6 +390,18 @@ IF(BUILD_TESTING)
     --build-project TestTar
     --test-command TestTarExec)
 
+  ADD_TEST(TargetName ${CMAKE_CTEST_COMMAND}
+    --build-and-test
+    "${CMake_SOURCE_DIR}/Tests/TargetName"
+    "${CMake_BINARY_DIR}/Tests/TargetName"
+    --build-two-config
+    --build-generator ${CMAKE_TEST_GENERATOR}
+    --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
+    --build-project TestTar
+    --test-command ${CMAKE_COMMAND} -E compare_files 
+    ${CMake_SOURCE_DIR}/Tests/TargetName/scripts/hello_world
+    ${CMake_BINARY_DIR}/Tests/TargetName/scripts/hello_world)
+
   ADD_TEST(CustomCommand  ${CMAKE_CTEST_COMMAND}
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/CustomCommand"

+ 4 - 0
Tests/TargetName/CMakeLists.txt

@@ -0,0 +1,4 @@
+project(TargetName)
+
+add_subdirectory(executables)
+add_subdirectory(scripts)

+ 1 - 0
Tests/TargetName/executables/CMakeLists.txt

@@ -0,0 +1 @@
+add_executable(hello_world hello_world.c)

+ 5 - 0
Tests/TargetName/executables/hello_world.c

@@ -0,0 +1,5 @@
+#include <stdio.h>
+main()
+{
+   printf("hello, world\n");
+}

+ 1 - 0
Tests/TargetName/scripts/.gitattributes

@@ -0,0 +1 @@
+hello_world      crlf=input

+ 13 - 0
Tests/TargetName/scripts/CMakeLists.txt

@@ -0,0 +1,13 @@
+if(NOT CMAKE_BINARY_DIR STREQUAL "${CMAKE_SOURCE_DIR}")
+  add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hello_world
+  COMMAND ${CMAKE_COMMAND} -E copy 
+  ${CMAKE_CURRENT_SOURCE_DIR}/hello_world ${CMAKE_CURRENT_BINARY_DIR}
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/hello_world
+  )
+  add_custom_target(
+  hello_world_copy ALL
+  DEPENDS #hello_world
+  ${CMAKE_CURRENT_BINARY_DIR}/hello_world
+  )
+endif(NOT CMAKE_BINARY_DIR STREQUAL "${CMAKE_SOURCE_DIR}")

+ 2 - 0
Tests/TargetName/scripts/hello_world

@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "hello, world"