14
14
require_relative "./test_utils/systemUtils.rb"
15
15
require_relative "./test_utils/PathnameMock.rb"
16
16
require_relative "./test_utils/TargetDefinitionMock.rb"
17
+ require_relative "./test_utils/XcodebuildMock.rb"
17
18
18
19
class UtilsTests < Test ::Unit ::TestCase
19
20
def setup
@@ -28,6 +29,7 @@ def teardown
28
29
Pod ::Config . reset ( )
29
30
SysctlChecker . reset ( )
30
31
Environment . reset ( )
32
+ XcodebuildMock . reset ( )
31
33
ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
32
34
ENV [ 'USE_HERMES' ] = '1'
33
35
ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -437,9 +439,9 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
437
439
# ================================= #
438
440
# Test - Apply Xcode 15 Patch #
439
441
# ================================= #
440
-
441
- def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
442
+ def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch
442
443
# Arrange
444
+ XcodebuildMock . set_version = "Xcode 14.3"
443
445
first_target = prepare_target ( "FirstTarget" )
444
446
second_target = prepare_target ( "SecondTarget" )
445
447
third_target = TargetMock . new ( "ThirdTarget" , [
@@ -468,24 +470,117 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
468
470
] )
469
471
470
472
# 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 )
472
478
473
479
# 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" ] )
478
483
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" ] )
483
522
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" ] )
488
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" ] )
572
+ 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 )
489
584
end
490
585
491
586
# ==================================== #
@@ -744,12 +839,14 @@ def prepare_empty_user_project_mock
744
839
] )
745
840
end
746
841
747
- def prepare_config ( config_name )
748
- return BuildConfigurationMock . new ( config_name , { "LIBRARY_SEARCH_PATHS" => [
842
+ def prepare_config ( config_name , extra_config = { } )
843
+ config = { "LIBRARY_SEARCH_PATHS" => [
749
844
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
750
845
"\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
751
846
"another/path" ,
752
- ] } )
847
+ ] } . merge ( extra_config )
848
+
849
+ return BuildConfigurationMock . new ( config_name , config )
753
850
end
754
851
755
852
def prepare_target ( name , product_type = nil , dependencies = [ ] )
0 commit comments