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
@@ -28,6 +29,7 @@ def teardown
2829 Pod ::Config . reset ( )
2930 SysctlChecker . reset ( )
3031 Environment . reset ( )
32+ XcodebuildMock . reset ( )
3133 ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
3234 ENV [ 'USE_HERMES' ] = '1'
3335 ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -437,9 +439,9 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
437439 # ================================= #
438440 # Test - Apply Xcode 15 Patch #
439441 # ================================= #
440-
441- def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
442+ def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch
442443 # Arrange
444+ XcodebuildMock . set_version = "Xcode 14.3"
443445 first_target = prepare_target ( "FirstTarget" )
444446 second_target = prepare_target ( "SecondTarget" )
445447 third_target = TargetMock . new ( "ThirdTarget" , [
@@ -468,24 +470,117 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
468470 ] )
469471
470472 # Act
471- ReactNativePodsUtils . apply_xcode_15_patch ( installer )
473+ user_project_mock . build_configurations . each do |config |
474+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
475+ end
476+
477+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
472478
473479 # Assert
474- first_target . build_configurations . each do |config |
475- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
476- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
477- )
480+ user_project_mock . build_configurations . each do |config |
481+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
482+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
478483 end
479- second_target . build_configurations . each do |config |
480- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
481- '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
482- )
484+
485+ # User project and Pods project
486+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
487+ end
488+
489+ def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch
490+ # Arrange
491+ XcodebuildMock . set_version = "Xcode 15.0"
492+ first_target = prepare_target ( "FirstTarget" )
493+ second_target = prepare_target ( "SecondTarget" )
494+ third_target = TargetMock . new ( "ThirdTarget" , [
495+ BuildConfigurationMock . new ( "Debug" , {
496+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
497+ } ) ,
498+ BuildConfigurationMock . new ( "Release" , {
499+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
500+ } ) ,
501+ ] , nil )
502+
503+ user_project_mock = UserProjectMock . new ( "/a/path" , [
504+ prepare_config ( "Debug" ) ,
505+ prepare_config ( "Release" ) ,
506+ ] ,
507+ :native_targets => [
508+ first_target ,
509+ second_target
510+ ]
511+ )
512+ pods_projects_mock = PodsProjectMock . new ( [ ] , { "hermes-engine" => { } } , :native_targets => [
513+ third_target
514+ ] )
515+ installer = InstallerMock . new ( pods_projects_mock , [
516+ AggregatedProjectMock . new ( user_project_mock )
517+ ] )
518+
519+ # Act
520+ user_project_mock . build_configurations . each do |config |
521+ assert_nil ( config . build_settings [ "OTHER_LDFLAGS" ] )
483522 end
484- third_target . build_configurations . each do |config |
485- assert_equal ( config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] . strip ,
486- '$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"'
487- )
523+
524+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
525+
526+ # Assert
527+ user_project_mock . build_configurations . each do |config |
528+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
529+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
530+ end
531+
532+ # User project and Pods project
533+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
534+ end
535+
536+ def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemovesNecessaryPatch
537+ # Arrange
538+ XcodebuildMock . set_version = "Xcode 14.3"
539+ first_target = prepare_target ( "FirstTarget" )
540+ second_target = prepare_target ( "SecondTarget" )
541+ third_target = TargetMock . new ( "ThirdTarget" , [
542+ BuildConfigurationMock . new ( "Debug" , {
543+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
544+ } ) ,
545+ BuildConfigurationMock . new ( "Release" , {
546+ "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" '
547+ } ) ,
548+ ] , nil )
549+
550+ debug_config = prepare_config ( "Debug" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
551+ release_config = prepare_config ( "Release" , { "OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic " } )
552+
553+ user_project_mock = UserProjectMock . new ( "/a/path" , [
554+ debug_config ,
555+ release_config ,
556+ ] ,
557+ :native_targets => [
558+ first_target ,
559+ second_target
560+ ]
561+ )
562+ pods_projects_mock = PodsProjectMock . new ( [ debug_config . clone , release_config . clone ] , { "hermes-engine" => { } } , :native_targets => [
563+ third_target
564+ ] )
565+ installer = InstallerMock . new ( pods_projects_mock , [
566+ AggregatedProjectMock . new ( user_project_mock )
567+ ] )
568+
569+ # Act
570+ user_project_mock . build_configurations . each do |config |
571+ assert_equal ( "$(inherited) -Wl -ld_classic " , config . build_settings [ "OTHER_LDFLAGS" ] )
488572 end
573+
574+ ReactNativePodsUtils . apply_xcode_15_patch ( installer , :xcodebuild_manager => XcodebuildMock )
575+
576+ # Assert
577+ user_project_mock . build_configurations . each do |config |
578+ assert_equal ( "$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION" , config . build_settings [ "GCC_PREPROCESSOR_DEFINITIONS" ] )
579+ assert_equal ( "$(inherited) " , config . build_settings [ "OTHER_LDFLAGS" ] )
580+ end
581+
582+ # User project and Pods project
583+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
489584 end
490585
491586 # ==================================== #
@@ -744,12 +839,21 @@ def prepare_empty_user_project_mock
744839 ] )
745840end
746841
747- def prepare_config ( config_name )
748- return BuildConfigurationMock . new ( config_name , { "LIBRARY_SEARCH_PATHS" => [
842+ def prepare_user_project_mock_with_plists
843+ return UserProjectMock . new ( :files => [
844+ PBXFileRefMock . new ( "Info.plist" ) ,
845+ PBXFileRefMock . new ( "Extension-Info.plist" ) ,
846+ ] )
847+ end
848+
849+ def prepare_config ( config_name , extra_config = { } )
850+ config = { "LIBRARY_SEARCH_PATHS" => [
749851 "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
750852 "\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
751853 "another/path" ,
752- ] } )
854+ ] } . merge ( extra_config )
855+
856+ return BuildConfigurationMock . new ( config_name , config )
753857end
754858
755859def prepare_target ( name , product_type = nil , dependencies = [ ] )
0 commit comments