15
15
require_relative "./test_utils/PathnameMock.rb"
16
16
require_relative "./test_utils/TargetDefinitionMock.rb"
17
17
require_relative "./test_utils/XcodeprojMock.rb"
18
+ require_relative "./test_utils/XcodebuildMock.rb"
18
19
19
20
class UtilsTests < Test ::Unit ::TestCase
20
21
def setup
@@ -30,6 +31,7 @@ def teardown
30
31
SysctlChecker . reset ( )
31
32
Environment . reset ( )
32
33
Xcodeproj ::Plist . reset ( )
34
+ XcodebuildMock . reset ( )
33
35
ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
34
36
ENV [ 'USE_HERMES' ] = '1'
35
37
ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -526,9 +528,56 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
526
528
# ================================= #
527
529
# Test - Apply Xcode 15 Patch #
528
530
# ================================= #
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 )
529
544
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
531
579
# Arrange
580
+ XcodebuildMock . set_version = "Xcode 15.0"
532
581
first_target = prepare_target ( "FirstTarget" )
533
582
second_target = prepare_target ( "SecondTarget" )
534
583
third_target = TargetMock . new ( "ThirdTarget" , [
@@ -557,24 +606,70 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
557
606
] )
558
607
559
608
# 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 )
561
614
562
615
# 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" ] )
567
619
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" ] )
572
661
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" ] )
577
669
end
670
+
671
+ # User project and Pods project
672
+ assert_equal ( 2 , XcodebuildMock . version_invocation_count )
578
673
end
579
674
580
675
# ==================================== #
@@ -923,12 +1018,14 @@ def prepare_user_project_mock_with_plists
923
1018
] )
924
1019
end
925
1020
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" => [
928
1023
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
929
1024
"\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
930
1025
"another/path" ,
931
- ] } )
1026
+ ] } . merge ( extra_config )
1027
+
1028
+ return BuildConfigurationMock . new ( config_name , config )
932
1029
end
933
1030
934
1031
def prepare_target ( name , product_type = nil , dependencies = [ ] )
0 commit comments