From f62a2bf44f392f6a23836848714ed36cd02975af Mon Sep 17 00:00:00 2001
From: Craig Scott <craig.scott@crascit.com>
Date: Sun, 11 Apr 2021 18:05:14 +1000
Subject: Tests: Factor out XcodeProject-Embed check function findAttribute()

---
 .../EmbedFrameworksFlagsOff-check.cmake               | 16 +++-------------
 .../EmbedFrameworksFlagsOnNoSubdir-check.cmake        | 16 +++-------------
 .../EmbedFrameworksFlagsOnWithSubdir-check.cmake      | 16 +++-------------
 Tests/RunCMake/XcodeProject-Embed/findAttribute.cmake | 19 +++++++++++++++++++
 4 files changed, 28 insertions(+), 39 deletions(-)
 create mode 100644 Tests/RunCMake/XcodeProject-Embed/findAttribute.cmake

diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOff-check.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOff-check.cmake
index 9cc03b9..dbd3e87 100644
--- a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOff-check.cmake
+++ b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOff-check.cmake
@@ -1,14 +1,4 @@
-function(findAttribute project attr)
-  execute_process(
-      COMMAND grep ${attr} ${RunCMake_TEST_BINARY_DIR}/${project}.xcodeproj/project.pbxproj
-      OUTPUT_VARIABLE output_var
-      RESULT_VARIABLE result_var
-  )
+include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
 
-  if(NOT result_var)
-    set(RunCMake_TEST_FAILED "${attr} attribute is set" PARENT_SCOPE)
-  endif()
-endfunction()
-
-findAttribute(${test} "RemoveHeadersOnCopy")
-findAttribute(${test} "CodeSignOnCopy")
+findAttribute(${test} "RemoveHeadersOnCopy" FALSE)
+findAttribute(${test} "CodeSignOnCopy" FALSE)
diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnNoSubdir-check.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnNoSubdir-check.cmake
index 3f62640..0f57820 100644
--- a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnNoSubdir-check.cmake
+++ b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnNoSubdir-check.cmake
@@ -1,14 +1,4 @@
-function(findAttribute project attr)
-  execute_process(
-      COMMAND grep ${attr} ${RunCMake_TEST_BINARY_DIR}/${project}.xcodeproj/project.pbxproj
-      OUTPUT_VARIABLE output_var
-      RESULT_VARIABLE result_var
-  )
+include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
 
-  if(result_var)
-    set(RunCMake_TEST_FAILED "${attr} attribute not set" PARENT_SCOPE)
-  endif()
-endfunction()
-
-findAttribute(${test} "RemoveHeadersOnCopy")
-findAttribute(${test} "CodeSignOnCopy")
+findAttribute(${test} "RemoveHeadersOnCopy" TRUE)
+findAttribute(${test} "CodeSignOnCopy" TRUE)
diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnWithSubdir-check.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnWithSubdir-check.cmake
index 3f62640..0f57820 100644
--- a/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnWithSubdir-check.cmake
+++ b/Tests/RunCMake/XcodeProject-Embed/EmbedFrameworksFlagsOnWithSubdir-check.cmake
@@ -1,14 +1,4 @@
-function(findAttribute project attr)
-  execute_process(
-      COMMAND grep ${attr} ${RunCMake_TEST_BINARY_DIR}/${project}.xcodeproj/project.pbxproj
-      OUTPUT_VARIABLE output_var
-      RESULT_VARIABLE result_var
-  )
+include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
 
-  if(result_var)
-    set(RunCMake_TEST_FAILED "${attr} attribute not set" PARENT_SCOPE)
-  endif()
-endfunction()
-
-findAttribute(${test} "RemoveHeadersOnCopy")
-findAttribute(${test} "CodeSignOnCopy")
+findAttribute(${test} "RemoveHeadersOnCopy" TRUE)
+findAttribute(${test} "CodeSignOnCopy" TRUE)
diff --git a/Tests/RunCMake/XcodeProject-Embed/findAttribute.cmake b/Tests/RunCMake/XcodeProject-Embed/findAttribute.cmake
new file mode 100644
index 0000000..b1963e2
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject-Embed/findAttribute.cmake
@@ -0,0 +1,19 @@
+cmake_policy(VERSION 3.1...3.20)
+
+function(findAttribute project attr expectPresent)
+  execute_process(
+      COMMAND grep ${attr} ${RunCMake_TEST_BINARY_DIR}/${project}.xcodeproj/project.pbxproj
+      OUTPUT_VARIABLE output_var
+      RESULT_VARIABLE result_var
+  )
+
+  if(${expectPresent})
+    if(result_var)
+      set(RunCMake_TEST_FAILED "${attr} attribute is not set" PARENT_SCOPE)
+    endif()
+  else()
+    if(NOT result_var)
+      set(RunCMake_TEST_FAILED "${attr} attribute is set" PARENT_SCOPE)
+    endif()
+  endif()
+endfunction()
-- 
cgit v0.12