1515require_relative "./test_utils/PathnameMock.rb"
1616require_relative "./test_utils/TargetDefinitionMock.rb"
1717require_relative "./test_utils/XcodeprojMock.rb"
18+ require_relative "./test_utils/XcodebuildMock.rb"
1819
1920class UtilsTests < Test ::Unit ::TestCase
2021 def setup
@@ -30,6 +31,7 @@ def teardown
3031 SysctlChecker . reset ( )
3132 Environment . reset ( )
3233 Xcodeproj ::Plist . reset ( )
34+ XcodebuildMock . reset ( )
3335 ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
3436 ENV [ 'USE_HERMES' ] = '1'
3537 ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -526,9 +528,56 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
526528 # ================================= #
527529 # Test - Apply Xcode 15 Patch #
528530 # ================================= #
531+ def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch
532+ # Arrange
533+ XcodebuildMock . set_version = "Xcode 14.3"
534+ first_target = prepare_target ( "FirstTarget" )
535+ second_target = prepare_target ( "SecondTarget" )
536+ third_target = TargetMock . new ( "ThirdTarget" , [
537+ BuildConfigurationMock . new ( "Debug" , {
538+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
539+ } ) ,
540+ BuildConfigurationMock . new ( "Release" , {
541+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
542+ } ) ,
543+ ] , nil )
529544
530- def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
545+ user_project_mock = UserProjectMock . new ( "/a/path" , [
546+ prepare_config ( "Debug" ) ,
547+ prepare_config ( "Release" ) ,
548+ ] ,
549+ :native_targets => [
550+ first_target ,
551+ second_target
552+ ]
553+ )
554+ pods_projects_mock = PodsProjectMock . new ( [ ] , { "hermes-engine" => { } } , :native_targets => [
555+ third_target
556+ ] )
557+ installer = InstallerMock . new ( pods_projects_mock , [
558+ AggregatedProjectMock . new ( user_project_mock )
559+ ] )
560+
561+ # Act
562+ user_project_mock . build_configurations . each do |config |
563+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
564+ end
565+
566+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
567+
568+ # Assert
569+ user_project_mock . build_configurations . each do |config |
570+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
571+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
572+ end
573+
574+ # User project and Pods project
575+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
576+ end
577+
578+ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
531579 # Arrange
580+ XcodebuildMock . set_version = "Xcode 15.0"
532581 first_target = prepare_target ( "FirstTarget" )
533582 second_target = prepare_target ( "SecondTarget" )
534583 third_target = TargetMock . new ( "ThirdTarget" , [
@@ -557,24 +606,70 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
557606 ] )
558607
559608 # Act
560- ReactNativePodsUtils . apply_xcode_15_patch ( installer )
609+ user_project_mock . build_configurations . each do |config |
610+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
611+ end
612+
613+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
561614
562615 # Assert
563- first_target . build_configurations . each do |config |
564- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
565- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
566- )
616+ user_project_mock . build_configurations . each do |config |
617+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
618+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
567619 end
568- second_target . build_configurations . each do |config |
569- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
570- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
571- )
620+
621+ # User project and Pods project
622+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
623+ end
624+
625+ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemovesNecessaryPatch
626+ # Arrange
627+ XcodebuildMock . set_version = "Xcode 14.3"
628+ first_target = prepare_target ( "FirstTarget" )
629+ second_target = prepare_target ( "SecondTarget" )
630+ third_target = TargetMock . new ( "ThirdTarget" , [
631+ BuildConfigurationMock . new ( "Debug" , {
632+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
633+ } ) ,
634+ BuildConfigurationMock . new ( "Release" , {
635+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
636+ } ) ,
637+ ] , nil )
638+
639+ debug_config = prepare_config ( "Debug" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
640+ release_config = prepare_config ( "Release" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
641+
642+ user_project_mock = UserProjectMock . new ( "/a/path" , [
643+ debug_config ,
644+ release_config ,
645+ ] ,
646+ :native_targets => [
647+ first_target ,
648+ second_target
649+ ]
650+ )
651+ pods_projects_mock = PodsProjectMock . new ( [ debug_config . clone , release_config . clone ] , { "hermes-engine" => { } } , :native_targets => [
652+ third_target
653+ ] )
654+ installer = InstallerMock . new ( pods_projects_mock , [
655+ AggregatedProjectMock . new ( user_project_mock )
656+ ] )
657+
658+ # Act
659+ user_project_mock . build_configurations . each do |config |
660+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
572661 end
573- third_target . build_configurations . each do |config |
574- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
575- '$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
576- )
662+
663+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
664+
665+ # Assert
666+ user_project_mock . build_configurations . each do |config |
667+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
668+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
577669 end
670+
671+ # User project and Pods project
672+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
578673 end
579674
580675 # ==================================== #
@@ -923,12 +1018,14 @@ def prepare_user_project_mock_with_plists
9231018 ] )
9241019end
9251020
926- def prepare_config ( config_name )
927- return BuildConfigurationMock . new ( config_name , { "LIBRARY_SEARCH_PATHS" => [
1021+ def prepare_config ( config_name , extra_config = { } )
1022+ config = { "LIBRARY_SEARCH_PATHS" => [
9281023 "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
9291024 "\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
9301025 "another/path" ,
931- ] } )
1026+ ] } . merge ( extra_config )
1027+
1028+ return BuildConfigurationMock . new ( config_name , config )
9321029end
9331030
9341031def prepare_target ( name , product_type = nil , dependencies = [ ] )
0 commit comments