1414require_relative "./test_utils/systemUtils.rb"
1515require_relative "./test_utils/PathnameMock.rb"
1616require_relative "./test_utils/TargetDefinitionMock.rb"
17+ require_relative "./test_utils/XcodebuildMock.rb"
1718
1819class UtilsTests < Test ::Unit ::TestCase
1920 def setup
@@ -29,6 +30,7 @@ def teardown
2930 Pod ::Config . reset ( )
3031 SysctlChecker . reset ( )
3132 Environment . reset ( )
33+ XcodebuildMock . reset ( )
3234 ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
3335 ENV [ 'USE_HERMES' ] = '1'
3436 ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -438,9 +440,9 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
438440 # ================================= #
439441 # Test - Apply Xcode 15 Patch #
440442 # ================================= #
441-
442- def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
443+ def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch
443444 # Arrange
445+ XcodebuildMock . set_version = "Xcode 14.3"
444446 first_target = prepare_target ( "FirstTarget" )
445447 second_target = prepare_target ( "SecondTarget" )
446448 third_target = TargetMock . new ( "ThirdTarget" , [
@@ -469,24 +471,117 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
469471 ] )
470472
471473 # Act
472- ReactNativePodsUtils . apply_xcode_15_patch ( installer )
474+ user_project_mock . build_configurations . each do |config |
475+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
476+ end
477+
478+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
473479
474480 # Assert
475- first_target . build_configurations . each do |config |
476- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
477- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
478- )
481+ user_project_mock . build_configurations . each do |config |
482+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
483+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
479484 end
480- second_target . build_configurations . each do |config |
481- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
482- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
483- )
485+
486+ # User project and Pods project
487+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
488+ end
489+
490+ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
491+ # Arrange
492+ XcodebuildMock . set_version = "Xcode 15.0"
493+ first_target = prepare_target ( "FirstTarget" )
494+ second_target = prepare_target ( "SecondTarget" )
495+ third_target = TargetMock . new ( "ThirdTarget" , [
496+ BuildConfigurationMock . new ( "Debug" , {
497+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
498+ } ) ,
499+ BuildConfigurationMock . new ( "Release" , {
500+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
501+ } ) ,
502+ ] , nil )
503+
504+ user_project_mock = UserProjectMock . new ( "/a/path" , [
505+ prepare_config ( "Debug" ) ,
506+ prepare_config ( "Release" ) ,
507+ ] ,
508+ :native_targets => [
509+ first_target ,
510+ second_target
511+ ]
512+ )
513+ pods_projects_mock = PodsProjectMock . new ( [ ] , { "hermes-engine" => { } } , :native_targets => [
514+ third_target
515+ ] )
516+ installer = InstallerMock . new ( pods_projects_mock , [
517+ AggregatedProjectMock . new ( user_project_mock )
518+ ] )
519+
520+ # Act
521+ user_project_mock . build_configurations . each do |config |
522+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
484523 end
485- third_target . build_configurations . each do |config |
486- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
487- '$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
488- )
524+
525+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
526+
527+ # Assert
528+ user_project_mock . build_configurations . each do |config |
529+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
530+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
489531 end
532+
533+ # User project and Pods project
534+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
535+ end
536+
537+ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemovesNecessaryPatch
538+ # Arrange
539+ XcodebuildMock . set_version = "Xcode 14.3"
540+ first_target = prepare_target ( "FirstTarget" )
541+ second_target = prepare_target ( "SecondTarget" )
542+ third_target = TargetMock . new ( "ThirdTarget" , [
543+ BuildConfigurationMock . new ( "Debug" , {
544+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
545+ } ) ,
546+ BuildConfigurationMock . new ( "Release" , {
547+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
548+ } ) ,
549+ ] , nil )
550+
551+ debug_config = prepare_config ( "Debug" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
552+ release_config = prepare_config ( "Release" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
553+
554+ user_project_mock = UserProjectMock . new ( "/a/path" , [
555+ debug_config ,
556+ release_config ,
557+ ] ,
558+ :native_targets => [
559+ first_target ,
560+ second_target
561+ ]
562+ )
563+ pods_projects_mock = PodsProjectMock . new ( [ debug_config . clone , release_config . clone ] , { "hermes-engine" => { } } , :native_targets => [
564+ third_target
565+ ] )
566+ installer = InstallerMock . new ( pods_projects_mock , [
567+ AggregatedProjectMock . new ( user_project_mock )
568+ ] )
569+
570+ # Act
571+ user_project_mock . build_configurations . each do |config |
572+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
573+ end
574+
575+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
576+
577+ # Assert
578+ user_project_mock . build_configurations . each do |config |
579+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
580+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
581+ end
582+
583+ # User project and Pods project
584+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
490585 end
491586
492587 # ==================================== #
@@ -597,12 +692,14 @@ def prepare_empty_user_project_mock
597692 ] )
598693end
599694
600- def prepare_config ( config_name )
601- return BuildConfigurationMock . new ( config_name , { "LIBRARY_SEARCH_PATHS" => [
695+ def prepare_config ( config_name , extra_config = { } )
696+ config = { "LIBRARY_SEARCH_PATHS" => [
602697 "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
603698 "\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
604699 "another/path" ,
605- ] } )
700+ ] } . merge ( extra_config )
701+
702+ return BuildConfigurationMock . new ( config_name , config )
606703end
607704
608705def prepare_target ( name , product_type = nil )
0 commit comments