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
@@ -29,6 +30,7 @@ def teardown
29
30
Pod ::Config . reset ( )
30
31
SysctlChecker . reset ( )
31
32
Environment . reset ( )
33
+ XcodebuildMock . reset ( )
32
34
ENV [ 'RCT_NEW_ARCH_ENABLED' ] = '0'
33
35
ENV [ 'USE_HERMES' ] = '1'
34
36
ENV [ 'USE_FRAMEWORKS' ] = nil
@@ -438,9 +440,9 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches
438
440
# ================================= #
439
441
# Test - Apply Xcode 15 Patch #
440
442
# ================================= #
441
-
442
- def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
443
+ def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch
443
444
# Arrange
445
+ XcodebuildMock . set_version = "Xcode 14.3"
444
446
first_target = prepare_target ( "FirstTarget" )
445
447
second_target = prepare_target ( "SecondTarget" )
446
448
third_target = TargetMock . new ( "ThirdTarget" , [
@@ -469,24 +471,117 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch
469
471
] )
470
472
471
473
# 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 )
473
479
474
480
# 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" ] )
479
484
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" ] )
484
523
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" ] )
489
531
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 )
490
585
end
491
586
492
587
# ==================================== #
@@ -597,12 +692,14 @@ def prepare_empty_user_project_mock
597
692
] )
598
693
end
599
694
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" => [
602
697
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" ,
603
698
"\" $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\" " ,
604
699
"another/path" ,
605
- ] } )
700
+ ] } . merge ( extra_config )
701
+
702
+ return BuildConfigurationMock . new ( config_name , config )
606
703
end
607
704
608
705
def prepare_target ( name , product_type = nil )
0 commit comments